@bleedingdev/modern-js-runtime 3.5.0-ultramodern.98 → 3.8.1-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/index.js +1 -11
- package/dist/cjs/cli/ssr/index.js +1 -0
- package/dist/cjs/core/browser/hydrate.js +31 -27
- package/dist/cjs/core/browser/index.js +4 -15
- package/dist/cjs/core/react/wrapper.js +23 -28
- package/dist/cjs/core/server/requestResponse.js +5 -5
- package/dist/cjs/core/server/scriptOrder.js +1 -1
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +1 -10
- package/dist/cjs/core/server/string/index.js +3 -3
- package/dist/cjs/core/server/utils.js +3 -3
- package/dist/cjs/document/cli/index.js +5 -2
- package/dist/cjs/module-federation/distributed-ssr.js +13 -12
- package/dist/cjs/module-federation/last-known-good.js +1 -1
- package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +27 -38
- package/dist/cjs/router/cli/code/index.js +16 -9
- package/dist/cjs/router/cli/code/templates.js +36 -27
- package/dist/cjs/router/cli/handler.js +7 -1
- package/dist/cjs/router/runtime/plugin.js +22 -17
- package/dist/cjs/router/runtime/plugin.node.js +11 -3
- package/dist/cjs/router/runtime/provider.js +2 -2
- package/dist/cjs/router/runtime/redirect.js +51 -0
- package/dist/cjs/router/runtime/routerHelper.js +4 -0
- package/dist/cjs/router/runtime/rsc-router.js +2 -13
- package/dist/cjs/router/runtime/utils.js +3 -2
- package/dist/esm/cli/index.mjs +2 -12
- package/dist/esm/cli/ssr/index.mjs +1 -0
- package/dist/esm/core/browser/hydrate.mjs +30 -22
- package/dist/esm/core/browser/index.mjs +5 -13
- package/dist/esm/core/react/wrapper.mjs +23 -28
- package/dist/esm/core/server/requestResponse.mjs +4 -4
- package/dist/esm/core/server/scriptOrder.mjs +1 -1
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +1 -10
- package/dist/esm/core/server/string/index.mjs +3 -3
- package/dist/esm/core/server/utils.mjs +1 -1
- package/dist/esm/document/cli/index.mjs +1 -1
- package/dist/esm/module-federation/distributed-ssr.mjs +13 -12
- package/dist/esm/module-federation/last-known-good.mjs +1 -1
- package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +22 -33
- package/dist/esm/router/cli/code/index.mjs +16 -9
- package/dist/esm/router/cli/code/templates.mjs +36 -27
- package/dist/esm/router/cli/handler.mjs +7 -1
- package/dist/esm/router/runtime/plugin.mjs +24 -19
- package/dist/esm/router/runtime/plugin.node.mjs +12 -4
- package/dist/esm/router/runtime/provider.mjs +2 -2
- package/dist/esm/router/runtime/redirect.mjs +13 -0
- package/dist/esm/router/runtime/routerHelper.mjs +2 -1
- package/dist/esm/router/runtime/rsc-router.mjs +2 -13
- package/dist/esm/router/runtime/utils.mjs +2 -1
- package/dist/esm-node/cli/index.mjs +2 -12
- package/dist/esm-node/cli/ssr/index.mjs +1 -0
- package/dist/esm-node/core/browser/hydrate.mjs +30 -22
- package/dist/esm-node/core/browser/index.mjs +5 -13
- package/dist/esm-node/core/react/wrapper.mjs +23 -28
- package/dist/esm-node/core/server/requestResponse.mjs +4 -4
- package/dist/esm-node/core/server/scriptOrder.mjs +1 -1
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +1 -10
- package/dist/esm-node/core/server/string/index.mjs +3 -3
- package/dist/esm-node/core/server/utils.mjs +1 -1
- package/dist/esm-node/document/cli/index.mjs +1 -1
- package/dist/esm-node/module-federation/distributed-ssr.mjs +13 -12
- package/dist/esm-node/module-federation/last-known-good.mjs +1 -1
- package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +22 -33
- package/dist/esm-node/router/cli/code/index.mjs +16 -9
- package/dist/esm-node/router/cli/code/templates.mjs +36 -27
- package/dist/esm-node/router/cli/handler.mjs +7 -1
- package/dist/esm-node/router/runtime/plugin.mjs +24 -19
- package/dist/esm-node/router/runtime/plugin.node.mjs +12 -4
- package/dist/esm-node/router/runtime/provider.mjs +2 -2
- package/dist/esm-node/router/runtime/redirect.mjs +14 -0
- package/dist/esm-node/router/runtime/routerHelper.mjs +2 -1
- package/dist/esm-node/router/runtime/rsc-router.mjs +2 -13
- package/dist/esm-node/router/runtime/utils.mjs +2 -1
- package/dist/types/core/browser/hydrate.d.ts +0 -1
- package/dist/types/core/browser/index.d.ts +0 -1
- package/dist/types/core/server/utils.d.ts +1 -1
- package/dist/types/document/cli/index.d.ts +1 -0
- package/dist/types/module-federation/distributed-ssr.d.ts +3 -3
- package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +1 -1
- package/dist/types/router/cli/code/index.d.ts +6 -1
- package/dist/types/router/cli/code/templates.d.ts +8 -3
- package/dist/types/router/cli/handler.d.ts +4 -0
- package/dist/types/router/runtime/redirect.d.ts +1 -0
- package/dist/types/router/runtime/routerHelper.d.ts +7 -0
- package/dist/types/router/runtime/rsc-router.d.ts +1 -2
- package/package.json +15 -14
- package/rstest.config.mts +2 -0
|
@@ -84,8 +84,9 @@ async function generateRoutesForEntry(entrypoint, appContext) {
|
|
|
84
84
|
}
|
|
85
85
|
return routes;
|
|
86
86
|
}
|
|
87
|
-
const generateCode = async (appContext, config, entrypoints, api)=>{
|
|
87
|
+
const generateCode = async (appContext, config, entrypoints, api, options = {})=>{
|
|
88
88
|
const { internalDirectory, srcDirectory, internalSrcAlias, packageName } = appContext;
|
|
89
|
+
const includeRouteServerLoadersInSsrEntry = false !== options.includeRouteServerLoadersInSsrEntry || !(0, utils_namespaceObject.isUseRsc)(config);
|
|
89
90
|
const hooks = api.getHooks();
|
|
90
91
|
const generatedRoutesByEntry = {};
|
|
91
92
|
const eagerRouteComponentFilesByEntry = new Map();
|
|
@@ -143,6 +144,7 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
|
|
|
143
144
|
internalDirectory,
|
|
144
145
|
splitRouteChunks: config?.output?.splitRouteChunks,
|
|
145
146
|
isRscClientBundle: (0, utils_namespaceObject.isUseRsc)(config),
|
|
147
|
+
hydrateRscClientRoutes: options.hydrateRscClientRoutes,
|
|
146
148
|
srcDirectory,
|
|
147
149
|
internalSrcAlias: appContext.internalSrcAlias
|
|
148
150
|
})
|
|
@@ -150,12 +152,14 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
|
|
|
150
152
|
if (entrypoint.nestedRoutesEntry && ((0, utils_namespaceObject.isUseSSRBundle)(config) || (0, utils_namespaceObject.isUseRsc)(config))) {
|
|
151
153
|
const routesServerFile = (0, external_utils_js_namespaceObject.getServerLoadersFile)(internalDirectory, entryName);
|
|
152
154
|
const filtedRoutesForServer = (0, utils_namespaceObject.filterRoutesForServer)(routes);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
if (includeRouteServerLoadersInSsrEntry) {
|
|
156
|
+
const routesForServerLoaderMatches = (0, utils_namespaceObject.filterRoutesLoader)(routes);
|
|
157
|
+
const code = external_templates_js_namespaceObject.routesForServer({
|
|
158
|
+
routesForServerLoaderMatches
|
|
159
|
+
});
|
|
160
|
+
await utils_namespaceObject.fs.ensureFile(routesServerFile);
|
|
161
|
+
await utils_namespaceObject.fs.writeFile(routesServerFile, code);
|
|
162
|
+
} else await utils_namespaceObject.fs.remove(routesServerFile);
|
|
159
163
|
const serverRoutesCode = await external_templates_js_namespaceObject.fileSystemRoutes({
|
|
160
164
|
metaName,
|
|
161
165
|
routes: filtedRoutesForServer,
|
|
@@ -165,12 +169,15 @@ const generateCode = async (appContext, config, entrypoints, api)=>{
|
|
|
165
169
|
internalDirectory,
|
|
166
170
|
splitRouteChunks: config?.output?.splitRouteChunks,
|
|
167
171
|
isRscClientBundle: false,
|
|
172
|
+
isolateRouteDataInRscLayer: (0, utils_namespaceObject.isUseRsc)(config) && options.isolateRouteDataInRscLayer,
|
|
168
173
|
srcDirectory,
|
|
169
174
|
internalSrcAlias: appContext.internalSrcAlias
|
|
170
175
|
});
|
|
171
|
-
await utils_namespaceObject.fs.outputFile(external_path_default().resolve(internalDirectory, `./${entryName}
|
|
176
|
+
await utils_namespaceObject.fs.outputFile(external_path_default().resolve(internalDirectory, `./${entryName}/${options.serverRoutesFileName || 'routes.server.js'}`), serverRoutesCode, 'utf8');
|
|
172
177
|
}
|
|
173
|
-
const serverLoaderCombined = external_templates_js_namespaceObject.ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext
|
|
178
|
+
const serverLoaderCombined = external_templates_js_namespaceObject.ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext, {
|
|
179
|
+
includeRouteServerLoaders: includeRouteServerLoadersInSsrEntry
|
|
180
|
+
});
|
|
174
181
|
if (serverLoaderCombined) {
|
|
175
182
|
const serverLoaderFile = (0, external_utils_js_namespaceObject.getServerCombinedModuleFile)(internalDirectory, entryName);
|
|
176
183
|
await utils_namespaceObject.fs.outputFile(serverLoaderFile, serverLoaderCombined);
|
|
@@ -134,7 +134,7 @@ async function hasUseClientDirective(componentPath, srcDirectory, internalSrcAli
|
|
|
134
134
|
await fh?.close();
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
|
-
const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, splitRouteChunks = true, isRscClientBundle = false, srcDirectory, internalSrcAlias })=>{
|
|
137
|
+
const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, splitRouteChunks = true, isRscClientBundle = false, hydrateRscClientRoutes = false, isolateRouteDataInRscLayer = false, srcDirectory, internalSrcAlias })=>{
|
|
138
138
|
const components = [];
|
|
139
139
|
const loadings = [];
|
|
140
140
|
const errors = [];
|
|
@@ -206,7 +206,6 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
206
206
|
componentPath: route._component,
|
|
207
207
|
routeId: route.id
|
|
208
208
|
});
|
|
209
|
-
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
210
209
|
component = 'RootLayout';
|
|
211
210
|
} else if (splitRouteChunks) {
|
|
212
211
|
lazyImport = createLazyImport({
|
|
@@ -227,8 +226,9 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
227
226
|
component = `component_${components.length - 1}`;
|
|
228
227
|
}
|
|
229
228
|
const isClientComponent = 'nested' === route.type && Boolean(route._component) && Boolean(srcDirectory) && Boolean(internalSrcAlias) && await hasUseClientDirective(route._component, srcDirectory, internalSrcAlias);
|
|
230
|
-
const shouldHydrateRscRoute = isRscClientBundle && !isClientComponent && !route.loader && !route.data;
|
|
229
|
+
const shouldHydrateRscRoute = hydrateRscClientRoutes && isRscClientBundle && !isClientComponent && ('nested' !== route.type || !route.loader && !route.data);
|
|
231
230
|
const shouldIncludeClientBundle = !isRscClientBundle || isClientComponent || shouldHydrateRscRoute;
|
|
231
|
+
if ('nested' === route.type && route.isRoot && route._component && shouldIncludeClientBundle) rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
232
232
|
const finalRoute = {
|
|
233
233
|
...route,
|
|
234
234
|
loading,
|
|
@@ -289,32 +289,30 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
289
289
|
const importComponentsCode = components.map((component, index)=>`import component_${index} from '${component}';\n`).join('');
|
|
290
290
|
const importErrorComponentsCode = errors.map((error, index)=>`import error_${index} from '${error}';\n`).join('');
|
|
291
291
|
let importLoadersCode = '';
|
|
292
|
-
|
|
292
|
+
const isolatedRouteDataDirectory = external_path_default().join(internalDirectory, entryName, '__rsc_route_data__');
|
|
293
|
+
await utils_namespaceObject.fs.remove(isolatedRouteDataDirectory);
|
|
294
|
+
if (isolateRouteDataInRscLayer) await utils_namespaceObject.fs.ensureDir(isolatedRouteDataDirectory);
|
|
295
|
+
for (const [key, loaderInfo] of Object.entries(loadersMap)){
|
|
293
296
|
const { route } = loaderInfo;
|
|
294
|
-
|
|
297
|
+
const loaderRequest = `${(0, utils_namespaceObject.slash)(loaderInfo.filePath)}${getDataLoaderPath({
|
|
295
298
|
loaderId: key,
|
|
296
299
|
clientData: loaderInfo.clientData,
|
|
297
|
-
action: route.action,
|
|
300
|
+
action: route.action || false,
|
|
298
301
|
inline: loaderInfo.inline,
|
|
299
302
|
routeId: loaderInfo.routeId,
|
|
300
303
|
inValidSSRRoute: loaderInfo.inValidSSRRoute
|
|
301
|
-
})}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
action:
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
action: false,
|
|
314
|
-
inline: loaderInfo.inline,
|
|
315
|
-
routeId: loaderInfo.routeId,
|
|
316
|
-
inValidSSRRoute: loaderInfo.inValidSSRRoute
|
|
317
|
-
})}";\n`;
|
|
304
|
+
})}`;
|
|
305
|
+
let loaderImport = loaderRequest;
|
|
306
|
+
if (isolateRouteDataInRscLayer) {
|
|
307
|
+
const isolatedLoaderFile = external_path_default().join(isolatedRouteDataDirectory, `${key}.js`);
|
|
308
|
+
const isolatedLoaderCode = loaderInfo.inline ? route.action ? `export { loader, action } from ${JSON.stringify(loaderRequest)};` : `export { loader } from ${JSON.stringify(loaderRequest)};` : `export { default } from ${JSON.stringify(loaderRequest)};`;
|
|
309
|
+
await utils_namespaceObject.fs.outputFile(isolatedLoaderFile, isolatedLoaderCode, 'utf8');
|
|
310
|
+
loaderImport = `./__rsc_route_data__/${key}.js`;
|
|
311
|
+
}
|
|
312
|
+
if (loaderInfo.inline) if (route.action) importLoadersCode += `import { loader as ${key}, action as action_${loaderInfo.loaderId} } from "${loaderImport}";\n`;
|
|
313
|
+
else importLoadersCode += `import { loader as ${key} } from "${loaderImport}";\n`;
|
|
314
|
+
else importLoadersCode += `import ${key} from "${loaderImport}";\n`;
|
|
315
|
+
}
|
|
318
316
|
let importConfigsCode = '';
|
|
319
317
|
for (const [key, configPath] of Object.entries(configsMap))importConfigsCode += `import * as ${key} from "${(0, utils_namespaceObject.slash)(configPath)}";\n`;
|
|
320
318
|
await utils_namespaceObject.fs.ensureFile(loadersMapFile);
|
|
@@ -340,7 +338,7 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
340
338
|
${routeComponentsCode}
|
|
341
339
|
`;
|
|
342
340
|
};
|
|
343
|
-
function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
341
|
+
function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext, options = {}) {
|
|
344
342
|
const { entryName, isMainEntry } = entrypoint;
|
|
345
343
|
const { packageName } = appContext;
|
|
346
344
|
const ssr = (0, utils_namespaceObject.getEntryOptions)(entryName, isMainEntry, config.server.ssr, config.server.ssrByEntries, packageName);
|
|
@@ -348,6 +346,17 @@ function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
|
348
346
|
if (entrypoint.nestedRoutesEntry && (ssr || ssg)) {
|
|
349
347
|
const serverLoaderRuntime = require.resolve('@modern-js/plugin-data-loader/runtime');
|
|
350
348
|
const serverLoadersFile = './route-server-loaders.js';
|
|
349
|
+
const includeRouteServerLoaders = false !== options.includeRouteServerLoaders;
|
|
350
|
+
if (!includeRouteServerLoaders) {
|
|
351
|
+
if (!config.source.enableAsyncEntry) return `export * from "${(0, utils_namespaceObject.slash)(serverLoaderRuntime)}"`;
|
|
352
|
+
return `
|
|
353
|
+
async function loadModules() {
|
|
354
|
+
return import("${(0, utils_namespaceObject.slash)(serverLoaderRuntime)}");
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export { loadModules };
|
|
358
|
+
`;
|
|
359
|
+
}
|
|
351
360
|
const combinedModule = `export * from "${(0, utils_namespaceObject.slash)(serverLoaderRuntime)}"; export * from "${serverLoadersFile}"`;
|
|
352
361
|
if (!config.source.enableAsyncEntry) return combinedModule;
|
|
353
362
|
return `
|
|
@@ -368,7 +377,7 @@ function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
|
368
377
|
}
|
|
369
378
|
return null;
|
|
370
379
|
}
|
|
371
|
-
const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedRoutesEntry, internalSrcAlias, globalApp, rscType = false, basename })=>{
|
|
380
|
+
const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedRoutesEntry, internalSrcAlias, globalApp, rscType = false, routesImportPath = './routes', basename })=>{
|
|
372
381
|
const imports = [
|
|
373
382
|
`import { setGlobalContext } from '@${metaName}/runtime/context';`
|
|
374
383
|
];
|
|
@@ -399,7 +408,7 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
|
|
|
399
408
|
const enableRsc = Boolean(rscType);
|
|
400
409
|
if (isClient) return `${imports.join('\n')}
|
|
401
410
|
|
|
402
|
-
import { routes } from '
|
|
411
|
+
import { routes } from '${routesImportPath}';
|
|
403
412
|
|
|
404
413
|
const entryName = '${entryName}';
|
|
405
414
|
const basename = '${basename || '/'}';
|
|
@@ -415,7 +424,7 @@ const runtimeGlobalContext = async ({ entryName, metaName, srcDirectory, nestedR
|
|
|
415
424
|
`;
|
|
416
425
|
return `${imports.join('\n')}
|
|
417
426
|
|
|
418
|
-
import { routes } from '
|
|
427
|
+
import { routes } from '${routesImportPath}';
|
|
419
428
|
|
|
420
429
|
const entryName = '${entryName}';
|
|
421
430
|
const basename = '${basename || '/'}';
|
|
@@ -64,7 +64,12 @@ async function handleGeneratorEntryCode(api, entrypoints, options = {}) {
|
|
|
64
64
|
const { generatorRegisterCode, generateCode, generatorServerRegisterCode } = await import("./code/index.js");
|
|
65
65
|
originEntrypointsByKey.set(entrypointsKey, (0, lodash_namespaceObject.cloneDeep)(entrypoints));
|
|
66
66
|
const enableRsc = resolvedConfig?.server?.rsc;
|
|
67
|
-
const routesByEntry = await generateCode(appContext, resolvedConfig, entrypoints, api
|
|
67
|
+
const routesByEntry = await generateCode(appContext, resolvedConfig, entrypoints, api, {
|
|
68
|
+
hydrateRscClientRoutes: normalizedOptions.hydrateRscClientRoutes,
|
|
69
|
+
includeRouteServerLoadersInSsrEntry: normalizedOptions.includeRouteServerLoadersInSsrEntry,
|
|
70
|
+
isolateRouteDataInRscLayer: normalizedOptions.isolateRouteDataInRscLayer,
|
|
71
|
+
serverRoutesFileName: normalizedOptions.serverRoutesFileName
|
|
72
|
+
});
|
|
68
73
|
await Promise.all(entrypoints.map(async (entrypoint)=>{
|
|
69
74
|
if (entrypoint.nestedRoutesEntry || entrypoint.pageRoutesEntry) {
|
|
70
75
|
const route = appContext.serverRoutes.find((r)=>r.entryName === entrypoint.entryName);
|
|
@@ -87,6 +92,7 @@ async function handleGeneratorEntryCode(api, entrypoints, options = {}) {
|
|
|
87
92
|
internalSrcAlias: appContext.internalSrcAlias,
|
|
88
93
|
globalApp: entrypoint.fileSystemRoutes?.globalApp,
|
|
89
94
|
rscType: 'server',
|
|
95
|
+
routesImportPath: normalizedOptions.serverRoutesFileName ? `./${normalizedOptions.serverRoutesFileName.replace(/\.js$/, '')}` : void 0,
|
|
90
96
|
basename
|
|
91
97
|
}));
|
|
92
98
|
}
|
|
@@ -40,6 +40,7 @@ const url_namespaceObject = require("@modern-js/runtime-utils/url");
|
|
|
40
40
|
const external_react_namespaceObject = require("react");
|
|
41
41
|
const index_js_namespaceObject = require("../../core/context/index.js");
|
|
42
42
|
const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
|
|
43
|
+
const external_PrefetchLink_js_namespaceObject = require("./PrefetchLink.js");
|
|
43
44
|
const external_provider_js_namespaceObject = require("./provider.js");
|
|
44
45
|
const external_rsc_router_js_namespaceObject = require("./rsc-router.js");
|
|
45
46
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
@@ -73,9 +74,13 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
context.router = {
|
|
77
|
+
Link: external_PrefetchLink_js_namespaceObject.Link,
|
|
76
78
|
useMatches: router_namespaceObject.useMatches,
|
|
77
79
|
useLocation: router_namespaceObject.useLocation,
|
|
78
|
-
useHref: router_namespaceObject.useHref
|
|
80
|
+
useHref: router_namespaceObject.useHref,
|
|
81
|
+
useInRouterContext: router_namespaceObject.useInRouterContext,
|
|
82
|
+
useNavigate: router_namespaceObject.useNavigate,
|
|
83
|
+
useParams: router_namespaceObject.useParams
|
|
79
84
|
};
|
|
80
85
|
Object.defineProperty(context, 'routes', {
|
|
81
86
|
get () {
|
|
@@ -99,7 +104,7 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
99
104
|
};
|
|
100
105
|
let cachedRouter = null;
|
|
101
106
|
const RouterWrapper = (props)=>{
|
|
102
|
-
const routerResult = useRouterCreation(
|
|
107
|
+
const routerResult = useRouterCreation(("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0, index_js_namespaceObject.getGlobalEnableRsc)()) ? {
|
|
103
108
|
...props,
|
|
104
109
|
rscPayload: props?.rscPayload
|
|
105
110
|
} : props, {
|
|
@@ -117,18 +122,18 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
117
122
|
const { routes } = routerResult;
|
|
118
123
|
routesContainer.current = routes;
|
|
119
124
|
beforeCreateRouter = false;
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
const routerContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
126
|
+
children: [
|
|
127
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(router_namespaceObject.RouterProvider, {
|
|
128
|
+
router: router
|
|
129
|
+
}),
|
|
130
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(EmptyComponent, {}),
|
|
131
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(EmptyComponent, {})
|
|
132
|
+
]
|
|
133
|
+
});
|
|
129
134
|
return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
130
|
-
children:
|
|
131
|
-
}) :
|
|
135
|
+
children: routerContent
|
|
136
|
+
}) : routerContent;
|
|
132
137
|
};
|
|
133
138
|
return RouterWrapper;
|
|
134
139
|
});
|
|
@@ -156,15 +161,15 @@ function useRouterCreation(props, options) {
|
|
|
156
161
|
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
157
162
|
const _basename = '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
158
163
|
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
159
|
-
const rscPayload =
|
|
160
|
-
let hydrationData =
|
|
164
|
+
const rscPayload = ("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0, index_js_namespaceObject.getGlobalEnableRsc)()) && props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
165
|
+
let hydrationData = "u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA : true === (0, index_js_namespaceObject.getGlobalEnableRsc)() ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA;
|
|
161
166
|
return (0, external_react_namespaceObject.useMemo)(()=>{
|
|
162
167
|
if (hydrationData?.errors) hydrationData = {
|
|
163
168
|
...hydrationData,
|
|
164
169
|
errors: (0, external_utils_js_namespaceObject.deserializeErrors)(hydrationData.errors)
|
|
165
170
|
};
|
|
166
171
|
let routes = null;
|
|
167
|
-
routes =
|
|
172
|
+
routes = ("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0, index_js_namespaceObject.getGlobalEnableRsc)()) && (0, index_js_namespaceObject.getGlobalIsRscClient)() ? createRoutes ? createRoutes() : (0, external_utils_js_namespaceObject.createRouteObjectsFromConfig)({
|
|
168
173
|
routesConfig: finalRouteConfig
|
|
169
174
|
}) : createRoutes ? createRoutes() : (0, router_namespaceObject.createRoutesFromElements)((0, external_utils_js_namespaceObject.renderRoutes)({
|
|
170
175
|
routesConfig: finalRouteConfig,
|
|
@@ -172,7 +177,7 @@ function useRouterCreation(props, options) {
|
|
|
172
177
|
}));
|
|
173
178
|
if (!routes) routes = [];
|
|
174
179
|
const hooks = api.getHooks();
|
|
175
|
-
if (
|
|
180
|
+
if (("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0, index_js_namespaceObject.getGlobalEnableRsc)()) && rscPayload) try {
|
|
176
181
|
const router = (0, external_rsc_router_js_namespaceObject.createClientRouterFromPayload)(rscPayload, routes, _basename);
|
|
177
182
|
return {
|
|
178
183
|
router,
|
|
@@ -52,6 +52,7 @@ const index_server_js_namespaceObject = require("../../core/context/serverPayloa
|
|
|
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);
|
|
54
54
|
const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
|
|
55
|
+
const external_PrefetchLink_js_namespaceObject = require("./PrefetchLink.js");
|
|
55
56
|
const external_provider_js_namespaceObject = require("./provider.js");
|
|
56
57
|
const external_rsc_router_js_namespaceObject = require("./rsc-router.js");
|
|
57
58
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
@@ -89,6 +90,13 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
89
90
|
setup: (api)=>{
|
|
90
91
|
let finalRouteConfig = {};
|
|
91
92
|
api.onBeforeRender(async (context, interrupt)=>{
|
|
93
|
+
context.router = {
|
|
94
|
+
Link: external_PrefetchLink_js_namespaceObject.Link,
|
|
95
|
+
useInRouterContext: router_namespaceObject.useInRouterContext,
|
|
96
|
+
useLocation: router_namespaceObject.useLocation,
|
|
97
|
+
useNavigate: router_namespaceObject.useNavigate,
|
|
98
|
+
useParams: router_namespaceObject.useParams
|
|
99
|
+
};
|
|
92
100
|
const pluginConfig = api.getRuntimeConfig();
|
|
93
101
|
const { basename = '', routesConfig, createRoutes } = (0, merge_namespaceObject.merge)(pluginConfig.router || {}, userConfig);
|
|
94
102
|
finalRouteConfig = {
|
|
@@ -177,10 +185,8 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
177
185
|
const enableRsc = (0, index_js_namespaceObject.getGlobalEnableRsc)();
|
|
178
186
|
return (props)=>{
|
|
179
187
|
const context = (0, external_react_namespaceObject.useContext)(index_js_namespaceObject.InternalRuntimeContext);
|
|
180
|
-
const { routerContext,
|
|
181
|
-
const { nonce, mode, useJsonScript } = ssrContext;
|
|
188
|
+
const { routerContext, routes } = context;
|
|
182
189
|
const { basename } = routerContext;
|
|
183
|
-
const remixRouter = (0, router_namespaceObject.createStaticRouter)(routes, routerContext);
|
|
184
190
|
if (enableRsc) return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
185
191
|
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_rsc_router_js_namespaceObject.RSCStaticRouter, {
|
|
186
192
|
basename: basename
|
|
@@ -189,6 +195,8 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
189
195
|
basename: basename
|
|
190
196
|
});
|
|
191
197
|
{
|
|
198
|
+
const { nonce, mode, useJsonScript } = context.ssrContext;
|
|
199
|
+
const remixRouter = (0, router_namespaceObject.createStaticRouter)(routes, routerContext);
|
|
192
200
|
const routerWrapper = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
193
201
|
children: [
|
|
194
202
|
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(router_namespaceObject.StaticRouterProvider, {
|
|
@@ -53,7 +53,7 @@ function createRouterProviderRealm(registrations) {
|
|
|
53
53
|
const providers = new Map();
|
|
54
54
|
let defaultProvider;
|
|
55
55
|
for (const registration of registrations){
|
|
56
|
-
if (
|
|
56
|
+
if (0 === registration.name.length) throw new Error('[@modern-js/runtime] A router provider realm cannot contain an unnamed provider.');
|
|
57
57
|
if (providers.has(registration.name)) throw new Error(`[@modern-js/runtime] Router provider "${registration.name}" is declared more than once in the same runtime realm.`);
|
|
58
58
|
if (true === registration.isDefault && void 0 !== defaultProvider && defaultProvider !== registration.name) throw new Error(`[@modern-js/runtime] Router provider realm declares both "${defaultProvider}" and "${registration.name}" as defaults.`);
|
|
59
59
|
providers.set(registration.name, registration.factory);
|
|
@@ -63,7 +63,7 @@ function createRouterProviderRealm(registrations) {
|
|
|
63
63
|
...providers.keys()
|
|
64
64
|
]);
|
|
65
65
|
return Object.freeze({
|
|
66
|
-
...defaultProvider ? {
|
|
66
|
+
...void 0 !== defaultProvider ? {
|
|
67
67
|
defaultProvider
|
|
68
68
|
} : {},
|
|
69
69
|
get: (name)=>providers.get(name),
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
const handleRSCRedirect = (headers, basename, status)=>{
|
|
31
|
+
const newHeaders = new Headers(headers);
|
|
32
|
+
let redirectUrl = headers.get('Location');
|
|
33
|
+
if ('/' !== basename) redirectUrl = redirectUrl.replace(basename, '');
|
|
34
|
+
newHeaders.set('X-Modernjs-Redirect', redirectUrl);
|
|
35
|
+
newHeaders.set('X-Modernjs-BaseUrl', basename);
|
|
36
|
+
newHeaders.delete('Location');
|
|
37
|
+
return new Response(null, {
|
|
38
|
+
status,
|
|
39
|
+
headers: newHeaders
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
43
|
+
handleRSCRedirect: handleRSCRedirect
|
|
44
|
+
});
|
|
45
|
+
exports.handleRSCRedirect = __webpack_exports__.handleRSCRedirect;
|
|
46
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
47
|
+
"handleRSCRedirect"
|
|
48
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
49
|
+
Object.defineProperty(exports, '__esModule', {
|
|
50
|
+
value: true
|
|
51
|
+
});
|
|
@@ -31,9 +31,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
createShouldRevalidate: ()=>createShouldRevalidate,
|
|
32
32
|
handleRouteModule: ()=>handleRouteModule,
|
|
33
33
|
handleRouteModuleError: ()=>handleRouteModuleError,
|
|
34
|
+
isRouteErrorResponse: ()=>isRouteErrorResponse,
|
|
34
35
|
resolveRouteComponent: ()=>resolveRouteComponent
|
|
35
36
|
});
|
|
36
37
|
const constants_namespaceObject = require("@modern-js/utils/universal/constants");
|
|
38
|
+
const isRouteErrorResponse = (error)=>null !== error && 'object' == typeof error && 'number' == typeof error.status && 'string' == typeof error.statusText && 'boolean' == typeof error.internal && 'data' in error;
|
|
37
39
|
const isObjectLike = (value)=>'object' == typeof value && null !== value || 'function' == typeof value;
|
|
38
40
|
const isRouteComponent = (value)=>'function' == typeof value || isObjectLike(value) && '$$typeof' in value;
|
|
39
41
|
const getRouteModules = ()=>{
|
|
@@ -89,11 +91,13 @@ const handleRouteModuleError = (error)=>{
|
|
|
89
91
|
exports.createShouldRevalidate = __webpack_exports__.createShouldRevalidate;
|
|
90
92
|
exports.handleRouteModule = __webpack_exports__.handleRouteModule;
|
|
91
93
|
exports.handleRouteModuleError = __webpack_exports__.handleRouteModuleError;
|
|
94
|
+
exports.isRouteErrorResponse = __webpack_exports__.isRouteErrorResponse;
|
|
92
95
|
exports.resolveRouteComponent = __webpack_exports__.resolveRouteComponent;
|
|
93
96
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
94
97
|
"createShouldRevalidate",
|
|
95
98
|
"handleRouteModule",
|
|
96
99
|
"handleRouteModuleError",
|
|
100
|
+
"isRouteErrorResponse",
|
|
97
101
|
"resolveRouteComponent"
|
|
98
102
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
99
103
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -40,7 +40,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
40
40
|
RSCStaticRouter: ()=>RSCStaticRouter,
|
|
41
41
|
createClientRouterFromPayload: ()=>createClientRouterFromPayload,
|
|
42
42
|
createServerPayload: ()=>createServerPayload,
|
|
43
|
-
handleRSCRedirect: ()=>handleRSCRedirect,
|
|
43
|
+
handleRSCRedirect: ()=>external_redirect_js_namespaceObject.handleRSCRedirect,
|
|
44
44
|
prepareRSCRoutes: ()=>prepareRSCRoutes
|
|
45
45
|
});
|
|
46
46
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
@@ -49,6 +49,7 @@ const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
|
49
49
|
const external_react_namespaceObject = require("react");
|
|
50
50
|
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
|
|
51
51
|
const external_CSSLinks_js_namespaceObject = require("./CSSLinks.js");
|
|
52
|
+
const external_redirect_js_namespaceObject = require("./redirect.js");
|
|
52
53
|
const safeUse = (value)=>{
|
|
53
54
|
const reactUse = external_react_default().use;
|
|
54
55
|
if ('function' == typeof reactUse) return reactUse(value);
|
|
@@ -131,18 +132,6 @@ const createServerPayload = (routerContext, routes)=>{
|
|
|
131
132
|
})
|
|
132
133
|
};
|
|
133
134
|
};
|
|
134
|
-
const handleRSCRedirect = (headers, basename, status)=>{
|
|
135
|
-
const newHeaders = new Headers(headers);
|
|
136
|
-
let redirectUrl = headers.get('Location');
|
|
137
|
-
if ('/' !== basename) redirectUrl = redirectUrl.replace(basename, '');
|
|
138
|
-
newHeaders.set('X-Modernjs-Redirect', redirectUrl);
|
|
139
|
-
newHeaders.set('X-Modernjs-BaseUrl', basename);
|
|
140
|
-
newHeaders.delete('Location');
|
|
141
|
-
return new Response(null, {
|
|
142
|
-
status: status,
|
|
143
|
-
headers: newHeaders
|
|
144
|
-
});
|
|
145
|
-
};
|
|
146
135
|
const prepareRSCRoutes = async (routes)=>{
|
|
147
136
|
const isLazyComponent = (component)=>null != component && 'object' == typeof component && '_init' in component && '_payload' in component;
|
|
148
137
|
const processRoutes = async (routesList)=>{
|
|
@@ -55,6 +55,7 @@ var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_
|
|
|
55
55
|
const external_DefaultNotFound_js_namespaceObject = require("./DefaultNotFound.js");
|
|
56
56
|
const external_DeferredDataScripts_js_namespaceObject = require("./DeferredDataScripts.js");
|
|
57
57
|
var external_DeferredDataScripts_js_default = /*#__PURE__*/ __webpack_require__.n(external_DeferredDataScripts_js_namespaceObject);
|
|
58
|
+
const external_routerHelper_js_namespaceObject = require("./routerHelper.js");
|
|
58
59
|
function getRouteComponents(routes, { globalApp, ssrMode, props }) {
|
|
59
60
|
const Layout = ({ Component, ...props })=>{
|
|
60
61
|
const GlobalLayout = globalApp;
|
|
@@ -200,7 +201,7 @@ function serializeErrors(errors) {
|
|
|
200
201
|
if (!errors) return null;
|
|
201
202
|
const entries = Object.entries(errors);
|
|
202
203
|
const serialized = {};
|
|
203
|
-
for (const [key, val] of entries)if ((0,
|
|
204
|
+
for (const [key, val] of entries)if ((0, external_routerHelper_js_namespaceObject.isRouteErrorResponse)(val)) serialized[key] = serializeRouteErrorResponse(val);
|
|
204
205
|
else if (val instanceof Error) serialized[key] = serializeError(val);
|
|
205
206
|
else serialized[key] = val;
|
|
206
207
|
return serialized;
|
|
@@ -221,7 +222,7 @@ function serializeError(error) {
|
|
|
221
222
|
};
|
|
222
223
|
}
|
|
223
224
|
function serializeRouteErrorResponse(error) {
|
|
224
|
-
if (!(0,
|
|
225
|
+
if (!(0, external_routerHelper_js_namespaceObject.isRouteErrorResponse)(error)) return error;
|
|
225
226
|
if (error.status >= 500 && shouldRedactServerError()) return {
|
|
226
227
|
status: error.status,
|
|
227
228
|
statusText: 'Internal Server Error',
|
package/dist/esm/cli/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { cleanRequireCache
|
|
1
|
+
import { cleanRequireCache } from "@modern-js/utils";
|
|
2
2
|
import path_0 from "path";
|
|
3
3
|
import { documentPlugin } from "../document/cli/index.mjs";
|
|
4
4
|
import { getEntrypointRoutesDir, getEntrypointRoutesOwner, handleFileChange, handleGeneratorEntryCode, handleModifyEntrypoints, isRouteEntry, routerPlugin, updateNestedRoutesSpec } from "../router/cli/index.mjs";
|
|
@@ -54,12 +54,10 @@ const runtimePlugin = (params)=>({
|
|
|
54
54
|
});
|
|
55
55
|
api.config(()=>{
|
|
56
56
|
const { appDirectory, metaName } = api.getAppContext();
|
|
57
|
-
const isReact18 = utils_isReact18(appDirectory);
|
|
58
|
-
process.env.IS_REACT18 = isReact18.toString();
|
|
59
57
|
return {
|
|
60
58
|
source: {
|
|
61
59
|
globalVars: {
|
|
62
|
-
'process.env.IS_REACT18':
|
|
60
|
+
'process.env.IS_REACT18': 'true'
|
|
63
61
|
},
|
|
64
62
|
include: [
|
|
65
63
|
new RegExp(`[\\\\/]node_modules[\\\\/]@${metaName}[\\\\/]runtime[\\\\/].*[\\\\/]head\\.`)
|
|
@@ -68,14 +66,6 @@ const runtimePlugin = (params)=>({
|
|
|
68
66
|
tools: {
|
|
69
67
|
bundlerChain: (chain)=>{
|
|
70
68
|
chain.module.rule('modern-entry').test(/\.jsx?$/).include.add(path_0.resolve(appDirectory, 'node_modules', `.${metaName}`)).end().sideEffects(true);
|
|
71
|
-
},
|
|
72
|
-
rspack: (_config, { appendPlugins, rspack })=>{
|
|
73
|
-
if (!isReact18) appendPlugins([
|
|
74
|
-
new rspack.IgnorePlugin({
|
|
75
|
-
resourceRegExp: /^react-dom\/client$/,
|
|
76
|
-
contextRegExp: /@modern-js\/runtime/
|
|
77
|
-
})
|
|
78
|
-
]);
|
|
79
69
|
}
|
|
80
70
|
}
|
|
81
71
|
};
|
|
@@ -106,6 +106,7 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
106
106
|
'process.env.MODERN_SSR_ENV': JSON.stringify(ssrEnv),
|
|
107
107
|
'process.env.MODERN_ENABLE_HYDRATION': JSON.stringify(isUseSSRBundle(userConfig)),
|
|
108
108
|
'process.env.MODERN_ENABLE_RSC': JSON.stringify(Boolean(userConfig.server?.rsc)),
|
|
109
|
+
__MODERN_ENABLE_RSC__: JSON.stringify(Boolean(userConfig.server?.rsc)),
|
|
109
110
|
'process.env.MODERN_MF_APP_SSR': JSON.stringify(isModuleFederationAppSSR)
|
|
110
111
|
}
|
|
111
112
|
},
|
|
@@ -5,15 +5,23 @@ import { hydrateRoot } from "react-dom/client";
|
|
|
5
5
|
import { RenderLevel } from "../constants.mjs";
|
|
6
6
|
import { wrapRuntimeContextProvider } from "../react/wrapper.mjs";
|
|
7
7
|
import { WithCallback } from "./withCallback.mjs";
|
|
8
|
-
const isReact18 = ()=>'true' === process.env.IS_REACT18;
|
|
9
8
|
const runtimeProcess = Reflect.get(globalThis, 'process');
|
|
9
|
+
const runtimeEnvironment = null !== runtimeProcess && 'object' == typeof runtimeProcess ? Reflect.get(runtimeProcess, 'env') : void 0;
|
|
10
|
+
const readRuntimeEnvironment = (name)=>{
|
|
11
|
+
if (null === runtimeEnvironment || 'object' != typeof runtimeEnvironment) return;
|
|
12
|
+
const value = Reflect.get(runtimeEnvironment, name);
|
|
13
|
+
return 'string' == typeof value ? value : void 0;
|
|
14
|
+
};
|
|
10
15
|
const loadableReadyOptions = {
|
|
11
|
-
chunkLoadingGlobal:
|
|
16
|
+
chunkLoadingGlobal: (()=>{
|
|
17
|
+
const configured = readRuntimeEnvironment('MODERN_CHUNK_LOADING_GLOBAL');
|
|
18
|
+
return void 0 === configured || '' === configured ? '__LOADABLE_LOADED_CHUNKS__' : configured;
|
|
19
|
+
})()
|
|
12
20
|
};
|
|
13
|
-
|
|
14
|
-
return hydrateRoot(rootElement, App, {
|
|
21
|
+
function hydrateWithReact(App, rootElement) {
|
|
22
|
+
return Promise.resolve(hydrateRoot(rootElement, App, {
|
|
15
23
|
identifierPrefix: SSR_HYDRATION_ID_PREFIX
|
|
16
|
-
});
|
|
24
|
+
}));
|
|
17
25
|
}
|
|
18
26
|
function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
19
27
|
const hydrateContext = {
|
|
@@ -26,9 +34,9 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
26
34
|
const callback = ()=>{
|
|
27
35
|
delete hydrateContext._hydration;
|
|
28
36
|
};
|
|
29
|
-
const renderLevel = window?._SSR_DATA?.renderLevel
|
|
30
|
-
const renderMode = window?._SSR_DATA?.mode
|
|
31
|
-
if (
|
|
37
|
+
const renderLevel = window?._SSR_DATA?.renderLevel ?? RenderLevel.CLIENT_RENDER;
|
|
38
|
+
const renderMode = window?._SSR_DATA?.mode ?? 'string';
|
|
39
|
+
if ('stream' === renderMode) return streamSSRHydrate();
|
|
32
40
|
function streamSSRHydrate() {
|
|
33
41
|
if (renderLevel !== RenderLevel.SERVER_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
34
42
|
{
|
|
@@ -42,23 +50,23 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
42
50
|
return stringSSRHydrate();
|
|
43
51
|
function stringSSRHydrate() {
|
|
44
52
|
if (renderLevel === RenderLevel.CLIENT_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
{
|
|
54
|
+
if (renderLevel === RenderLevel.SERVER_RENDER) return loadableReady(()=>void 0, loadableReadyOptions).then(()=>{
|
|
47
55
|
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
48
56
|
callback: callback,
|
|
49
57
|
children: App
|
|
50
58
|
});
|
|
51
|
-
ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext))
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
return ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext));
|
|
60
|
+
});
|
|
61
|
+
const runtimeConsole = Reflect.get(globalThis, 'console');
|
|
62
|
+
if (null !== runtimeConsole && 'object' == typeof runtimeConsole) {
|
|
63
|
+
const warn = Reflect.get(runtimeConsole, 'warn');
|
|
64
|
+
if ('function' == typeof warn) Reflect.apply(warn, runtimeConsole, [
|
|
65
|
+
`unknow render level: ${renderLevel}, execute render()`
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
69
|
+
}
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
|
-
export { hydrateWithReact, hydrate_hydrateRoot as hydrateRoot
|
|
72
|
+
export { hydrateWithReact, hydrate_hydrateRoot as hydrateRoot };
|