@modern-js/runtime 3.9.1 → 3.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/template.server.js +1 -2
- package/dist/cjs/core/browser/hydrate.js +13 -11
- package/dist/cjs/core/server/stream/beforeTemplate.js +3 -3
- package/dist/cjs/core/server/string/loadable.js +4 -4
- package/dist/cjs/router/cli/code/nestedRoutes.js +1 -2
- package/dist/cjs/router/cli/code/templates.js +1 -1
- package/dist/cjs/router/cli/code/utils.js +2 -2
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +10 -9
- package/dist/cjs/router/runtime/plugin.node.js +1 -1
- package/dist/esm/cli/template.server.mjs +1 -2
- package/dist/esm/core/browser/hydrate.mjs +13 -11
- package/dist/esm/core/server/stream/beforeTemplate.mjs +3 -3
- package/dist/esm/core/server/string/loadable.mjs +4 -4
- package/dist/esm/router/cli/code/nestedRoutes.mjs +1 -2
- package/dist/esm/router/cli/code/templates.mjs +1 -1
- package/dist/esm/router/cli/code/utils.mjs +2 -2
- package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +10 -9
- package/dist/esm/router/runtime/plugin.node.mjs +1 -1
- package/dist/esm-node/cli/template.server.mjs +1 -2
- package/dist/esm-node/core/browser/hydrate.mjs +13 -11
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +3 -3
- package/dist/esm-node/core/server/string/loadable.mjs +4 -4
- package/dist/esm-node/router/cli/code/nestedRoutes.mjs +1 -2
- package/dist/esm-node/router/cli/code/templates.mjs +1 -1
- package/dist/esm-node/router/cli/code/utils.mjs +2 -2
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +10 -9
- package/dist/esm-node/router/runtime/plugin.node.mjs +1 -1
- package/package.json +9 -9
|
@@ -141,8 +141,7 @@ function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, inter
|
|
|
141
141
|
return `
|
|
142
142
|
export * from '${realEntryPath}';
|
|
143
143
|
export { default as requestHandler } from '${realEntryPath}'`;
|
|
144
|
-
}
|
|
145
|
-
{
|
|
144
|
+
} else {
|
|
146
145
|
const entrySource = enableRsc ? SERVER_ENTRY_RSC : SERVER_ENTRY;
|
|
147
146
|
const serverEntry = transformServerEntry(entrySource, {
|
|
148
147
|
metaName: metaName || 'modern-js',
|
|
@@ -59,7 +59,7 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
59
59
|
if ('stream' === renderMode) return streamSSRHydrate();
|
|
60
60
|
function streamSSRHydrate() {
|
|
61
61
|
if (renderLevel !== external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER) return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
|
|
62
|
-
{
|
|
62
|
+
else {
|
|
63
63
|
const SSRApp = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_withCallback_js_namespaceObject.WithCallback, {
|
|
64
64
|
callback: callback,
|
|
65
65
|
children: App
|
|
@@ -70,19 +70,21 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
70
70
|
return stringSSRHydrate();
|
|
71
71
|
function stringSSRHydrate() {
|
|
72
72
|
if (renderLevel === external_constants_js_namespaceObject.RenderLevel.CLIENT_RENDER) return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
|
|
73
|
-
|
|
74
|
-
(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
else {
|
|
74
|
+
if (renderLevel === external_constants_js_namespaceObject.RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
|
|
75
|
+
(0, component_namespaceObject.loadableReady)(()=>{
|
|
76
|
+
const SSRApp = ()=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_withCallback_js_namespaceObject.WithCallback, {
|
|
77
|
+
callback: callback,
|
|
78
|
+
children: App
|
|
79
|
+
});
|
|
80
|
+
ModernHydrate((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SSRApp, {}), hydrateContext)).then((root)=>{
|
|
81
|
+
resolve(root);
|
|
78
82
|
});
|
|
79
|
-
ModernHydrate((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SSRApp, {}), hydrateContext)).then((root)=>{
|
|
80
|
-
resolve(root);
|
|
81
83
|
});
|
|
82
84
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
85
|
+
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
86
|
+
return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
|
|
87
|
+
}
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
exports.hydrateRoot = __webpack_exports__.hydrateRoot;
|
|
@@ -54,8 +54,8 @@ const readAsset = async (chunk)=>{
|
|
|
54
54
|
};
|
|
55
55
|
const checkIsInline = (chunk, enableInline)=>{
|
|
56
56
|
if ('production' !== process.env.NODE_ENV) return false;
|
|
57
|
-
if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
58
|
-
return Boolean(enableInline);
|
|
57
|
+
else if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
58
|
+
else return Boolean(enableInline);
|
|
59
59
|
};
|
|
60
60
|
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
61
61
|
const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
|
|
@@ -96,7 +96,7 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
|
96
96
|
const styles = await Promise.all(cssChunks.map(async (chunk)=>{
|
|
97
97
|
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
98
98
|
if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
|
|
99
|
-
return link;
|
|
99
|
+
else return link;
|
|
100
100
|
}));
|
|
101
101
|
return `${styles.join('')}`;
|
|
102
102
|
}
|
|
@@ -39,8 +39,8 @@ const extname = (uri)=>{
|
|
|
39
39
|
const generateChunks = (chunks, ext)=>chunks.filter((chunk)=>Boolean(chunk.url)).filter((chunk)=>extname(chunk.url).slice(1) === ext);
|
|
40
40
|
const checkIsInline = (chunk, enableInline)=>{
|
|
41
41
|
if ('production' !== process.env.NODE_ENV) return false;
|
|
42
|
-
if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
|
|
43
|
-
return Boolean(enableInline);
|
|
42
|
+
else if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
|
|
43
|
+
else return Boolean(enableInline);
|
|
44
44
|
};
|
|
45
45
|
const readAsset = async (chunk)=>{
|
|
46
46
|
const fs = await import("fs/promises");
|
|
@@ -108,7 +108,7 @@ class LoadableCollector {
|
|
|
108
108
|
const scripts = await Promise.all(chunks.filter((chunk)=>!existedScript.includes(chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
|
|
109
109
|
const script = `<script${attributes} src="${chunk.url}"></script>`;
|
|
110
110
|
if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<script>${content}</script>`).catch((_)=>script);
|
|
111
|
-
return script;
|
|
111
|
+
else return script;
|
|
112
112
|
}));
|
|
113
113
|
chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
|
|
114
114
|
}
|
|
@@ -119,7 +119,7 @@ class LoadableCollector {
|
|
|
119
119
|
const css = await Promise.all(chunks.filter((chunk)=>!(0, external_utils_js_namespaceObject.hasStylesheetLink)(template, chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
|
|
120
120
|
const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
|
|
121
121
|
if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
|
|
122
|
-
return link;
|
|
122
|
+
else return link;
|
|
123
123
|
}));
|
|
124
124
|
chunkSet.cssChunk += css.filter((css)=>Boolean(css)).join('');
|
|
125
125
|
}
|
|
@@ -76,8 +76,7 @@ const optimizeRoute = (routeTree)=>{
|
|
|
76
76
|
children: optimizedChildren
|
|
77
77
|
}
|
|
78
78
|
];
|
|
79
|
-
}
|
|
80
|
-
{
|
|
79
|
+
} else {
|
|
81
80
|
const newRoutes = children.map((child)=>{
|
|
82
81
|
const routePath = routeTree.path ? `${routeTree.path}${child.path ? `/${child.path}` : ''}` : child.path || '';
|
|
83
82
|
const newRoute = {
|
|
@@ -61,7 +61,7 @@ const walkDirectory = (dir)=>external_fs_default().readdirSync(dir).reduce((prev
|
|
|
61
61
|
...previous,
|
|
62
62
|
...walkDirectory(filePath)
|
|
63
63
|
];
|
|
64
|
-
return [
|
|
64
|
+
else return [
|
|
65
65
|
...previous,
|
|
66
66
|
filePath
|
|
67
67
|
];
|
|
@@ -78,7 +78,7 @@ const isPageComponentFile = (filePath)=>{
|
|
|
78
78
|
};
|
|
79
79
|
const replaceWithAlias = (base, filePath, alias)=>{
|
|
80
80
|
if (filePath.includes(base)) return (0, utils_namespaceObject.normalizeToPosixPath)(external_path_default().join(alias, external_path_default().relative(base, filePath)));
|
|
81
|
-
return filePath;
|
|
81
|
+
else return filePath;
|
|
82
82
|
};
|
|
83
83
|
const parseModule = async ({ source, filename })=>{
|
|
84
84
|
let content = source;
|
|
@@ -68,7 +68,7 @@ const DeferredDataScripts = (props)=>{
|
|
|
68
68
|
(0, node_namespaceObject.serializeJson)(key)
|
|
69
69
|
]
|
|
70
70
|
};
|
|
71
|
-
{
|
|
71
|
+
else {
|
|
72
72
|
const trackedPromise = deferredData.data[key];
|
|
73
73
|
if (void 0 !== trackedPromise._error) {
|
|
74
74
|
const error = {
|
|
@@ -83,15 +83,16 @@ const DeferredDataScripts = (props)=>{
|
|
|
83
83
|
(0, node_namespaceObject.serializeJson)(error)
|
|
84
84
|
]
|
|
85
85
|
};
|
|
86
|
+
} else {
|
|
87
|
+
if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
|
|
88
|
+
return {
|
|
89
|
+
key,
|
|
90
|
+
routerDataFnName: 'p',
|
|
91
|
+
routerDataFnArgs: [
|
|
92
|
+
(0, node_namespaceObject.serializeJson)(trackedPromise._data)
|
|
93
|
+
]
|
|
94
|
+
};
|
|
86
95
|
}
|
|
87
|
-
if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
|
|
88
|
-
return {
|
|
89
|
-
key,
|
|
90
|
-
routerDataFnName: 'p',
|
|
91
|
-
routerDataFnArgs: [
|
|
92
|
-
(0, node_namespaceObject.serializeJson)(trackedPromise._data)
|
|
93
|
-
]
|
|
94
|
-
};
|
|
95
96
|
}
|
|
96
97
|
});
|
|
97
98
|
return {
|
|
@@ -149,7 +149,7 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
149
149
|
}) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_rsc_router_js_namespaceObject.RSCStaticRouter, {
|
|
150
150
|
basename: basename
|
|
151
151
|
});
|
|
152
|
-
{
|
|
152
|
+
else {
|
|
153
153
|
const routerWrapper = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
154
154
|
children: [
|
|
155
155
|
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(router_namespaceObject.StaticRouterProvider, {
|
|
@@ -108,8 +108,7 @@ function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, inter
|
|
|
108
108
|
return `
|
|
109
109
|
export * from '${realEntryPath}';
|
|
110
110
|
export { default as requestHandler } from '${realEntryPath}'`;
|
|
111
|
-
}
|
|
112
|
-
{
|
|
111
|
+
} else {
|
|
113
112
|
const entrySource = enableRsc ? SERVER_ENTRY_RSC : SERVER_ENTRY;
|
|
114
113
|
const serverEntry = transformServerEntry(entrySource, {
|
|
115
114
|
metaName: metaName || 'modern-js',
|
|
@@ -26,7 +26,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
26
26
|
if ('stream' === renderMode) return streamSSRHydrate();
|
|
27
27
|
function streamSSRHydrate() {
|
|
28
28
|
if (renderLevel !== RenderLevel.SERVER_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
29
|
-
{
|
|
29
|
+
else {
|
|
30
30
|
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
31
31
|
callback: callback,
|
|
32
32
|
children: App
|
|
@@ -37,19 +37,21 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
37
37
|
return stringSSRHydrate();
|
|
38
38
|
function stringSSRHydrate() {
|
|
39
39
|
if (renderLevel === RenderLevel.CLIENT_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
else {
|
|
41
|
+
if (renderLevel === RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
|
|
42
|
+
loadableReady(()=>{
|
|
43
|
+
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
44
|
+
callback: callback,
|
|
45
|
+
children: App
|
|
46
|
+
});
|
|
47
|
+
ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
|
|
48
|
+
resolve(root);
|
|
45
49
|
});
|
|
46
|
-
ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
|
|
47
|
-
resolve(root);
|
|
48
50
|
});
|
|
49
51
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
53
|
+
return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
54
|
+
}
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
export { hydrateWithReact, hydrate_hydrateRoot as hydrateRoot };
|
|
@@ -12,8 +12,8 @@ const readAsset = async (chunk)=>{
|
|
|
12
12
|
};
|
|
13
13
|
const checkIsInline = (chunk, enableInline)=>{
|
|
14
14
|
if ('production' !== process.env.NODE_ENV) return false;
|
|
15
|
-
if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
16
|
-
return Boolean(enableInline);
|
|
15
|
+
else if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
16
|
+
else return Boolean(enableInline);
|
|
17
17
|
};
|
|
18
18
|
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
19
19
|
const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
|
|
@@ -54,7 +54,7 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
|
54
54
|
const styles = await Promise.all(cssChunks.map(async (chunk)=>{
|
|
55
55
|
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
56
56
|
if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
|
|
57
|
-
return link;
|
|
57
|
+
else return link;
|
|
58
58
|
}));
|
|
59
59
|
return `${styles.join('')}`;
|
|
60
60
|
}
|
|
@@ -7,8 +7,8 @@ const extname = (uri)=>{
|
|
|
7
7
|
const generateChunks = (chunks, ext)=>chunks.filter((chunk)=>Boolean(chunk.url)).filter((chunk)=>extname(chunk.url).slice(1) === ext);
|
|
8
8
|
const checkIsInline = (chunk, enableInline)=>{
|
|
9
9
|
if ('production' !== process.env.NODE_ENV) return false;
|
|
10
|
-
if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
|
|
11
|
-
return Boolean(enableInline);
|
|
10
|
+
else if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
|
|
11
|
+
else return Boolean(enableInline);
|
|
12
12
|
};
|
|
13
13
|
const readAsset = async (chunk)=>{
|
|
14
14
|
const fs = await import("fs/promises");
|
|
@@ -76,7 +76,7 @@ class LoadableCollector {
|
|
|
76
76
|
const scripts = await Promise.all(chunks.filter((chunk)=>!existedScript.includes(chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
|
|
77
77
|
const script = `<script${attributes} src="${chunk.url}"></script>`;
|
|
78
78
|
if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<script>${content}</script>`).catch((_)=>script);
|
|
79
|
-
return script;
|
|
79
|
+
else return script;
|
|
80
80
|
}));
|
|
81
81
|
chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
|
|
82
82
|
}
|
|
@@ -87,7 +87,7 @@ class LoadableCollector {
|
|
|
87
87
|
const css = await Promise.all(chunks.filter((chunk)=>!hasStylesheetLink(template, chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
|
|
88
88
|
const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
|
|
89
89
|
if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
|
|
90
|
-
return link;
|
|
90
|
+
else return link;
|
|
91
91
|
}));
|
|
92
92
|
chunkSet.cssChunk += css.filter((css)=>Boolean(css)).join('');
|
|
93
93
|
}
|
|
@@ -42,8 +42,7 @@ const optimizeRoute = (routeTree)=>{
|
|
|
42
42
|
children: optimizedChildren
|
|
43
43
|
}
|
|
44
44
|
];
|
|
45
|
-
}
|
|
46
|
-
{
|
|
45
|
+
} else {
|
|
47
46
|
const newRoutes = children.map((child)=>{
|
|
48
47
|
const routePath = routeTree.path ? `${routeTree.path}${child.path ? `/${child.path}` : ''}` : child.path || '';
|
|
49
48
|
const newRoute = {
|
|
@@ -10,7 +10,7 @@ const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
|
|
|
10
10
|
...previous,
|
|
11
11
|
...walkDirectory(filePath)
|
|
12
12
|
];
|
|
13
|
-
return [
|
|
13
|
+
else return [
|
|
14
14
|
...previous,
|
|
15
15
|
filePath
|
|
16
16
|
];
|
|
@@ -27,7 +27,7 @@ const isPageComponentFile = (filePath)=>{
|
|
|
27
27
|
};
|
|
28
28
|
const replaceWithAlias = (base, filePath, alias)=>{
|
|
29
29
|
if (filePath.includes(base)) return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
30
|
-
return filePath;
|
|
30
|
+
else return filePath;
|
|
31
31
|
};
|
|
32
32
|
const parseModule = async ({ source, filename })=>{
|
|
33
33
|
let content = source;
|
|
@@ -36,7 +36,7 @@ const DeferredDataScripts = (props)=>{
|
|
|
36
36
|
serializeJson(key)
|
|
37
37
|
]
|
|
38
38
|
};
|
|
39
|
-
{
|
|
39
|
+
else {
|
|
40
40
|
const trackedPromise = deferredData.data[key];
|
|
41
41
|
if (void 0 !== trackedPromise._error) {
|
|
42
42
|
const error = {
|
|
@@ -51,15 +51,16 @@ const DeferredDataScripts = (props)=>{
|
|
|
51
51
|
serializeJson(error)
|
|
52
52
|
]
|
|
53
53
|
};
|
|
54
|
+
} else {
|
|
55
|
+
if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
|
|
56
|
+
return {
|
|
57
|
+
key,
|
|
58
|
+
routerDataFnName: 'p',
|
|
59
|
+
routerDataFnArgs: [
|
|
60
|
+
serializeJson(trackedPromise._data)
|
|
61
|
+
]
|
|
62
|
+
};
|
|
54
63
|
}
|
|
55
|
-
if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
|
|
56
|
-
return {
|
|
57
|
-
key,
|
|
58
|
-
routerDataFnName: 'p',
|
|
59
|
-
routerDataFnArgs: [
|
|
60
|
-
serializeJson(trackedPromise._data)
|
|
61
|
-
]
|
|
62
|
-
};
|
|
63
64
|
}
|
|
64
65
|
});
|
|
65
66
|
return {
|
|
@@ -106,7 +106,7 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
106
106
|
}) : /*#__PURE__*/ jsx(RSCStaticRouter, {
|
|
107
107
|
basename: basename
|
|
108
108
|
});
|
|
109
|
-
{
|
|
109
|
+
else {
|
|
110
110
|
const routerWrapper = /*#__PURE__*/ jsxs(Fragment, {
|
|
111
111
|
children: [
|
|
112
112
|
/*#__PURE__*/ jsx(StaticRouterProvider, {
|
|
@@ -109,8 +109,7 @@ function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, inter
|
|
|
109
109
|
return `
|
|
110
110
|
export * from '${realEntryPath}';
|
|
111
111
|
export { default as requestHandler } from '${realEntryPath}'`;
|
|
112
|
-
}
|
|
113
|
-
{
|
|
112
|
+
} else {
|
|
114
113
|
const entrySource = enableRsc ? SERVER_ENTRY_RSC : SERVER_ENTRY;
|
|
115
114
|
const serverEntry = transformServerEntry(entrySource, {
|
|
116
115
|
metaName: metaName || 'modern-js',
|
|
@@ -27,7 +27,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
27
27
|
if ('stream' === renderMode) return streamSSRHydrate();
|
|
28
28
|
function streamSSRHydrate() {
|
|
29
29
|
if (renderLevel !== RenderLevel.SERVER_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
30
|
-
{
|
|
30
|
+
else {
|
|
31
31
|
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
32
32
|
callback: callback,
|
|
33
33
|
children: App
|
|
@@ -38,19 +38,21 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
38
38
|
return stringSSRHydrate();
|
|
39
39
|
function stringSSRHydrate() {
|
|
40
40
|
if (renderLevel === RenderLevel.CLIENT_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
else {
|
|
42
|
+
if (renderLevel === RenderLevel.SERVER_RENDER) return new Promise((resolve)=>{
|
|
43
|
+
loadableReady(()=>{
|
|
44
|
+
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
45
|
+
callback: callback,
|
|
46
|
+
children: App
|
|
47
|
+
});
|
|
48
|
+
ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
|
|
49
|
+
resolve(root);
|
|
46
50
|
});
|
|
47
|
-
ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext)).then((root)=>{
|
|
48
|
-
resolve(root);
|
|
49
51
|
});
|
|
50
52
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
54
|
+
return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
55
|
+
}
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
export { hydrateWithReact, hydrate_hydrateRoot as hydrateRoot };
|
|
@@ -16,8 +16,8 @@ const readAsset = async (chunk)=>{
|
|
|
16
16
|
};
|
|
17
17
|
const checkIsInline = (chunk, enableInline)=>{
|
|
18
18
|
if ('production' !== process.env.NODE_ENV) return false;
|
|
19
|
-
if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
20
|
-
return Boolean(enableInline);
|
|
19
|
+
else if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
20
|
+
else return Boolean(enableInline);
|
|
21
21
|
};
|
|
22
22
|
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
23
23
|
const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
|
|
@@ -58,7 +58,7 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
|
58
58
|
const styles = await Promise.all(cssChunks.map(async (chunk)=>{
|
|
59
59
|
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
60
60
|
if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
|
|
61
|
-
return link;
|
|
61
|
+
else return link;
|
|
62
62
|
}));
|
|
63
63
|
return `${styles.join('')}`;
|
|
64
64
|
}
|
|
@@ -11,8 +11,8 @@ const extname = (uri)=>{
|
|
|
11
11
|
const generateChunks = (chunks, ext)=>chunks.filter((chunk)=>Boolean(chunk.url)).filter((chunk)=>extname(chunk.url).slice(1) === ext);
|
|
12
12
|
const checkIsInline = (chunk, enableInline)=>{
|
|
13
13
|
if ('production' !== process.env.NODE_ENV) return false;
|
|
14
|
-
if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
|
|
15
|
-
return Boolean(enableInline);
|
|
14
|
+
else if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
|
|
15
|
+
else return Boolean(enableInline);
|
|
16
16
|
};
|
|
17
17
|
const readAsset = async (chunk)=>{
|
|
18
18
|
const fs = await import("fs/promises");
|
|
@@ -80,7 +80,7 @@ class LoadableCollector {
|
|
|
80
80
|
const scripts = await Promise.all(chunks.filter((chunk)=>!existedScript.includes(chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
|
|
81
81
|
const script = `<script${attributes} src="${chunk.url}"></script>`;
|
|
82
82
|
if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<script>${content}</script>`).catch((_)=>script);
|
|
83
|
-
return script;
|
|
83
|
+
else return script;
|
|
84
84
|
}));
|
|
85
85
|
chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
|
|
86
86
|
}
|
|
@@ -91,7 +91,7 @@ class LoadableCollector {
|
|
|
91
91
|
const css = await Promise.all(chunks.filter((chunk)=>!hasStylesheetLink(template, chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
|
|
92
92
|
const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
|
|
93
93
|
if (checkIsNode() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
|
|
94
|
-
return link;
|
|
94
|
+
else return link;
|
|
95
95
|
}));
|
|
96
96
|
chunkSet.cssChunk += css.filter((css)=>Boolean(css)).join('');
|
|
97
97
|
}
|
|
@@ -43,8 +43,7 @@ const optimizeRoute = (routeTree)=>{
|
|
|
43
43
|
children: optimizedChildren
|
|
44
44
|
}
|
|
45
45
|
];
|
|
46
|
-
}
|
|
47
|
-
{
|
|
46
|
+
} else {
|
|
48
47
|
const newRoutes = children.map((child)=>{
|
|
49
48
|
const routePath = routeTree.path ? `${routeTree.path}${child.path ? `/${child.path}` : ''}` : child.path || '';
|
|
50
49
|
const newRoute = {
|
|
@@ -11,7 +11,7 @@ const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
|
|
|
11
11
|
...previous,
|
|
12
12
|
...walkDirectory(filePath)
|
|
13
13
|
];
|
|
14
|
-
return [
|
|
14
|
+
else return [
|
|
15
15
|
...previous,
|
|
16
16
|
filePath
|
|
17
17
|
];
|
|
@@ -28,7 +28,7 @@ const isPageComponentFile = (filePath)=>{
|
|
|
28
28
|
};
|
|
29
29
|
const replaceWithAlias = (base, filePath, alias)=>{
|
|
30
30
|
if (filePath.includes(base)) return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
31
|
-
return filePath;
|
|
31
|
+
else return filePath;
|
|
32
32
|
};
|
|
33
33
|
const parseModule = async ({ source, filename })=>{
|
|
34
34
|
let content = source;
|
|
@@ -37,7 +37,7 @@ const DeferredDataScripts = (props)=>{
|
|
|
37
37
|
serializeJson(key)
|
|
38
38
|
]
|
|
39
39
|
};
|
|
40
|
-
{
|
|
40
|
+
else {
|
|
41
41
|
const trackedPromise = deferredData.data[key];
|
|
42
42
|
if (void 0 !== trackedPromise._error) {
|
|
43
43
|
const error = {
|
|
@@ -52,15 +52,16 @@ const DeferredDataScripts = (props)=>{
|
|
|
52
52
|
serializeJson(error)
|
|
53
53
|
]
|
|
54
54
|
};
|
|
55
|
+
} else {
|
|
56
|
+
if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
|
|
57
|
+
return {
|
|
58
|
+
key,
|
|
59
|
+
routerDataFnName: 'p',
|
|
60
|
+
routerDataFnArgs: [
|
|
61
|
+
serializeJson(trackedPromise._data)
|
|
62
|
+
]
|
|
63
|
+
};
|
|
55
64
|
}
|
|
56
|
-
if (void 0 === trackedPromise._data) throw new Error(`The deferred data for ${key} was not resolved, did you forget to return data from a deferred promise`);
|
|
57
|
-
return {
|
|
58
|
-
key,
|
|
59
|
-
routerDataFnName: 'p',
|
|
60
|
-
routerDataFnArgs: [
|
|
61
|
-
serializeJson(trackedPromise._data)
|
|
62
|
-
]
|
|
63
|
-
};
|
|
64
65
|
}
|
|
65
66
|
});
|
|
66
67
|
return {
|
|
@@ -107,7 +107,7 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
107
107
|
}) : /*#__PURE__*/ jsx(RSCStaticRouter, {
|
|
108
108
|
basename: basename
|
|
109
109
|
});
|
|
110
|
-
{
|
|
110
|
+
else {
|
|
111
111
|
const routerWrapper = /*#__PURE__*/ jsxs(Fragment, {
|
|
112
112
|
children: [
|
|
113
113
|
/*#__PURE__*/ jsx(StaticRouterProvider, {
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "3.9.
|
|
18
|
+
"version": "3.9.2",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=20"
|
|
21
21
|
},
|
|
@@ -215,12 +215,12 @@
|
|
|
215
215
|
"isbot": "3.8.0",
|
|
216
216
|
"react-helmet": "^6.1.0",
|
|
217
217
|
"react-is": "^18.3.1",
|
|
218
|
-
"@modern-js/plugin": "3.9.
|
|
219
|
-
"@modern-js/
|
|
220
|
-
"@modern-js/
|
|
221
|
-
"@modern-js/
|
|
222
|
-
"@modern-js/
|
|
223
|
-
"@modern-js/
|
|
218
|
+
"@modern-js/plugin": "3.9.2",
|
|
219
|
+
"@modern-js/plugin-data-loader": "3.9.2",
|
|
220
|
+
"@modern-js/render": "3.9.2",
|
|
221
|
+
"@modern-js/runtime-utils": "3.9.2",
|
|
222
|
+
"@modern-js/utils": "3.9.2",
|
|
223
|
+
"@modern-js/types": "3.9.2"
|
|
224
224
|
},
|
|
225
225
|
"peerDependencies": {
|
|
226
226
|
"react": ">=18.3.1",
|
|
@@ -228,7 +228,7 @@
|
|
|
228
228
|
},
|
|
229
229
|
"devDependencies": {
|
|
230
230
|
"@remix-run/web-fetch": "^4.1.3",
|
|
231
|
-
"@rsbuild/core": "2.2.
|
|
231
|
+
"@rsbuild/core": "2.2.7",
|
|
232
232
|
"@rslib/core": "1.0.0",
|
|
233
233
|
"@testing-library/dom": "^10.4.1",
|
|
234
234
|
"@testing-library/react": "^16.3.2",
|
|
@@ -240,7 +240,7 @@
|
|
|
240
240
|
"react-dom": "^19.2.8",
|
|
241
241
|
"ts-node": "^10.9.2",
|
|
242
242
|
"typescript": "^5",
|
|
243
|
-
"@modern-js/app-tools": "3.9.
|
|
243
|
+
"@modern-js/app-tools": "3.9.2",
|
|
244
244
|
"@modern-js/rslib": "2.68.10",
|
|
245
245
|
"@scripts/rstest-config": "2.66.0"
|
|
246
246
|
},
|