@bleedingdev/modern-js-runtime 3.9.0-ultramodern.8 → 3.9.3-ultramodern.1
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/code.js +2 -2
- package/dist/cjs/cli/index.js +0 -7
- package/dist/cjs/cli/ssr/loadable-bundler-plugin.js +2 -0
- package/dist/cjs/cli/template.server.js +1 -2
- package/dist/cjs/core/browser/hydrate.js +3 -9
- package/dist/cjs/core/browser/index.js +4 -5
- package/dist/cjs/core/context/index.js +8 -2
- package/dist/cjs/core/context/public.js +4 -4
- package/dist/cjs/core/context/runtime.js +3 -9
- package/dist/cjs/core/index.js +3 -3
- package/dist/cjs/core/plugin/index.js +2 -2
- package/dist/cjs/core/react/index.js +3 -3
- package/dist/cjs/core/react/wrapper.js +7 -8
- package/dist/cjs/core/server/requestHandler.js +253 -25
- package/dist/cjs/core/server/stream/beforeTemplate.js +3 -3
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +2 -2
- package/dist/cjs/core/server/stream/createReadableStream.js +51 -19
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +54 -27
- package/dist/cjs/core/server/stream/deferredScript.js +12 -6
- package/dist/cjs/core/server/stream/deferredScriptOutputCoordinator.js +370 -0
- package/dist/cjs/core/server/stream/shared.js +4 -0
- package/dist/cjs/core/server/string/index.js +6 -4
- package/dist/cjs/core/server/string/loadable.js +4 -4
- package/dist/cjs/document/cli/index.js +14 -5
- package/dist/cjs/exports/head.js +2 -2
- package/dist/cjs/internal.js +2 -2
- package/dist/cjs/router/cli/code/nestedRoutes.js +1 -2
- package/dist/cjs/router/cli/code/templates.js +2 -2
- package/dist/cjs/router/cli/code/utils.js +5 -4
- package/dist/cjs/router/runtime/DeferredDataScripts.node.js +13 -10
- package/dist/cjs/router/runtime/PrefetchLink.js +4 -4
- package/dist/cjs/router/runtime/hooks.js +6 -7
- package/dist/cjs/router/runtime/plugin.js +22 -27
- package/dist/cjs/router/runtime/plugin.node.js +8 -9
- package/dist/esm/cli/code.mjs +2 -2
- package/dist/esm/cli/index.mjs +0 -7
- package/dist/esm/cli/ssr/loadable-bundler-plugin.mjs +2 -0
- package/dist/esm/cli/template.server.mjs +1 -2
- package/dist/esm/core/browser/hydrate.mjs +3 -9
- package/dist/esm/core/browser/index.mjs +1 -2
- package/dist/esm/core/context/index.mjs +1 -1
- package/dist/esm/core/context/public.mjs +1 -1
- package/dist/esm/core/context/runtime.mjs +3 -9
- package/dist/esm/core/index.mjs +1 -1
- package/dist/esm/core/plugin/index.mjs +1 -1
- package/dist/esm/core/react/index.mjs +1 -1
- package/dist/esm/core/react/wrapper.mjs +1 -2
- package/dist/esm/core/server/requestHandler.mjs +223 -19
- package/dist/esm/core/server/stream/beforeTemplate.mjs +3 -3
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +2 -2
- package/dist/esm/core/server/stream/createReadableStream.mjs +48 -16
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +53 -26
- package/dist/esm/core/server/stream/deferredScript.mjs +12 -6
- package/dist/esm/core/server/stream/deferredScriptOutputCoordinator.mjs +332 -0
- package/dist/esm/core/server/stream/shared.mjs +2 -1
- package/dist/esm/core/server/string/index.mjs +3 -1
- package/dist/esm/core/server/string/loadable.mjs +4 -4
- package/dist/esm/document/cli/index.mjs +12 -6
- package/dist/esm/exports/head.mjs +1 -1
- package/dist/esm/internal.mjs +1 -1
- package/dist/esm/router/cli/code/nestedRoutes.mjs +1 -2
- package/dist/esm/router/cli/code/templates.mjs +2 -2
- package/dist/esm/router/cli/code/utils.mjs +6 -5
- package/dist/esm/router/runtime/DeferredDataScripts.node.mjs +13 -10
- package/dist/esm/router/runtime/PrefetchLink.mjs +1 -1
- package/dist/esm/router/runtime/hooks.mjs +6 -7
- package/dist/esm/router/runtime/plugin.mjs +14 -19
- package/dist/esm/router/runtime/plugin.node.mjs +3 -4
- package/dist/esm-node/cli/code.mjs +2 -2
- package/dist/esm-node/cli/index.mjs +1 -9
- package/dist/esm-node/cli/ssr/loadable-bundler-plugin.mjs +2 -0
- package/dist/esm-node/cli/template.server.mjs +1 -2
- package/dist/esm-node/core/browser/hydrate.mjs +3 -9
- package/dist/esm-node/core/browser/index.mjs +1 -2
- package/dist/esm-node/core/context/index.mjs +1 -1
- package/dist/esm-node/core/context/public.mjs +1 -1
- package/dist/esm-node/core/context/runtime.mjs +3 -9
- package/dist/esm-node/core/index.mjs +1 -1
- package/dist/esm-node/core/plugin/index.mjs +1 -1
- package/dist/esm-node/core/react/index.mjs +1 -1
- package/dist/esm-node/core/react/wrapper.mjs +1 -2
- package/dist/esm-node/core/server/requestHandler.mjs +223 -19
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +3 -3
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +2 -2
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +48 -16
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +53 -26
- package/dist/esm-node/core/server/stream/deferredScript.mjs +12 -6
- package/dist/esm-node/core/server/stream/deferredScriptOutputCoordinator.mjs +333 -0
- package/dist/esm-node/core/server/stream/shared.mjs +2 -1
- package/dist/esm-node/core/server/string/index.mjs +3 -1
- package/dist/esm-node/core/server/string/loadable.mjs +4 -4
- package/dist/esm-node/document/cli/index.mjs +12 -6
- package/dist/esm-node/exports/head.mjs +1 -1
- package/dist/esm-node/internal.mjs +1 -1
- package/dist/esm-node/router/cli/code/nestedRoutes.mjs +1 -2
- package/dist/esm-node/router/cli/code/templates.mjs +2 -2
- package/dist/esm-node/router/cli/code/utils.mjs +6 -5
- package/dist/esm-node/router/runtime/DeferredDataScripts.node.mjs +13 -10
- package/dist/esm-node/router/runtime/PrefetchLink.mjs +1 -1
- package/dist/esm-node/router/runtime/hooks.mjs +6 -7
- package/dist/esm-node/router/runtime/plugin.mjs +14 -19
- package/dist/esm-node/router/runtime/plugin.node.mjs +3 -4
- package/dist/types/common.d.ts +2 -8
- package/dist/types/core/context/index.d.ts +1 -1
- package/dist/types/core/context/public.d.ts +1 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/react/wrapper.d.ts +1 -1
- package/dist/types/core/server/requestHandler.d.ts +32 -3
- package/dist/types/core/server/shared.d.ts +1 -1
- package/dist/types/core/server/stream/deferredScript.d.ts +1 -1
- package/dist/types/core/server/stream/deferredScriptOutputCoordinator.d.ts +72 -0
- package/dist/types/core/server/stream/shared.d.ts +15 -1
- package/dist/types/core/server/tracer.d.ts +1 -1
- package/dist/types/core/server/utils.d.ts +1 -1
- package/dist/types/core/types.d.ts +1 -2
- package/dist/types/document/cli/index.d.ts +1 -0
- package/dist/types/internal.d.ts +1 -1
- package/dist/types/router/cli/code/utils.d.ts +1 -1
- package/dist/types/router/runtime/hooks.d.ts +12 -16
- package/package.json +32 -25
- package/rslib.config.mts +3 -0
- package/rstest.config.mts +0 -4
- package/dist/cjs/core/server/requestResponse.js +0 -107
- package/dist/cjs/core/server/routerCleanup.js +0 -129
- package/dist/cjs/rsc/server.worker.js +0 -62
- package/dist/esm/core/server/requestResponse.mjs +0 -63
- package/dist/esm/core/server/routerCleanup.mjs +0 -82
- package/dist/esm/rsc/server.worker.mjs +0 -1
- package/dist/esm-node/core/server/requestResponse.mjs +0 -64
- package/dist/esm-node/core/server/routerCleanup.mjs +0 -83
- package/dist/esm-node/rsc/server.worker.mjs +0 -2
- package/dist/types/core/server/requestResponse.d.ts +0 -15
- package/dist/types/core/server/routerCleanup.d.ts +0 -31
- package/dist/types/rsc/server.worker.d.ts +0 -1
|
@@ -48,8 +48,8 @@ const assetToChunk = (asset)=>({
|
|
|
48
48
|
});
|
|
49
49
|
const checkIsInline = (chunk, enableInline)=>{
|
|
50
50
|
if ('production' !== process.env.NODE_ENV) return false;
|
|
51
|
-
if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
|
|
52
|
-
return Boolean(enableInline);
|
|
51
|
+
else if (enableInline instanceof RegExp) return enableInline.test(chunk.url);
|
|
52
|
+
else return Boolean(enableInline);
|
|
53
53
|
};
|
|
54
54
|
const readAsset = async (chunk)=>{
|
|
55
55
|
const fs = await import("fs/promises");
|
|
@@ -142,7 +142,7 @@ class LoadableCollector {
|
|
|
142
142
|
const scripts = await Promise.all(chunks.filter((chunk)=>!existedScript.includes(chunk.url) && !this.existsAssets?.includes(chunk.path)).map(async (chunk)=>{
|
|
143
143
|
const script = `<script${attributes} src="${chunk.url}"></script>`;
|
|
144
144
|
if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<script>${content}</script>`).catch((_)=>script);
|
|
145
|
-
return script;
|
|
145
|
+
else return script;
|
|
146
146
|
}));
|
|
147
147
|
chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
|
|
148
148
|
}
|
|
@@ -159,7 +159,7 @@ class LoadableCollector {
|
|
|
159
159
|
const css = await Promise.all(emittedChunks.map(async (chunk)=>{
|
|
160
160
|
const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
|
|
161
161
|
if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
|
|
162
|
-
return link;
|
|
162
|
+
else return link;
|
|
163
163
|
}));
|
|
164
164
|
chunkSet.cssChunk += css.filter((css)=>Boolean(css)).join('');
|
|
165
165
|
this.stylesheetInfo.emittedAssets = emittedChunks.map((chunk)=>chunk.url);
|
|
@@ -40,6 +40,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
40
40
|
default: ()=>cli,
|
|
41
41
|
documentPlugin: ()=>documentPlugin,
|
|
42
42
|
getDocumentByEntryName: ()=>getDocumentByEntryName,
|
|
43
|
+
getDocumentTempEntry: ()=>getDocumentTempEntry,
|
|
43
44
|
processScriptPlaceholders: ()=>processScriptPlaceholders
|
|
44
45
|
});
|
|
45
46
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
@@ -170,6 +171,7 @@ g.__MODERN_DOC_RENDERERS__[${JSON.stringify(_entryName)}] = render;
|
|
|
170
171
|
|
|
171
172
|
export default { render: render };`;
|
|
172
173
|
};
|
|
174
|
+
const getDocumentTempEntry = (internalDirectory, compilerName, entryName)=>external_path_default().join(internalDirectory, CONSTANTS.DOCUMENT_OUTPUT_DIR, compilerName ?? '', `${CONSTANTS.TEMP_ENTRY_PREFIX}${entryName}.js`);
|
|
173
175
|
const processChildCompilation = async (entryName, docPath, compilation, compiler, appDirectory, internalDirectory)=>new Promise((resolve, reject)=>{
|
|
174
176
|
const outFile = external_path_default().posix.join(CONSTANTS.DOCUMENT_OUTPUT_DIR, `${CONSTANTS.HTML_OUTPUT_PREFIX}${entryName}${CONSTANTS.HTML_OUTPUT_SUFFIX}`);
|
|
175
177
|
const child = compilation.createChildCompiler(`${CONSTANTS.CHILD_COMPILER_PREFIX}${entryName}`, {
|
|
@@ -180,8 +182,7 @@ const processChildCompilation = async (entryName, docPath, compilation, compiler
|
|
|
180
182
|
}, []);
|
|
181
183
|
configureChildCompiler(child, compiler, appDirectory);
|
|
182
184
|
applyExternalsPlugin(child, compiler);
|
|
183
|
-
const
|
|
184
|
-
const tempEntry = external_path_default().join(entryDir, `${CONSTANTS.TEMP_ENTRY_PREFIX}${entryName}.js`);
|
|
185
|
+
const tempEntry = getDocumentTempEntry(internalDirectory, compiler.name, entryName);
|
|
185
186
|
const finalize = ()=>{
|
|
186
187
|
try {
|
|
187
188
|
const EntryPlugin = compiler.rspack?.EntryPlugin;
|
|
@@ -248,6 +249,7 @@ const documentPlugin = ()=>({
|
|
|
248
249
|
const tasks = [];
|
|
249
250
|
for (const ep of entrypoints || []){
|
|
250
251
|
const entryName = ep.entryName;
|
|
252
|
+
if (!this.htmlEntryNames.has(entryName)) continue;
|
|
251
253
|
const docPath = getDocumentByEntryName(entrypoints, entryName, appDirectory);
|
|
252
254
|
if (docPath) {
|
|
253
255
|
compilation.fileDependencies?.add?.(docPath);
|
|
@@ -264,14 +266,19 @@ const documentPlugin = ()=>({
|
|
|
264
266
|
}
|
|
265
267
|
});
|
|
266
268
|
}
|
|
267
|
-
constructor(){
|
|
269
|
+
constructor(htmlEntryNames){
|
|
270
|
+
this.htmlEntryNames = htmlEntryNames;
|
|
268
271
|
this.name = 'ModernJsDocumentChildCompilerPlugin';
|
|
269
272
|
}
|
|
270
273
|
}
|
|
271
274
|
api.config(()=>({
|
|
272
275
|
tools: {
|
|
273
|
-
bundlerChain: (chain)=>{
|
|
274
|
-
|
|
276
|
+
bundlerChain: (chain, { environment })=>{
|
|
277
|
+
const htmlEntryNames = new Set(Object.keys(environment.htmlPaths));
|
|
278
|
+
if (0 === htmlEntryNames.size) return;
|
|
279
|
+
chain.plugin('modernjs-document-child-compiler').use(ModernJsDocumentChildCompilerPlugin, [
|
|
280
|
+
htmlEntryNames
|
|
281
|
+
]);
|
|
275
282
|
}
|
|
276
283
|
}
|
|
277
284
|
}));
|
|
@@ -394,11 +401,13 @@ const cli = documentPlugin;
|
|
|
394
401
|
exports["default"] = __webpack_exports__["default"];
|
|
395
402
|
exports.documentPlugin = __webpack_exports__.documentPlugin;
|
|
396
403
|
exports.getDocumentByEntryName = __webpack_exports__.getDocumentByEntryName;
|
|
404
|
+
exports.getDocumentTempEntry = __webpack_exports__.getDocumentTempEntry;
|
|
397
405
|
exports.processScriptPlaceholders = __webpack_exports__.processScriptPlaceholders;
|
|
398
406
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
399
407
|
"default",
|
|
400
408
|
"documentPlugin",
|
|
401
409
|
"getDocumentByEntryName",
|
|
410
|
+
"getDocumentTempEntry",
|
|
402
411
|
"processScriptPlaceholders"
|
|
403
412
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
404
413
|
Object.defineProperty(exports, '__esModule', {
|
package/dist/cjs/exports/head.js
CHANGED
|
@@ -41,12 +41,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
41
41
|
Helmet: ()=>Helmet,
|
|
42
42
|
default: ()=>exports_head
|
|
43
43
|
});
|
|
44
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
44
45
|
const external_react_namespaceObject = require("react");
|
|
45
46
|
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
|
|
46
47
|
const external_react_helmet_async_namespaceObject = require("react-helmet-async");
|
|
47
|
-
const runtime_js_namespaceObject = require("../core/context/runtime.js");
|
|
48
48
|
const Helmet = (props)=>{
|
|
49
|
-
const resolveComponent = external_react_default().useContext(
|
|
49
|
+
const resolveComponent = external_react_default().useContext(context_namespaceObject.RuntimeComponentResolverContext);
|
|
50
50
|
const Component = resolveComponent?.(external_react_helmet_async_namespaceObject.Helmet, {
|
|
51
51
|
name: 'head.Helmet'
|
|
52
52
|
}) ?? external_react_helmet_async_namespaceObject.Helmet;
|
package/dist/cjs/internal.js
CHANGED
|
@@ -28,9 +28,9 @@ var __webpack_require__ = {};
|
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
InternalRuntimeContext: ()=>
|
|
31
|
+
InternalRuntimeContext: ()=>context_namespaceObject.InternalRuntimeContext
|
|
32
32
|
});
|
|
33
|
-
const
|
|
33
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
34
34
|
exports.InternalRuntimeContext = __webpack_exports__.InternalRuntimeContext;
|
|
35
35
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
36
36
|
"InternalRuntimeContext"
|
|
@@ -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 = {
|
|
@@ -396,7 +396,7 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
|
|
|
396
396
|
source: rootLayout.toString(),
|
|
397
397
|
filename: rootLayoutFile
|
|
398
398
|
});
|
|
399
|
-
const hasAppInit = moduleExports.some((e)=>e.
|
|
399
|
+
const hasAppInit = moduleExports.some((e)=>'reexport-all' !== e.type && e.name === external_constants_js_namespaceObject.APP_INIT_EXPORTED);
|
|
400
400
|
const layoutPath = (0, utils_namespaceObject.formatImportPath)((0, external_utils_js_namespaceObject.getPathWithoutExt)((0, external_utils_js_namespaceObject.replaceWithAlias)(srcDirectory, rootLayoutFile, internalSrcAlias)));
|
|
401
401
|
if (hasAppInit) imports.push(`import { init as appInit } from '${layoutPath}';`);
|
|
402
402
|
else imports.push("let appInit;");
|
|
@@ -422,7 +422,7 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
|
|
|
422
422
|
enableRsc: true,
|
|
423
423
|
});
|
|
424
424
|
`;
|
|
425
|
-
return `${imports.join('\n')}
|
|
425
|
+
else return `${imports.join('\n')}
|
|
426
426
|
|
|
427
427
|
import { routes } from '${routesImportPath}';
|
|
428
428
|
|
|
@@ -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;
|
|
@@ -98,6 +98,7 @@ const parseModule = async ({ source, filename })=>{
|
|
|
98
98
|
});
|
|
99
99
|
content = result.code;
|
|
100
100
|
}
|
|
101
|
+
await (0, external_es_module_lexer_namespaceObject.init)();
|
|
101
102
|
return (0, external_es_module_lexer_namespaceObject.parse)(content);
|
|
102
103
|
};
|
|
103
104
|
const hasLoader = async (filename, source)=>{
|
|
@@ -108,7 +109,7 @@ const hasLoader = async (filename, source)=>{
|
|
|
108
109
|
source: content.toString(),
|
|
109
110
|
filename
|
|
110
111
|
});
|
|
111
|
-
return moduleExports.some((e)=>e.
|
|
112
|
+
return moduleExports.some((e)=>'reexport-all' !== e.type && e.name === external_constants_js_namespaceObject.LOADER_EXPORT_NAME);
|
|
112
113
|
}
|
|
113
114
|
return false;
|
|
114
115
|
};
|
|
@@ -120,7 +121,7 @@ const hasAction = async (filename, source)=>{
|
|
|
120
121
|
source: content.toString(),
|
|
121
122
|
filename
|
|
122
123
|
});
|
|
123
|
-
return moduleExports.some((e)=>e.
|
|
124
|
+
return moduleExports.some((e)=>'reexport-all' !== e.type && e.name === external_constants_js_namespaceObject.ACTION_EXPORT_NAME);
|
|
124
125
|
}
|
|
125
126
|
return false;
|
|
126
127
|
};
|
|
@@ -60,7 +60,8 @@ const DeferredDataScripts = (props)=>{
|
|
|
60
60
|
}, []);
|
|
61
61
|
const deferredScripts = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
62
62
|
if (!staticContext) return null;
|
|
63
|
-
const
|
|
63
|
+
const requestStorage = node_namespaceObject.storage.useContext();
|
|
64
|
+
const activeDeferreds = requestStorage.activeDeferreds;
|
|
64
65
|
const _ROUTER_DATA = {
|
|
65
66
|
loaderData: staticContext.loaderData,
|
|
66
67
|
errors: (0, external_utils_js_namespaceObject.serializeErrors)(staticContext.errors)
|
|
@@ -73,6 +74,7 @@ const DeferredDataScripts = (props)=>{
|
|
|
73
74
|
const deferredDataScripts = [];
|
|
74
75
|
const initialScripts = Array.from(activeDeferreds.entries()).map(([routeId, deferredData])=>{
|
|
75
76
|
const pendingKeys = new Set(deferredData.pendingKeys);
|
|
77
|
+
requestStorage.deferredScriptKeys?.set(routeId, Array.from(pendingKeys));
|
|
76
78
|
const { deferredKeys } = deferredData;
|
|
77
79
|
const deferredKeyPromiseManifests = deferredKeys.map((key)=>{
|
|
78
80
|
if (pendingKeys.has(key)) return {
|
|
@@ -83,7 +85,7 @@ const DeferredDataScripts = (props)=>{
|
|
|
83
85
|
(0, node_namespaceObject.serializeJson)(key)
|
|
84
86
|
]
|
|
85
87
|
};
|
|
86
|
-
{
|
|
88
|
+
else {
|
|
87
89
|
const trackedPromise = deferredData.data[key];
|
|
88
90
|
if (void 0 !== trackedPromise._error) {
|
|
89
91
|
const error = toDeferredErrorInfo(trackedPromise._error);
|
|
@@ -95,15 +97,16 @@ const DeferredDataScripts = (props)=>{
|
|
|
95
97
|
(0, node_namespaceObject.serializeJson)(error)
|
|
96
98
|
]
|
|
97
99
|
};
|
|
100
|
+
} else {
|
|
101
|
+
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`);
|
|
102
|
+
return {
|
|
103
|
+
key,
|
|
104
|
+
routerDataFnName: 'p',
|
|
105
|
+
routerDataFnArgs: [
|
|
106
|
+
(0, node_namespaceObject.serializeJson)(trackedPromise._data)
|
|
107
|
+
]
|
|
108
|
+
};
|
|
98
109
|
}
|
|
99
|
-
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`);
|
|
100
|
-
return {
|
|
101
|
-
key,
|
|
102
|
-
routerDataFnName: 'p',
|
|
103
|
-
routerDataFnArgs: [
|
|
104
|
-
(0, node_namespaceObject.serializeJson)(trackedPromise._data)
|
|
105
|
-
]
|
|
106
|
-
};
|
|
107
110
|
}
|
|
108
111
|
});
|
|
109
112
|
return {
|
|
@@ -70,10 +70,10 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
70
70
|
NavLink: ()=>NavLink
|
|
71
71
|
});
|
|
72
72
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
73
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
73
74
|
const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
74
75
|
const external_react_namespaceObject = require("react");
|
|
75
76
|
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
|
|
76
|
-
const index_js_namespaceObject = require("../../core/context/index.js");
|
|
77
77
|
const getWebpackChunkLoader = ()=>__webpack_chunk_load__;
|
|
78
78
|
const getWebpackPublicPath = ()=>{
|
|
79
79
|
try {
|
|
@@ -200,7 +200,7 @@ const getDataHref = (route, pathname, basename)=>{
|
|
|
200
200
|
};
|
|
201
201
|
const PrefetchPageLinks = ({ path, includeData })=>{
|
|
202
202
|
const { pathname } = path;
|
|
203
|
-
const context = (0, external_react_namespaceObject.useContext)(
|
|
203
|
+
const context = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
204
204
|
const { routeManifest, routes } = context;
|
|
205
205
|
const { routeAssets } = routeManifest || {};
|
|
206
206
|
const policy = context.linkPrefetchPolicy;
|
|
@@ -254,7 +254,7 @@ const PrefetchPageLinks = ({ path, includeData })=>{
|
|
|
254
254
|
};
|
|
255
255
|
const PrefetchDataLinks = ({ matches, path, routeManifest })=>{
|
|
256
256
|
const { pathname, search, hash } = path;
|
|
257
|
-
const policy = (0, external_react_namespaceObject.useContext)(
|
|
257
|
+
const policy = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext).linkPrefetchPolicy;
|
|
258
258
|
const currentMatches = (0, router_namespaceObject.useMatches)();
|
|
259
259
|
const basename = (0, router_namespaceObject.useHref)('/');
|
|
260
260
|
const dataHrefs = (0, external_react_namespaceObject.useMemo)(()=>matches?.filter((match, index)=>{
|
|
@@ -287,7 +287,7 @@ const PrefetchDataLinks = ({ matches, path, routeManifest })=>{
|
|
|
287
287
|
};
|
|
288
288
|
const createPrefetchLink = (Link)=>/*#__PURE__*/ (external_react_default()).forwardRef(({ to, prefetch, preload, ...props }, forwardedRef)=>{
|
|
289
289
|
const isAbsolute = 'string' == typeof to && ABSOLUTE_URL_REGEX.test(to);
|
|
290
|
-
const policy = (0, external_react_namespaceObject.useContext)(
|
|
290
|
+
const policy = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext).linkPrefetchPolicy;
|
|
291
291
|
const [shouldPrefetch, shouldPreload, prefetchHandlers, setViewportElement] = usePrefetchBehavior(prefetch, preload, props, policy);
|
|
292
292
|
const setAnchorRef = external_react_default().useCallback((element)=>{
|
|
293
293
|
setViewportElement(element);
|
|
@@ -37,13 +37,12 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
37
37
|
routerProviderRegistryHooks: ()=>routerProviderRegistryHooks
|
|
38
38
|
});
|
|
39
39
|
const plugin_namespaceObject = require("@modern-js/plugin");
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const onAfterHydrateRouter = createRouterSyncHook();
|
|
40
|
+
const modifyRoutes = (0, plugin_namespaceObject.createSyncHook)();
|
|
41
|
+
const onBeforeCreateRoutes = (0, plugin_namespaceObject.createSyncHook)();
|
|
42
|
+
const onBeforeCreateRouter = (0, plugin_namespaceObject.createSyncHook)();
|
|
43
|
+
const onAfterCreateRouter = (0, plugin_namespaceObject.createSyncHook)();
|
|
44
|
+
const onBeforeHydrateRouter = (0, plugin_namespaceObject.createSyncHook)();
|
|
45
|
+
const onAfterHydrateRouter = (0, plugin_namespaceObject.createSyncHook)();
|
|
47
46
|
const routerProviderRegistryHooks = {
|
|
48
47
|
modifyRoutes,
|
|
49
48
|
onBeforeCreateRoutes,
|
|
@@ -34,11 +34,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
34
34
|
routerPlugin: ()=>routerPlugin
|
|
35
35
|
});
|
|
36
36
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
37
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
37
38
|
const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
|
|
38
39
|
const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
39
40
|
const url_namespaceObject = require("@modern-js/runtime-utils/url");
|
|
40
41
|
const external_react_namespaceObject = require("react");
|
|
41
|
-
const index_js_namespaceObject = require("../../core/context/index.js");
|
|
42
42
|
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
43
43
|
const external_PrefetchLink_js_namespaceObject = require("./PrefetchLink.js");
|
|
44
44
|
const external_rsc_router_js_namespaceObject = require("./rsc-router.js");
|
|
@@ -92,8 +92,8 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
92
92
|
const mergedConfig = (0, merge_namespaceObject.merge)(api.getRuntimeConfig().router || {}, userConfig);
|
|
93
93
|
const { serverBase = [], supportHtml5History = true, basename = '', routesConfig, createRoutes } = mergedConfig;
|
|
94
94
|
finalRouteConfig = {
|
|
95
|
-
routes: (0,
|
|
96
|
-
globalApp: (0,
|
|
95
|
+
routes: (0, context_namespaceObject.getGlobalRoutes)(),
|
|
96
|
+
globalApp: (0, context_namespaceObject.getGlobalLayoutApp)(),
|
|
97
97
|
...routesConfig
|
|
98
98
|
};
|
|
99
99
|
if (!finalRouteConfig.routes && !createRoutes) return App;
|
|
@@ -101,24 +101,20 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
101
101
|
const match = serverBase.find((baseUrl)=>isSegmentPrefix(pathname, baseUrl));
|
|
102
102
|
return match || '/';
|
|
103
103
|
};
|
|
104
|
-
|
|
104
|
+
const routerCache = new WeakMap();
|
|
105
105
|
const RouterWrapper = (props)=>{
|
|
106
|
-
const routerResult = useRouterCreation(("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0,
|
|
106
|
+
const routerResult = useRouterCreation(("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0, context_namespaceObject.getGlobalEnableRsc)()) ? {
|
|
107
107
|
...props,
|
|
108
108
|
rscPayload: props?.rscPayload
|
|
109
109
|
} : props, {
|
|
110
110
|
api: api,
|
|
111
|
+
cache: routerCache,
|
|
111
112
|
createRoutes,
|
|
112
113
|
supportHtml5History,
|
|
113
114
|
selectBasePath,
|
|
114
115
|
basename
|
|
115
116
|
});
|
|
116
|
-
const router =
|
|
117
|
-
if (cachedRouter) return cachedRouter;
|
|
118
|
-
cachedRouter = routerResult.router;
|
|
119
|
-
return cachedRouter;
|
|
120
|
-
}, []);
|
|
121
|
-
const { routes } = routerResult;
|
|
117
|
+
const { router, routes } = routerResult;
|
|
122
118
|
routesContainer.current = routes;
|
|
123
119
|
beforeCreateRouter = false;
|
|
124
120
|
const routerContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
@@ -155,20 +151,21 @@ function isSegmentPrefix(pathname, base) {
|
|
|
155
151
|
return p === b || p.startsWith(`${b}/`);
|
|
156
152
|
}
|
|
157
153
|
function useRouterCreation(props, options) {
|
|
158
|
-
const { api, createRoutes, supportHtml5History, selectBasePath, basename } = options;
|
|
159
|
-
const runtimeContext = (0, external_react_namespaceObject.useContext)(
|
|
154
|
+
const { api, cache, createRoutes, supportHtml5History, selectBasePath, basename } = options;
|
|
155
|
+
const runtimeContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
160
156
|
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
161
157
|
const _basename = '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
162
158
|
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
163
|
-
const rscPayload = ("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0,
|
|
164
|
-
let hydrationData = "u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA : true === (0,
|
|
165
|
-
|
|
159
|
+
const rscPayload = ("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0, context_namespaceObject.getGlobalEnableRsc)()) && props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
160
|
+
let hydrationData = "u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA : true === (0, context_namespaceObject.getGlobalEnableRsc)() ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA;
|
|
161
|
+
const result = (0, external_react_namespaceObject.useRef)(cache.get(runtimeContext) ?? null);
|
|
162
|
+
if (null === result.current) {
|
|
166
163
|
if (hydrationData?.errors) hydrationData = {
|
|
167
164
|
...hydrationData,
|
|
168
165
|
errors: (0, external_utils_js_namespaceObject.deserializeErrors)(hydrationData.errors)
|
|
169
166
|
};
|
|
170
167
|
let routes = null;
|
|
171
|
-
routes = ("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0,
|
|
168
|
+
routes = ("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0, context_namespaceObject.getGlobalEnableRsc)()) && (0, context_namespaceObject.getGlobalIsRscClient)() ? createRoutes ? createRoutes() : (0, external_utils_js_namespaceObject.createRouteObjectsFromConfig)({
|
|
172
169
|
routesConfig: finalRouteConfig
|
|
173
170
|
}) : createRoutes ? createRoutes() : (0, router_namespaceObject.createRoutesFromElements)((0, external_utils_js_namespaceObject.renderRoutes)({
|
|
174
171
|
routesConfig: finalRouteConfig,
|
|
@@ -176,12 +173,14 @@ function useRouterCreation(props, options) {
|
|
|
176
173
|
}));
|
|
177
174
|
if (!routes) routes = [];
|
|
178
175
|
const hooks = api.getHooks();
|
|
179
|
-
if (("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0,
|
|
176
|
+
if (("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0, context_namespaceObject.getGlobalEnableRsc)()) && rscPayload) try {
|
|
180
177
|
const router = (0, external_rsc_router_js_namespaceObject.createClientRouterFromPayload)(rscPayload, routes, _basename);
|
|
181
|
-
|
|
178
|
+
result.current = {
|
|
182
179
|
router,
|
|
183
180
|
routes: router.routes || []
|
|
184
181
|
};
|
|
182
|
+
cache.set(runtimeContext, result.current);
|
|
183
|
+
return result.current;
|
|
185
184
|
} catch (e) {
|
|
186
185
|
console.error('Failed to create router from RSC payload:', e);
|
|
187
186
|
}
|
|
@@ -230,17 +229,13 @@ function useRouterCreation(props, options) {
|
|
|
230
229
|
};
|
|
231
230
|
return originSubscribe(wrappedListener);
|
|
232
231
|
};
|
|
233
|
-
|
|
232
|
+
result.current = {
|
|
234
233
|
router,
|
|
235
234
|
routes: modifiedRoutes
|
|
236
235
|
};
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
_basename,
|
|
241
|
-
hydrationData,
|
|
242
|
-
getBlockNavState
|
|
243
|
-
]);
|
|
236
|
+
cache.set(runtimeContext, result.current);
|
|
237
|
+
}
|
|
238
|
+
return result.current;
|
|
244
239
|
}
|
|
245
240
|
exports.beforeCreateRouter = __webpack_exports__.beforeCreateRouter;
|
|
246
241
|
exports.finalRouteConfig = __webpack_exports__.finalRouteConfig;
|
|
@@ -41,13 +41,13 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
41
41
|
routerPlugin: ()=>routerPlugin
|
|
42
42
|
});
|
|
43
43
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
44
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
44
45
|
const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
|
|
45
46
|
const node_namespaceObject = require("@modern-js/runtime-utils/node");
|
|
46
47
|
const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
47
48
|
const time_namespaceObject = require("@modern-js/runtime-utils/time");
|
|
48
49
|
const constants_namespaceObject = require("@modern-js/utils/universal/constants");
|
|
49
50
|
const external_react_namespaceObject = require("react");
|
|
50
|
-
const index_js_namespaceObject = require("../../core/context/index.js");
|
|
51
51
|
const index_server_js_namespaceObject = require("../../core/context/serverPayload/index.server.js");
|
|
52
52
|
const external_DeferredDataScripts_node_js_namespaceObject = require("./DeferredDataScripts.node.js");
|
|
53
53
|
var external_DeferredDataScripts_node_js_default = /*#__PURE__*/ __webpack_require__.n(external_DeferredDataScripts_node_js_namespaceObject);
|
|
@@ -58,11 +58,10 @@ const external_utils_js_namespaceObject = require("./utils.js");
|
|
|
58
58
|
function createRemixRequest(request) {
|
|
59
59
|
const method = 'GET';
|
|
60
60
|
const { headers } = request;
|
|
61
|
-
const controller = new AbortController();
|
|
62
61
|
return new Request(request.url, {
|
|
63
62
|
method,
|
|
64
63
|
headers,
|
|
65
|
-
signal:
|
|
64
|
+
signal: request.signal
|
|
66
65
|
});
|
|
67
66
|
}
|
|
68
67
|
const routerPlugin = (userConfig = {})=>({
|
|
@@ -81,12 +80,12 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
81
80
|
const pluginConfig = api.getRuntimeConfig();
|
|
82
81
|
const { basename = '', routesConfig, createRoutes } = (0, merge_namespaceObject.merge)(pluginConfig.router || {}, userConfig);
|
|
83
82
|
finalRouteConfig = {
|
|
84
|
-
routes: (0,
|
|
85
|
-
globalApp: (0,
|
|
83
|
+
routes: (0, context_namespaceObject.getGlobalRoutes)(),
|
|
84
|
+
globalApp: (0, context_namespaceObject.getGlobalLayoutApp)(),
|
|
86
85
|
...routesConfig
|
|
87
86
|
};
|
|
88
87
|
if (!finalRouteConfig.routes && !createRoutes) return;
|
|
89
|
-
const enableRsc = (0,
|
|
88
|
+
const enableRsc = (0, context_namespaceObject.getGlobalEnableRsc)();
|
|
90
89
|
if (enableRsc) await (0, external_rsc_router_js_namespaceObject.prepareRSCRoutes)(finalRouteConfig.routes);
|
|
91
90
|
const { request, mode: ssrMode, nonce, loaderFailureMode = 'errorBoundary', baseUrl } = context.ssrContext;
|
|
92
91
|
const _basename = '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, basename) : baseUrl;
|
|
@@ -154,9 +153,9 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
154
153
|
api.wrapRoot((App)=>{
|
|
155
154
|
if (!finalRouteConfig) return App;
|
|
156
155
|
const getRouteApp = ()=>{
|
|
157
|
-
const enableRsc = (0,
|
|
156
|
+
const enableRsc = (0, context_namespaceObject.getGlobalEnableRsc)();
|
|
158
157
|
return (props)=>{
|
|
159
|
-
const context = (0, external_react_namespaceObject.useContext)(
|
|
158
|
+
const context = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
160
159
|
const { routerContext, routes } = context;
|
|
161
160
|
const { basename } = routerContext;
|
|
162
161
|
if (enableRsc) return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
@@ -166,7 +165,7 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
166
165
|
}) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_rsc_router_js_namespaceObject.RSCStaticRouter, {
|
|
167
166
|
basename: basename
|
|
168
167
|
});
|
|
169
|
-
{
|
|
168
|
+
else {
|
|
170
169
|
const { nonce, mode, useJsonScript } = context.ssrContext;
|
|
171
170
|
const remixRouter = (0, router_namespaceObject.createStaticRouter)(routes, routerContext);
|
|
172
171
|
const routerWrapper = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
package/dist/esm/cli/code.mjs
CHANGED
|
@@ -43,7 +43,7 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
43
43
|
entryName,
|
|
44
44
|
customEntry,
|
|
45
45
|
mountId,
|
|
46
|
-
enableRsc: config.server.rsc,
|
|
46
|
+
enableRsc: Boolean(config.server.rsc),
|
|
47
47
|
isNestedRouter: !!entrypoint.nestedRoutesEntry
|
|
48
48
|
}) : __rspack_external__template_mjs_d1604447.entryForCSRWithRSC({
|
|
49
49
|
metaName,
|
|
@@ -86,7 +86,7 @@ requestHandler.catch(() => {});`, 'utf8');
|
|
|
86
86
|
mode: ssrMode,
|
|
87
87
|
customServerEntry,
|
|
88
88
|
srcDirectory,
|
|
89
|
-
enableRsc: config.server.rsc
|
|
89
|
+
enableRsc: Boolean(config.server.rsc)
|
|
90
90
|
});
|
|
91
91
|
const indexServerFile = path.resolve(internalDirectory, `./${entryName}/${SERVER_ENTRY_POINT_FILE_NAME}`);
|
|
92
92
|
await fs.outputFile(indexServerFile, indexServerCode, 'utf8');
|
package/dist/esm/cli/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { cleanRequireCache } from "@modern-js/utils";
|
|
2
1
|
import path_0 from "path";
|
|
3
2
|
import { documentPlugin } from "../document/cli/index.mjs";
|
|
4
3
|
import { getEntrypointRoutesDir, getEntrypointRoutesOwner, handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints, isRouteEntry, routerPlugin, updateNestedRoutesSpec } from "../router/cli/index.mjs";
|
|
@@ -70,12 +69,6 @@ const runtimePlugin = (params)=>({
|
|
|
70
69
|
}
|
|
71
70
|
};
|
|
72
71
|
});
|
|
73
|
-
api.onBeforeRestart(()=>{
|
|
74
|
-
cleanRequireCache([
|
|
75
|
-
require.resolve('../router/cli'),
|
|
76
|
-
require.resolve('./ssr')
|
|
77
|
-
]);
|
|
78
|
-
});
|
|
79
72
|
}
|
|
80
73
|
});
|
|
81
74
|
const cli = runtimePlugin;
|
|
@@ -2,6 +2,7 @@ import { fs } from "@modern-js/utils";
|
|
|
2
2
|
import path_0 from "path";
|
|
3
3
|
const normalizeChunkId = (id)=>'string' == typeof id && /^\d+$/.test(id) ? Number(id) : id;
|
|
4
4
|
const DEFAULT_CHUNK_LOADING_GLOBAL = '__LOADABLE_LOADED_CHUNKS__';
|
|
5
|
+
const normalizeStatsPublicPath = (publicPath)=>'auto' === publicPath || 'auto/' === publicPath ? '/' : publicPath;
|
|
5
6
|
const normalizeChunkGroup = (group)=>({
|
|
6
7
|
...group,
|
|
7
8
|
chunks: (group.chunks || []).map(normalizeChunkId)
|
|
@@ -44,6 +45,7 @@ class LoadablePlugin {
|
|
|
44
45
|
for (const [name, ep] of Object.entries(stats.entrypoints || {}))entrypoints[name] = normalizeChunkGroup(ep);
|
|
45
46
|
const output = {
|
|
46
47
|
...stats,
|
|
48
|
+
publicPath: normalizeStatsPublicPath(stats.publicPath),
|
|
47
49
|
namedChunkGroups,
|
|
48
50
|
entrypoints,
|
|
49
51
|
generator: 'loadable-components',
|
|
@@ -120,8 +120,7 @@ function genHandlerCode({ mode, metaName, customServerEntry, srcDirectory, inter
|
|
|
120
120
|
return `
|
|
121
121
|
export * from '${realEntryPath}';
|
|
122
122
|
export { default as requestHandler } from '${realEntryPath}'`;
|
|
123
|
-
}
|
|
124
|
-
{
|
|
123
|
+
} else {
|
|
125
124
|
const entrySource = enableRsc ? SERVER_ENTRY_RSC : SERVER_ENTRY;
|
|
126
125
|
const serverEntry = transformServerEntry(entrySource, {
|
|
127
126
|
metaName: metaName || 'modern-js',
|
|
@@ -29,7 +29,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
29
29
|
if ('stream' === renderMode) return streamSSRHydrate();
|
|
30
30
|
function streamSSRHydrate() {
|
|
31
31
|
if (renderLevel !== RenderLevel.SERVER_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
32
|
-
{
|
|
32
|
+
else {
|
|
33
33
|
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
34
34
|
callback: callback,
|
|
35
35
|
children: App
|
|
@@ -45,7 +45,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
45
45
|
return stringSSRHydrate();
|
|
46
46
|
function stringSSRHydrate() {
|
|
47
47
|
if (renderLevel === RenderLevel.CLIENT_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
48
|
-
{
|
|
48
|
+
else {
|
|
49
49
|
if (renderLevel === RenderLevel.SERVER_RENDER) return loadableReady(()=>void 0, loadableReadyOptions).then(()=>{
|
|
50
50
|
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
51
51
|
callback: callback,
|
|
@@ -53,13 +53,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
53
53
|
});
|
|
54
54
|
return ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext));
|
|
55
55
|
});
|
|
56
|
-
|
|
57
|
-
if (null !== runtimeConsole && 'object' == typeof runtimeConsole) {
|
|
58
|
-
const warn = Reflect.get(runtimeConsole, 'warn');
|
|
59
|
-
if ('function' == typeof warn) Reflect.apply(warn, runtimeConsole, [
|
|
60
|
-
`unknow render level: ${renderLevel}, execute render()`
|
|
61
|
-
]);
|
|
62
|
-
}
|
|
56
|
+
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
63
57
|
return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
64
58
|
}
|
|
65
59
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { getGlobalInternalRuntimeContext, getInitialContext } from "@modern-js/runtime/context";
|
|
1
2
|
import { parseCookie } from "cookie";
|
|
2
3
|
import { createRoot } from "react-dom/client";
|
|
3
|
-
import { getGlobalInternalRuntimeContext } from "../context/index.mjs";
|
|
4
|
-
import { getInitialContext } from "../context/runtime.mjs";
|
|
5
4
|
import { wrapRuntimeContextProvider } from "../react/wrapper.mjs";
|
|
6
5
|
import { hydrateRoot, hydrateWithReact } from "./hydrate.mjs";
|
|
7
6
|
const IS_REACT18 = 'true' === process.env.IS_REACT18;
|
|
@@ -42,6 +42,6 @@ function getGlobalBasename() {
|
|
|
42
42
|
}
|
|
43
43
|
export { DefaultNotFound } from "../../router/runtime/DefaultNotFound.mjs";
|
|
44
44
|
export { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter, routerProviderRegistryHooks } from "../../router/runtime/hooks.mjs";
|
|
45
|
-
export { InternalRuntimeContext, RuntimeComponentResolverContext, RuntimeContext, getInitialContext } from "./runtime.mjs";
|
|
45
|
+
export { InternalRuntimeContext, ReactRuntimeContext, RuntimeComponentResolverContext, RuntimeContext, getInitialContext, useRuntimeContext } from "./runtime.mjs";
|
|
46
46
|
export { getServerPayload, setServerPayload } from "./serverPayload/index.mjs";
|
|
47
47
|
export { getCurrentEntryName, getGlobalApp, getGlobalBasename, getGlobalEnableRsc, getGlobalInternalRuntimeContext, getGlobalIsRscClient, getGlobalLayoutApp, getGlobalRSCRoot, getGlobalRoutes, setGlobalContext, setGlobalInternalRuntimeContext };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ReactRuntimeContext, RuntimeContext, useRuntimeContext } from "
|
|
1
|
+
export { ReactRuntimeContext, RuntimeContext, useRuntimeContext } from "@modern-js/runtime/context";
|