@bleedingdev/modern-js-runtime 3.9.0-ultramodern.2 → 3.9.0-ultramodern.20
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 +3 -1
- package/dist/cjs/cli/ssr/index.js +2 -74
- 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 +9 -10
- package/dist/cjs/core/browser/index.js +4 -5
- package/dist/cjs/core/context/index.js +12 -45
- package/dist/cjs/core/context/public.js +4 -7
- package/dist/cjs/core/context/runtime.js +10 -4
- 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 +23 -67
- package/dist/cjs/core/server/helmet.js +5 -4
- package/dist/cjs/core/server/requestHandler.js +6 -7
- package/dist/cjs/core/server/requestResponse.js +4 -4
- package/dist/cjs/core/server/routerCleanup.js +2 -2
- package/dist/cjs/core/server/shared.js +171 -4
- package/dist/cjs/core/server/stream/afterTemplate.js +21 -16
- package/dist/cjs/core/server/stream/beforeTemplate.js +37 -28
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +30 -23
- package/dist/cjs/core/server/stream/createReadableStream.js +222 -125
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +171 -90
- package/dist/cjs/core/server/stream/deferredScript.js +3 -3
- package/dist/cjs/core/server/stream/shared.js +6 -2
- package/dist/cjs/core/server/string/index.js +104 -66
- package/dist/cjs/core/server/string/loadable.js +38 -23
- package/dist/cjs/core/server/string/ssrData.js +5 -12
- package/dist/cjs/core/server/utils.js +1 -2
- package/dist/cjs/exports/head.js +7 -14
- 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 +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/PrefetchLink.js +69 -125
- package/dist/cjs/router/runtime/hooks.js +13 -2
- package/dist/cjs/router/runtime/internal.js +7 -45
- package/dist/cjs/router/runtime/plugin.js +19 -34
- package/dist/cjs/router/runtime/plugin.node.js +9 -37
- package/dist/cjs/router/runtime/redirect.js +1 -1
- package/dist/esm/cli/code.mjs +3 -1
- package/dist/esm/cli/ssr/index.mjs +3 -72
- 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 +10 -11
- package/dist/esm/core/browser/index.mjs +1 -2
- package/dist/esm/core/context/index.mjs +2 -5
- package/dist/esm/core/context/public.mjs +1 -5
- package/dist/esm/core/context/runtime.mjs +6 -3
- 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 +20 -67
- package/dist/esm/core/server/helmet.mjs +5 -4
- package/dist/esm/core/server/requestHandler.mjs +1 -2
- package/dist/esm/core/server/requestResponse.mjs +3 -3
- package/dist/esm/core/server/routerCleanup.mjs +1 -1
- package/dist/esm/core/server/shared.mjs +153 -1
- package/dist/esm/core/server/stream/afterTemplate.mjs +23 -18
- package/dist/esm/core/server/stream/beforeTemplate.mjs +40 -31
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +33 -26
- package/dist/esm/core/server/stream/createReadableStream.mjs +220 -123
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +161 -90
- package/dist/esm/core/server/stream/deferredScript.mjs +3 -3
- package/dist/esm/core/server/stream/shared.mjs +4 -3
- package/dist/esm/core/server/string/index.mjs +106 -68
- package/dist/esm/core/server/string/loadable.mjs +38 -23
- package/dist/esm/core/server/string/ssrData.mjs +5 -12
- package/dist/esm/core/server/utils.mjs +1 -2
- package/dist/esm/exports/head.mjs +7 -14
- 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 +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/PrefetchLink.mjs +68 -124
- package/dist/esm/router/runtime/hooks.mjs +9 -1
- package/dist/esm/router/runtime/internal.mjs +2 -33
- package/dist/esm/router/runtime/plugin.mjs +10 -25
- package/dist/esm/router/runtime/plugin.node.mjs +3 -31
- package/dist/esm/router/runtime/redirect.mjs +1 -1
- package/dist/esm-node/cli/code.mjs +3 -1
- package/dist/esm-node/cli/ssr/index.mjs +3 -72
- 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 +10 -11
- package/dist/esm-node/core/browser/index.mjs +1 -2
- package/dist/esm-node/core/context/index.mjs +2 -5
- package/dist/esm-node/core/context/public.mjs +1 -5
- package/dist/esm-node/core/context/runtime.mjs +6 -3
- 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 +20 -67
- package/dist/esm-node/core/server/helmet.mjs +5 -4
- package/dist/esm-node/core/server/requestHandler.mjs +1 -2
- package/dist/esm-node/core/server/requestResponse.mjs +3 -3
- package/dist/esm-node/core/server/routerCleanup.mjs +1 -1
- package/dist/esm-node/core/server/shared.mjs +153 -1
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +23 -18
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +40 -31
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +33 -26
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +220 -123
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +161 -90
- package/dist/esm-node/core/server/stream/deferredScript.mjs +3 -3
- package/dist/esm-node/core/server/stream/shared.mjs +4 -3
- package/dist/esm-node/core/server/string/index.mjs +106 -68
- package/dist/esm-node/core/server/string/loadable.mjs +38 -23
- package/dist/esm-node/core/server/string/ssrData.mjs +5 -12
- package/dist/esm-node/core/server/utils.mjs +1 -2
- package/dist/esm-node/exports/head.mjs +7 -14
- 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 +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/PrefetchLink.mjs +68 -124
- package/dist/esm-node/router/runtime/hooks.mjs +9 -1
- package/dist/esm-node/router/runtime/internal.mjs +2 -33
- package/dist/esm-node/router/runtime/plugin.mjs +10 -25
- package/dist/esm-node/router/runtime/plugin.node.mjs +3 -31
- package/dist/esm-node/router/runtime/redirect.mjs +1 -1
- package/dist/types/cli/ssr/index.d.ts +0 -3
- package/dist/types/core/context/index.d.ts +4 -6
- package/dist/types/core/context/public.d.ts +1 -23
- package/dist/types/core/context/runtime.d.ts +26 -2
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/react/wrapper.d.ts +7 -1
- package/dist/types/core/server/helmet.d.ts +4 -5
- package/dist/types/core/server/requestHandler.d.ts +3 -3
- package/dist/types/core/server/requestResponse.d.ts +1 -1
- package/dist/types/core/server/routerCleanup.d.ts +1 -1
- package/dist/types/core/server/shared.d.ts +24 -1
- package/dist/types/core/server/stream/afterTemplate.d.ts +2 -1
- package/dist/types/core/server/stream/beforeTemplate.d.ts +4 -1
- package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +4 -1
- package/dist/types/core/server/stream/shared.d.ts +16 -2
- package/dist/types/core/server/string/loadable.d.ts +6 -3
- package/dist/types/core/server/string/ssrData.d.ts +2 -1
- package/dist/types/core/server/string/types.d.ts +1 -5
- 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/exports/head.d.ts +2 -2
- package/dist/types/internal.d.ts +1 -1
- package/dist/types/router/runtime/PrefetchLink.d.ts +27 -2
- package/dist/types/router/runtime/hooks.d.ts +19 -2
- package/dist/types/router/runtime/internal.d.ts +4 -21
- package/dist/types/router/runtime/types.d.ts +2 -43
- package/package.json +18 -46
- package/rslib.config.mts +3 -0
- package/rstest.config.mts +28 -2
- package/dist/cjs/boundary-debugger/index.js +0 -317
- package/dist/cjs/core/context/extensions.js +0 -74
- package/dist/cjs/core/context/helmetContext.js +0 -54
- package/dist/cjs/core/server/federatedCss.js +0 -58
- package/dist/cjs/core/server/scriptOrder.js +0 -140
- package/dist/cjs/module-federation/consume-surface.js +0 -199
- package/dist/cjs/module-federation/distributed-ssr.js +0 -135
- package/dist/cjs/module-federation/index.js +0 -316
- package/dist/cjs/module-federation/last-known-good.js +0 -157
- package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +0 -129
- package/dist/cjs/module-federation/surface-resolution-types.js +0 -61
- package/dist/cjs/router/runtime/lifecycle.js +0 -167
- package/dist/cjs/router/runtime/provider.js +0 -153
- package/dist/cjs/rsc/server.worker.js +0 -62
- package/dist/esm/boundary-debugger/index.mjs +0 -277
- package/dist/esm/core/context/extensions.mjs +0 -33
- package/dist/esm/core/context/helmetContext.mjs +0 -13
- package/dist/esm/core/server/federatedCss.mjs +0 -20
- package/dist/esm/core/server/scriptOrder.mjs +0 -90
- package/dist/esm/module-federation/consume-surface.mjs +0 -158
- package/dist/esm/module-federation/distributed-ssr.mjs +0 -82
- package/dist/esm/module-federation/index.mjs +0 -115
- package/dist/esm/module-federation/last-known-good.mjs +0 -113
- package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +0 -89
- package/dist/esm/module-federation/surface-resolution-types.mjs +0 -8
- package/dist/esm/router/runtime/lifecycle.mjs +0 -105
- package/dist/esm/router/runtime/provider.mjs +0 -100
- package/dist/esm/rsc/server.worker.mjs +0 -1
- package/dist/esm-node/boundary-debugger/index.mjs +0 -278
- package/dist/esm-node/core/context/extensions.mjs +0 -34
- package/dist/esm-node/core/context/helmetContext.mjs +0 -14
- package/dist/esm-node/core/server/federatedCss.mjs +0 -21
- package/dist/esm-node/core/server/scriptOrder.mjs +0 -91
- package/dist/esm-node/module-federation/consume-surface.mjs +0 -159
- package/dist/esm-node/module-federation/distributed-ssr.mjs +0 -83
- package/dist/esm-node/module-federation/index.mjs +0 -116
- package/dist/esm-node/module-federation/last-known-good.mjs +0 -114
- package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +0 -90
- package/dist/esm-node/module-federation/surface-resolution-types.mjs +0 -9
- package/dist/esm-node/router/runtime/lifecycle.mjs +0 -106
- package/dist/esm-node/router/runtime/provider.mjs +0 -101
- package/dist/esm-node/rsc/server.worker.mjs +0 -2
- package/dist/types/boundary-debugger/index.d.ts +0 -28
- package/dist/types/core/context/extensions.d.ts +0 -35
- package/dist/types/core/context/helmetContext.d.ts +0 -10
- package/dist/types/core/server/federatedCss.d.ts +0 -5
- package/dist/types/core/server/scriptOrder.d.ts +0 -25
- package/dist/types/module-federation/consume-surface.d.ts +0 -104
- package/dist/types/module-federation/distributed-ssr.d.ts +0 -61
- package/dist/types/module-federation/index.d.ts +0 -71
- package/dist/types/module-federation/last-known-good.d.ts +0 -52
- package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +0 -25
- package/dist/types/module-federation/surface-resolution-types.d.ts +0 -23
- package/dist/types/router/runtime/lifecycle.d.ts +0 -27
- package/dist/types/router/runtime/provider.d.ts +0 -78
- package/dist/types/rsc/server.worker.d.ts +0 -1
|
@@ -28,64 +28,26 @@ var __webpack_require__ = {};
|
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
|
|
32
|
-
createRouterProviderRealm: ()=>external_provider_js_namespaceObject.createRouterProviderRealm,
|
|
33
|
-
default: ()=>internal,
|
|
31
|
+
default: ()=>external_plugin_js_namespaceObject.routerPlugin,
|
|
34
32
|
modifyRoutes: ()=>external_plugin_js_namespaceObject.modifyRoutes,
|
|
35
|
-
registerRouterProvider: ()=>external_provider_js_namespaceObject.registerRouterProvider,
|
|
36
33
|
renderRoutes: ()=>external_utils_js_namespaceObject.renderRoutes,
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
routerPlugin: ()=>external_plugin_js_namespaceObject.routerPlugin,
|
|
35
|
+
routerProviderRegistryHooks: ()=>external_hooks_js_namespaceObject.routerProviderRegistryHooks
|
|
39
36
|
});
|
|
40
|
-
const
|
|
37
|
+
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
41
38
|
const external_plugin_js_namespaceObject = require("./plugin.js");
|
|
42
|
-
const external_provider_js_namespaceObject = require("./provider.js");
|
|
43
39
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
44
|
-
(0, external_provider_js_namespaceObject.registerRouterProvider)('react-router', external_plugin_js_namespaceObject.routerPlugin, {
|
|
45
|
-
isDefault: true
|
|
46
|
-
});
|
|
47
|
-
const createRouterPlugin = (localProviders = [])=>{
|
|
48
|
-
const providerRealm = (0, external_provider_js_namespaceObject.createRouterProviderRealm)([
|
|
49
|
-
{
|
|
50
|
-
name: 'react-router',
|
|
51
|
-
factory: external_plugin_js_namespaceObject.routerPlugin,
|
|
52
|
-
isDefault: true
|
|
53
|
-
},
|
|
54
|
-
...localProviders
|
|
55
|
-
]);
|
|
56
|
-
return (userConfig = {})=>({
|
|
57
|
-
name: '@modern-js/plugin-router',
|
|
58
|
-
registryHooks: external_provider_js_namespaceObject.routerProviderRegistryHooks,
|
|
59
|
-
setup: (api)=>{
|
|
60
|
-
const mergedConfig = (0, merge_namespaceObject.merge)(api.getRuntimeConfig().router || {}, userConfig);
|
|
61
|
-
const pluginFactory = (0, external_provider_js_namespaceObject.resolveRouterProvider)(mergedConfig.framework, {
|
|
62
|
-
realm: providerRealm
|
|
63
|
-
});
|
|
64
|
-
const providerPlugin = pluginFactory(userConfig);
|
|
65
|
-
(0, external_provider_js_namespaceObject.reportUnsupportedProviderRegistryHooks)(providerPlugin);
|
|
66
|
-
providerPlugin.setup?.(api);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
const routerPlugin = createRouterPlugin();
|
|
71
|
-
const internal = routerPlugin;
|
|
72
|
-
exports.createRouterPlugin = __webpack_exports__.createRouterPlugin;
|
|
73
|
-
exports.createRouterProviderRealm = __webpack_exports__.createRouterProviderRealm;
|
|
74
40
|
exports["default"] = __webpack_exports__["default"];
|
|
75
41
|
exports.modifyRoutes = __webpack_exports__.modifyRoutes;
|
|
76
|
-
exports.registerRouterProvider = __webpack_exports__.registerRouterProvider;
|
|
77
42
|
exports.renderRoutes = __webpack_exports__.renderRoutes;
|
|
78
|
-
exports.resolveRouterProvider = __webpack_exports__.resolveRouterProvider;
|
|
79
43
|
exports.routerPlugin = __webpack_exports__.routerPlugin;
|
|
44
|
+
exports.routerProviderRegistryHooks = __webpack_exports__.routerProviderRegistryHooks;
|
|
80
45
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
81
|
-
"createRouterPlugin",
|
|
82
|
-
"createRouterProviderRealm",
|
|
83
46
|
"default",
|
|
84
47
|
"modifyRoutes",
|
|
85
|
-
"registerRouterProvider",
|
|
86
48
|
"renderRoutes",
|
|
87
|
-
"
|
|
88
|
-
"
|
|
49
|
+
"routerPlugin",
|
|
50
|
+
"routerProviderRegistryHooks"
|
|
89
51
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
90
52
|
Object.defineProperty(exports, '__esModule', {
|
|
91
53
|
value: true
|
|
@@ -34,14 +34,13 @@ __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
|
|
42
|
-
const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
|
|
42
|
+
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
43
43
|
const external_PrefetchLink_js_namespaceObject = require("./PrefetchLink.js");
|
|
44
|
-
const external_provider_js_namespaceObject = require("./provider.js");
|
|
45
44
|
const external_rsc_router_js_namespaceObject = require("./rsc-router.js");
|
|
46
45
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
47
46
|
let finalRouteConfig = {
|
|
@@ -57,7 +56,7 @@ function modifyRoutes(modifyFunction) {
|
|
|
57
56
|
}
|
|
58
57
|
const routerPlugin = (userConfig = {})=>({
|
|
59
58
|
name: '@modern-js/plugin-router',
|
|
60
|
-
registryHooks:
|
|
59
|
+
registryHooks: external_hooks_js_namespaceObject.routerProviderRegistryHooks,
|
|
61
60
|
setup: (api)=>{
|
|
62
61
|
const routesContainer = {
|
|
63
62
|
current: []
|
|
@@ -93,8 +92,8 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
93
92
|
const mergedConfig = (0, merge_namespaceObject.merge)(api.getRuntimeConfig().router || {}, userConfig);
|
|
94
93
|
const { serverBase = [], supportHtml5History = true, basename = '', routesConfig, createRoutes } = mergedConfig;
|
|
95
94
|
finalRouteConfig = {
|
|
96
|
-
routes: (0,
|
|
97
|
-
globalApp: (0,
|
|
95
|
+
routes: (0, context_namespaceObject.getGlobalRoutes)(),
|
|
96
|
+
globalApp: (0, context_namespaceObject.getGlobalLayoutApp)(),
|
|
98
97
|
...routesConfig
|
|
99
98
|
};
|
|
100
99
|
if (!finalRouteConfig.routes && !createRoutes) return App;
|
|
@@ -102,9 +101,8 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
102
101
|
const match = serverBase.find((baseUrl)=>isSegmentPrefix(pathname, baseUrl));
|
|
103
102
|
return match || '/';
|
|
104
103
|
};
|
|
105
|
-
let cachedRouter = null;
|
|
106
104
|
const RouterWrapper = (props)=>{
|
|
107
|
-
const routerResult = useRouterCreation(("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0,
|
|
105
|
+
const routerResult = useRouterCreation(("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0, context_namespaceObject.getGlobalEnableRsc)()) ? {
|
|
108
106
|
...props,
|
|
109
107
|
rscPayload: props?.rscPayload
|
|
110
108
|
} : props, {
|
|
@@ -114,12 +112,7 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
114
112
|
selectBasePath,
|
|
115
113
|
basename
|
|
116
114
|
});
|
|
117
|
-
const router =
|
|
118
|
-
if (cachedRouter) return cachedRouter;
|
|
119
|
-
cachedRouter = routerResult.router;
|
|
120
|
-
return cachedRouter;
|
|
121
|
-
}, []);
|
|
122
|
-
const { routes } = routerResult;
|
|
115
|
+
const { router, routes } = routerResult;
|
|
123
116
|
routesContainer.current = routes;
|
|
124
117
|
beforeCreateRouter = false;
|
|
125
118
|
const routerContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
@@ -157,19 +150,20 @@ function isSegmentPrefix(pathname, base) {
|
|
|
157
150
|
}
|
|
158
151
|
function useRouterCreation(props, options) {
|
|
159
152
|
const { api, createRoutes, supportHtml5History, selectBasePath, basename } = options;
|
|
160
|
-
const runtimeContext = (0, external_react_namespaceObject.useContext)(
|
|
153
|
+
const runtimeContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
161
154
|
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
162
155
|
const _basename = '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
163
156
|
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
164
|
-
const rscPayload = ("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0,
|
|
165
|
-
let hydrationData = "u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ ? window._ROUTER_DATA || rscPayload : window._ROUTER_DATA : true === (0,
|
|
166
|
-
|
|
157
|
+
const rscPayload = ("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0, context_namespaceObject.getGlobalEnableRsc)()) && props?.rscPayload ? safeUse(props.rscPayload) : null;
|
|
158
|
+
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;
|
|
159
|
+
const result = (0, external_react_namespaceObject.useRef)(null);
|
|
160
|
+
if (null === result.current) {
|
|
167
161
|
if (hydrationData?.errors) hydrationData = {
|
|
168
162
|
...hydrationData,
|
|
169
163
|
errors: (0, external_utils_js_namespaceObject.deserializeErrors)(hydrationData.errors)
|
|
170
164
|
};
|
|
171
165
|
let routes = null;
|
|
172
|
-
routes = ("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0,
|
|
166
|
+
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)({
|
|
173
167
|
routesConfig: finalRouteConfig
|
|
174
168
|
}) : createRoutes ? createRoutes() : (0, router_namespaceObject.createRoutesFromElements)((0, external_utils_js_namespaceObject.renderRoutes)({
|
|
175
169
|
routesConfig: finalRouteConfig,
|
|
@@ -177,12 +171,13 @@ function useRouterCreation(props, options) {
|
|
|
177
171
|
}));
|
|
178
172
|
if (!routes) routes = [];
|
|
179
173
|
const hooks = api.getHooks();
|
|
180
|
-
if (("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0,
|
|
174
|
+
if (("u" > typeof __MODERN_ENABLE_RSC__ ? __MODERN_ENABLE_RSC__ : true === (0, context_namespaceObject.getGlobalEnableRsc)()) && rscPayload) try {
|
|
181
175
|
const router = (0, external_rsc_router_js_namespaceObject.createClientRouterFromPayload)(rscPayload, routes, _basename);
|
|
182
|
-
|
|
176
|
+
result.current = {
|
|
183
177
|
router,
|
|
184
178
|
routes: router.routes || []
|
|
185
179
|
};
|
|
180
|
+
return result.current;
|
|
186
181
|
} catch (e) {
|
|
187
182
|
console.error('Failed to create router from RSC payload:', e);
|
|
188
183
|
}
|
|
@@ -203,11 +198,6 @@ function useRouterCreation(props, options) {
|
|
|
203
198
|
basename: _basename,
|
|
204
199
|
hydrationData
|
|
205
200
|
});
|
|
206
|
-
(0, external_lifecycle_js_namespaceObject.applyRouterRuntimeState)(runtimeContext, {
|
|
207
|
-
framework: 'react-router',
|
|
208
|
-
basename: _basename,
|
|
209
|
-
instance: router
|
|
210
|
-
});
|
|
211
201
|
hooks.onAfterCreateRouter.call({
|
|
212
202
|
...routerLifecycleContext,
|
|
213
203
|
router,
|
|
@@ -236,17 +226,12 @@ function useRouterCreation(props, options) {
|
|
|
236
226
|
};
|
|
237
227
|
return originSubscribe(wrappedListener);
|
|
238
228
|
};
|
|
239
|
-
|
|
229
|
+
result.current = {
|
|
240
230
|
router,
|
|
241
231
|
routes: modifiedRoutes
|
|
242
232
|
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
props,
|
|
246
|
-
_basename,
|
|
247
|
-
hydrationData,
|
|
248
|
-
getBlockNavState
|
|
249
|
-
]);
|
|
233
|
+
}
|
|
234
|
+
return result.current;
|
|
250
235
|
}
|
|
251
236
|
exports.beforeCreateRouter = __webpack_exports__.beforeCreateRouter;
|
|
252
237
|
exports.finalRouteConfig = __webpack_exports__.finalRouteConfig;
|
|
@@ -41,19 +41,18 @@ __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);
|
|
54
|
-
const
|
|
54
|
+
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
55
55
|
const external_PrefetchLink_js_namespaceObject = require("./PrefetchLink.js");
|
|
56
|
-
const external_provider_js_namespaceObject = require("./provider.js");
|
|
57
56
|
const external_rsc_router_js_namespaceObject = require("./rsc-router.js");
|
|
58
57
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
59
58
|
function createRemixRequest(request) {
|
|
@@ -66,27 +65,9 @@ function createRemixRequest(request) {
|
|
|
66
65
|
signal: controller.signal
|
|
67
66
|
});
|
|
68
67
|
}
|
|
69
|
-
function createReactRouterServerSnapshot(routerContext, basename) {
|
|
70
|
-
return (0, external_lifecycle_js_namespaceObject.createRouterServerSnapshot)({
|
|
71
|
-
framework: 'react-router',
|
|
72
|
-
basename,
|
|
73
|
-
statusCode: routerContext.statusCode,
|
|
74
|
-
errors: routerContext.errors,
|
|
75
|
-
routerData: {
|
|
76
|
-
loaderData: routerContext.loaderData,
|
|
77
|
-
errors: routerContext.errors
|
|
78
|
-
},
|
|
79
|
-
matches: routerContext.matches.map((match)=>{
|
|
80
|
-
const routeId = match.route.id;
|
|
81
|
-
return 'string' == typeof routeId ? {
|
|
82
|
-
routeId
|
|
83
|
-
} : void 0;
|
|
84
|
-
}).filter((match)=>void 0 !== match)
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
68
|
const routerPlugin = (userConfig = {})=>({
|
|
88
69
|
name: '@modern-js/plugin-router',
|
|
89
|
-
registryHooks:
|
|
70
|
+
registryHooks: external_hooks_js_namespaceObject.routerProviderRegistryHooks,
|
|
90
71
|
setup: (api)=>{
|
|
91
72
|
let finalRouteConfig = {};
|
|
92
73
|
api.onBeforeRender(async (context, interrupt)=>{
|
|
@@ -100,12 +81,12 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
100
81
|
const pluginConfig = api.getRuntimeConfig();
|
|
101
82
|
const { basename = '', routesConfig, createRoutes } = (0, merge_namespaceObject.merge)(pluginConfig.router || {}, userConfig);
|
|
102
83
|
finalRouteConfig = {
|
|
103
|
-
routes: (0,
|
|
104
|
-
globalApp: (0,
|
|
84
|
+
routes: (0, context_namespaceObject.getGlobalRoutes)(),
|
|
85
|
+
globalApp: (0, context_namespaceObject.getGlobalLayoutApp)(),
|
|
105
86
|
...routesConfig
|
|
106
87
|
};
|
|
107
88
|
if (!finalRouteConfig.routes && !createRoutes) return;
|
|
108
|
-
const enableRsc = (0,
|
|
89
|
+
const enableRsc = (0, context_namespaceObject.getGlobalEnableRsc)();
|
|
109
90
|
if (enableRsc) await (0, external_rsc_router_js_namespaceObject.prepareRSCRoutes)(finalRouteConfig.routes);
|
|
110
91
|
const { request, mode: ssrMode, nonce, loaderFailureMode = 'errorBoundary', baseUrl } = context.ssrContext;
|
|
111
92
|
const _basename = '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, basename) : baseUrl;
|
|
@@ -150,18 +131,9 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
150
131
|
throw errors[0];
|
|
151
132
|
}
|
|
152
133
|
context.routerContext = routerContext;
|
|
153
|
-
const routerServerSnapshot = createReactRouterServerSnapshot(routerContext, _basename);
|
|
154
|
-
(0, external_lifecycle_js_namespaceObject.applyRouterRuntimeState)(context, {
|
|
155
|
-
framework: 'react-router',
|
|
156
|
-
basename: _basename,
|
|
157
|
-
instance: routerContext,
|
|
158
|
-
matchedRouteIds: routerServerSnapshot.matchedRouteIds,
|
|
159
|
-
serverSnapshot: routerServerSnapshot
|
|
160
|
-
});
|
|
161
134
|
hooks.onAfterCreateRouter.call({
|
|
162
135
|
...routerLifecycleContext,
|
|
163
136
|
router: routerContext,
|
|
164
|
-
serverSnapshot: routerServerSnapshot,
|
|
165
137
|
runtimeContext: context
|
|
166
138
|
});
|
|
167
139
|
let payload;
|
|
@@ -182,9 +154,9 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
182
154
|
api.wrapRoot((App)=>{
|
|
183
155
|
if (!finalRouteConfig) return App;
|
|
184
156
|
const getRouteApp = ()=>{
|
|
185
|
-
const enableRsc = (0,
|
|
157
|
+
const enableRsc = (0, context_namespaceObject.getGlobalEnableRsc)();
|
|
186
158
|
return (props)=>{
|
|
187
|
-
const context = (0, external_react_namespaceObject.useContext)(
|
|
159
|
+
const context = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
188
160
|
const { routerContext, routes } = context;
|
|
189
161
|
const { basename } = routerContext;
|
|
190
162
|
if (enableRsc) return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
@@ -194,7 +166,7 @@ const routerPlugin = (userConfig = {})=>({
|
|
|
194
166
|
}) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_rsc_router_js_namespaceObject.RSCStaticRouter, {
|
|
195
167
|
basename: basename
|
|
196
168
|
});
|
|
197
|
-
{
|
|
169
|
+
else {
|
|
198
170
|
const { nonce, mode, useJsonScript } = context.ssrContext;
|
|
199
171
|
const remixRouter = (0, router_namespaceObject.createStaticRouter)(routes, routerContext);
|
|
200
172
|
const routerWrapper = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
@@ -30,7 +30,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30
30
|
const handleRSCRedirect = (headers, basename, status)=>{
|
|
31
31
|
const newHeaders = new Headers(headers);
|
|
32
32
|
let redirectUrl = headers.get('Location');
|
|
33
|
-
if (
|
|
33
|
+
if (null === redirectUrl || '' === redirectUrl || ![
|
|
34
34
|
301,
|
|
35
35
|
302,
|
|
36
36
|
303,
|
package/dist/esm/cli/code.mjs
CHANGED
|
@@ -73,7 +73,9 @@ const generateCode = async (entrypoints, appContext, config, hooks)=>{
|
|
|
73
73
|
const bootstrapFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`);
|
|
74
74
|
await fs.outputFile(bootstrapFile, `import(/* webpackChunkName: "async-${entryName}" */ './${INDEX_FILE_NAME}');`, 'utf8');
|
|
75
75
|
const bootstrapServerFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_SERVER_BOOTSTRAP_FILE_NAME}`);
|
|
76
|
-
if (ssrMode) await fs.outputFile(bootstrapServerFile, `export const requestHandler = import('./${SERVER_ENTRY_POINT_FILE_NAME}').then((m) => m.requestHandler)
|
|
76
|
+
if (ssrMode) await fs.outputFile(bootstrapServerFile, `export const requestHandler = import('./${SERVER_ENTRY_POINT_FILE_NAME}').then((m) => m.requestHandler);
|
|
77
|
+
// The renderer awaits this promise later; retain its rejection without an early unhandled rejection.
|
|
78
|
+
requestHandler.catch(() => {});`, 'utf8');
|
|
77
79
|
}
|
|
78
80
|
if (ssrMode) {
|
|
79
81
|
const indexServerCode = __rspack_external__template_server_mjs_f98cfe58.serverIndex({
|
|
@@ -2,51 +2,6 @@ import { LOADABLE_STATS_FILE, isUseSSRBundle } from "@modern-js/utils";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import loadable_bundler_plugin from "./loadable-bundler-plugin.mjs";
|
|
4
4
|
import { resolveSSRMode } from "./mode.mjs";
|
|
5
|
-
const getRspackPlugins = (rspackConfig)=>{
|
|
6
|
-
if (!rspackConfig) return [];
|
|
7
|
-
const rspackEntries = Array.isArray(rspackConfig) ? rspackConfig : [
|
|
8
|
-
rspackConfig
|
|
9
|
-
];
|
|
10
|
-
const plugins = [];
|
|
11
|
-
for (const entry of rspackEntries){
|
|
12
|
-
if (!entry || 'function' == typeof entry || 'object' != typeof entry) continue;
|
|
13
|
-
const maybePlugins = entry.plugins;
|
|
14
|
-
if (Array.isArray(maybePlugins)) {
|
|
15
|
-
for (const plugin of maybePlugins)if (plugin) plugins.push(plugin);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return plugins;
|
|
19
|
-
};
|
|
20
|
-
const getRspackPluginName = (plugin)=>{
|
|
21
|
-
if ('string' == typeof plugin) return plugin;
|
|
22
|
-
if ('function' == typeof plugin) return plugin.name;
|
|
23
|
-
if (Array.isArray(plugin)) {
|
|
24
|
-
const [first] = plugin;
|
|
25
|
-
if (!first) return;
|
|
26
|
-
if ('string' == typeof first) return first;
|
|
27
|
-
if ('function' == typeof first) return first.name;
|
|
28
|
-
if ('object' == typeof first) return first.name || first.constructor?.name;
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
return plugin.name || plugin.constructor?.name;
|
|
32
|
-
};
|
|
33
|
-
const hasServerRenderingConfig = (userConfig)=>{
|
|
34
|
-
const { output, server } = userConfig;
|
|
35
|
-
if (output?.ssg) return true;
|
|
36
|
-
if (output?.ssgByEntries && Object.keys(output.ssgByEntries).length > 0) return true;
|
|
37
|
-
if (server?.ssr) return true;
|
|
38
|
-
if (server?.ssrByEntries && Object.keys(server.ssrByEntries).length > 0) return true;
|
|
39
|
-
return false;
|
|
40
|
-
};
|
|
41
|
-
const isModuleFederationAppSSREnabledInConfig = (ssr)=>{
|
|
42
|
-
if (!ssr || 'object' != typeof ssr) return false;
|
|
43
|
-
return true === ssr.moduleFederationAppSSR;
|
|
44
|
-
};
|
|
45
|
-
const isModuleFederationAppSSREnabled = (userConfig)=>{
|
|
46
|
-
if (isModuleFederationAppSSREnabledInConfig(userConfig.server?.ssr)) return true;
|
|
47
|
-
if (userConfig.server?.ssrByEntries && 'object' == typeof userConfig.server.ssrByEntries) return Object.values(userConfig.server.ssrByEntries).some(isModuleFederationAppSSREnabledInConfig);
|
|
48
|
-
return false;
|
|
49
|
-
};
|
|
50
5
|
const checkUseStringSSR = (config, appDirectory, entrypoints)=>{
|
|
51
6
|
if (entrypoints && entrypoints.length > 0) {
|
|
52
7
|
for (const entrypoint of entrypoints){
|
|
@@ -62,41 +17,19 @@ const checkUseStringSSR = (config, appDirectory, entrypoints)=>{
|
|
|
62
17
|
}
|
|
63
18
|
return true;
|
|
64
19
|
};
|
|
65
|
-
const isModuleFederationRspackPlugin = (plugin)=>{
|
|
66
|
-
const candidate = getRspackPluginName(plugin);
|
|
67
|
-
return 'string' == typeof candidate && /modulefederation/i.test(candidate);
|
|
68
|
-
};
|
|
69
|
-
const hasModuleFederationMarker = (config)=>{
|
|
70
|
-
if ('true' === process.env.MF_SSR_PRJ) return true;
|
|
71
|
-
const define = config.source?.define || {};
|
|
72
|
-
if ('REMOTE_IP_STRATEGY' in define || 'FEDERATION_IPV4' in define) return true;
|
|
73
|
-
const plugins = getRspackPlugins(config.tools?.rspack);
|
|
74
|
-
return plugins.some(isModuleFederationRspackPlugin);
|
|
75
|
-
};
|
|
76
20
|
const isNodeEnvironmentTarget = (target)=>'string' == typeof target && ('node' === target || 'async-node' === target || target.startsWith('node'));
|
|
77
|
-
const shouldUseModuleFederationNodeOutput = (config)=>isNodeEnvironmentTarget(config.output?.target) && hasModuleFederationMarker(config);
|
|
78
21
|
const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
79
22
|
name: '@modern-js/builder-plugin-ssr',
|
|
80
23
|
setup (api) {
|
|
81
24
|
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig })=>{
|
|
82
25
|
const isServerEnvironment = isNodeEnvironmentTarget(config.output.target) || 'workerSSR' === name;
|
|
83
26
|
const userConfig = modernAPI.getNormalizedConfig();
|
|
84
|
-
const hasServerRendering = hasServerRenderingConfig(userConfig);
|
|
85
|
-
const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
|
|
86
|
-
const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
|
|
87
|
-
const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
|
|
88
|
-
if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
|
|
89
|
-
const warningMessage = '[modernjs][mf-ssr] Module Federation SSR was auto-detected from runtime markers. Set server.ssr.moduleFederationAppSSR=true explicitly in host and remotes to avoid heuristic drift.';
|
|
90
|
-
if (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
91
|
-
console.warn(warningMessage);
|
|
92
|
-
}
|
|
93
|
-
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
|
|
94
27
|
const ssrEnv = userConfig.deploy?.worker?.ssr || userConfig.server?.rsc ? 'edge' : 'node';
|
|
95
28
|
const appContext = modernAPI.getAppContext();
|
|
96
29
|
const { appDirectory, entrypoints } = appContext;
|
|
97
30
|
const useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
98
31
|
const outputConfig = {
|
|
99
|
-
module: isServerEnvironment &&
|
|
32
|
+
module: isServerEnvironment && outputModule
|
|
100
33
|
};
|
|
101
34
|
const useLoadableComponents = isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
102
35
|
return mergeEnvironmentConfig(config, {
|
|
@@ -106,12 +39,10 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
106
39
|
'process.env.MODERN_SSR_ENV': JSON.stringify(ssrEnv),
|
|
107
40
|
'process.env.MODERN_ENABLE_HYDRATION': JSON.stringify(isUseSSRBundle(userConfig)),
|
|
108
41
|
'process.env.MODERN_ENABLE_RSC': JSON.stringify(Boolean(userConfig.server?.rsc)),
|
|
109
|
-
__MODERN_ENABLE_RSC__: JSON.stringify(Boolean(userConfig.server?.rsc))
|
|
110
|
-
'process.env.MODERN_MF_APP_SSR': JSON.stringify(String(isModuleFederationAppSSR))
|
|
42
|
+
__MODERN_ENABLE_RSC__: JSON.stringify(Boolean(userConfig.server?.rsc))
|
|
111
43
|
}
|
|
112
44
|
},
|
|
113
45
|
output: outputConfig,
|
|
114
|
-
splitChunks: isServerEnvironment && (hasModuleFederationRuntimeMarker || hasExplicitMfSsrFlag) ? false : void 0,
|
|
115
46
|
tools: {
|
|
116
47
|
bundlerChain: useLoadablePlugin ? (chain)=>{
|
|
117
48
|
chain.plugin('loadable').use(loadable_bundler_plugin, [
|
|
@@ -180,4 +111,4 @@ const ssrPlugin = ()=>({
|
|
|
180
111
|
});
|
|
181
112
|
const cli_ssr = ssrPlugin;
|
|
182
113
|
export default cli_ssr;
|
|
183
|
-
export {
|
|
114
|
+
export { ssrPlugin };
|
|
@@ -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',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { loadableReady } from "@loadable/component";
|
|
3
3
|
import { SSR_HYDRATION_ID_PREFIX } from "@modern-js/utils/universal/constants";
|
|
4
4
|
import { hydrateRoot } from "react-dom/client";
|
|
@@ -29,18 +29,23 @@ 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
|
|
36
36
|
});
|
|
37
|
-
return ModernHydrate(
|
|
37
|
+
return ModernHydrate(/*#__PURE__*/ jsxs(Fragment, {
|
|
38
|
+
children: [
|
|
39
|
+
wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext),
|
|
40
|
+
null
|
|
41
|
+
]
|
|
42
|
+
}));
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
45
|
return stringSSRHydrate();
|
|
41
46
|
function stringSSRHydrate() {
|
|
42
47
|
if (renderLevel === RenderLevel.CLIENT_RENDER) return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
43
|
-
{
|
|
48
|
+
else {
|
|
44
49
|
if (renderLevel === RenderLevel.SERVER_RENDER) return loadableReady(()=>void 0, loadableReadyOptions).then(()=>{
|
|
45
50
|
const SSRApp = ()=>/*#__PURE__*/ jsx(WithCallback, {
|
|
46
51
|
callback: callback,
|
|
@@ -48,13 +53,7 @@ function hydrate_hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
48
53
|
});
|
|
49
54
|
return ModernHydrate(wrapRuntimeContextProvider(/*#__PURE__*/ jsx(SSRApp, {}), hydrateContext));
|
|
50
55
|
});
|
|
51
|
-
|
|
52
|
-
if (null !== runtimeConsole && 'object' == typeof runtimeConsole) {
|
|
53
|
-
const warn = Reflect.get(runtimeConsole, 'warn');
|
|
54
|
-
if ('function' == typeof warn) Reflect.apply(warn, runtimeConsole, [
|
|
55
|
-
`unknow render level: ${renderLevel}, execute render()`
|
|
56
|
-
]);
|
|
57
|
-
}
|
|
56
|
+
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
58
57
|
return ModernRender(wrapRuntimeContextProvider(App, context));
|
|
59
58
|
}
|
|
60
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;
|
|
@@ -41,10 +41,7 @@ function getGlobalBasename() {
|
|
|
41
41
|
return globalContext.basename;
|
|
42
42
|
}
|
|
43
43
|
export { DefaultNotFound } from "../../router/runtime/DefaultNotFound.mjs";
|
|
44
|
-
export { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter } from "../../router/runtime/hooks.mjs";
|
|
45
|
-
export {
|
|
46
|
-
export { createRouterProviderRealm, registerRouterProvider, resolveRouterProvider, routerProviderRegistryHooks } from "../../router/runtime/provider.mjs";
|
|
47
|
-
export { createRuntimeContextExtension } from "./extensions.mjs";
|
|
48
|
-
export { InternalRuntimeContext, RuntimeContext, getInitialContext } from "./runtime.mjs";
|
|
44
|
+
export { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter, routerProviderRegistryHooks } from "../../router/runtime/hooks.mjs";
|
|
45
|
+
export { InternalRuntimeContext, ReactRuntimeContext, RuntimeComponentResolverContext, RuntimeContext, getInitialContext, useRuntimeContext } from "./runtime.mjs";
|
|
49
46
|
export { getServerPayload, setServerPayload } from "./serverPayload/index.mjs";
|
|
50
47
|
export { getCurrentEntryName, getGlobalApp, getGlobalBasename, getGlobalEnableRsc, getGlobalInternalRuntimeContext, getGlobalIsRscClient, getGlobalLayoutApp, getGlobalRSCRoot, getGlobalRoutes, setGlobalContext, setGlobalInternalRuntimeContext };
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const RuntimeContext = createContext({});
|
|
3
|
-
const ReactRuntimeContext = RuntimeContext;
|
|
4
|
-
const useRuntimeContext = ()=>useContext(RuntimeContext);
|
|
5
|
-
export { ReactRuntimeContext, RuntimeContext, useRuntimeContext };
|
|
1
|
+
export { ReactRuntimeContext, RuntimeContext, useRuntimeContext } from "@modern-js/runtime/context";
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { createContext } from "react";
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
2
|
const ROUTE_MANIFEST = '_MODERNJS_ROUTE_MANIFEST';
|
|
3
3
|
const InternalRuntimeContext = createContext({});
|
|
4
|
+
const RuntimeContext = createContext({});
|
|
5
|
+
const RuntimeComponentResolverContext = createContext(void 0);
|
|
6
|
+
const ReactRuntimeContext = RuntimeContext;
|
|
7
|
+
const useRuntimeContext = ()=>useContext(RuntimeContext);
|
|
4
8
|
const getInitialContext = (isBrowser = true, routeManifest)=>{
|
|
5
9
|
const requestContext = {
|
|
6
10
|
request: {
|
|
@@ -24,5 +28,4 @@ const getInitialContext = (isBrowser = true, routeManifest)=>{
|
|
|
24
28
|
context: requestContext
|
|
25
29
|
};
|
|
26
30
|
};
|
|
27
|
-
export { ReactRuntimeContext, RuntimeContext, useRuntimeContext }
|
|
28
|
-
export { InternalRuntimeContext, getInitialContext };
|
|
31
|
+
export { InternalRuntimeContext, ReactRuntimeContext, RuntimeComponentResolverContext, RuntimeContext, getInitialContext, useRuntimeContext };
|
package/dist/esm/core/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { runtime } from "@modern-js/plugin/runtime";
|
|
2
|
+
import { setGlobalInternalRuntimeContext } from "@modern-js/runtime/context";
|
|
2
3
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
3
4
|
import { compatPlugin } from "../compat/index.mjs";
|
|
4
5
|
import { handleSetupResult } from "../compat/hooks.mjs";
|
|
5
6
|
import { requestContextPlugin } from "../compat/requestContext.mjs";
|
|
6
|
-
import { setGlobalInternalRuntimeContext } from "../context/index.mjs";
|
|
7
7
|
function registerPlugin(internalPlugins, runtimeConfig) {
|
|
8
8
|
const { plugins = [] } = runtimeConfig || {};
|
|
9
9
|
const { runtimeContext } = runtime.run({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { getGlobalApp, getGlobalInternalRuntimeContext } from "@modern-js/runtime/context";
|
|
1
2
|
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
2
3
|
import { isBrowser } from "../../common.mjs";
|
|
3
4
|
import { ROUTER_DATA_JSON_ID, SSR_DATA_JSON_ID } from "../constants.mjs";
|
|
4
|
-
import { getGlobalApp, getGlobalInternalRuntimeContext } from "../context/index.mjs";
|
|
5
5
|
function createRoot(UserApp) {
|
|
6
6
|
const App = UserApp || getGlobalApp();
|
|
7
7
|
if (isBrowser()) {
|