@bleedingdev/modern-js-runtime 3.5.0-ultramodern.102 → 3.5.0-ultramodern.103
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/ssr/index.js +1 -0
- package/dist/cjs/core/browser/hydrate.js +31 -27
- 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/utils.js +3 -3
- 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 +13 -7
- package/dist/cjs/router/cli/code/templates.js +33 -24
- package/dist/cjs/router/cli/handler.js +2 -0
- package/dist/cjs/router/runtime/plugin.js +11 -6
- 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/ssr/index.mjs +1 -0
- package/dist/esm/core/browser/hydrate.mjs +30 -22
- 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/utils.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 +13 -7
- package/dist/esm/router/cli/code/templates.mjs +33 -24
- package/dist/esm/router/cli/handler.mjs +2 -0
- package/dist/esm/router/runtime/plugin.mjs +13 -8
- 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/ssr/index.mjs +1 -0
- package/dist/esm-node/core/browser/hydrate.mjs +30 -22
- 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/utils.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 +13 -7
- package/dist/esm-node/router/cli/code/templates.mjs +33 -24
- package/dist/esm-node/router/cli/handler.mjs +2 -0
- package/dist/esm-node/router/runtime/plugin.mjs +13 -8
- 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/server/utils.d.ts +1 -1
- 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 +2 -0
- package/dist/types/router/cli/code/templates.d.ts +5 -2
- package/dist/types/router/cli/handler.d.ts +2 -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 +14 -14
- package/rstest.config.mts +2 -0
|
@@ -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, {
|
|
@@ -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',
|
|
@@ -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 };
|
|
@@ -3,39 +3,34 @@ import { HelmetProvider } from "react-helmet-async";
|
|
|
3
3
|
import { InternalRuntimeContext, RuntimeContext, getGlobalEnableRsc } from "../context/index.mjs";
|
|
4
4
|
import { stripRuntimeContextExtensions } from "../context/extensions.mjs";
|
|
5
5
|
import { ensureHelmetContext } from "../context/helmetContext.mjs";
|
|
6
|
-
function
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
function createRscSafeRequestContext(ssrContext) {
|
|
7
|
+
if (void 0 === ssrContext) return {
|
|
8
|
+
request: {},
|
|
9
|
+
response: {
|
|
10
|
+
locals: {}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const { request, response } = ssrContext;
|
|
13
14
|
return {
|
|
14
|
-
|
|
15
|
-
useJsonScript: ssrContext.useJsonScript,
|
|
16
|
-
htmlModifiers: [],
|
|
17
|
-
baseUrl: ssrContext.baseUrl,
|
|
18
|
-
request: request ? {
|
|
15
|
+
request: {
|
|
19
16
|
url: request.url,
|
|
20
17
|
userAgent: request.userAgent,
|
|
21
18
|
cookie: request.cookie,
|
|
22
19
|
pathname: request.pathname,
|
|
23
|
-
query:
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
query: {
|
|
21
|
+
...request.query
|
|
22
|
+
},
|
|
23
|
+
params: {
|
|
24
|
+
...request.params
|
|
25
|
+
},
|
|
26
|
+
headers: {
|
|
27
|
+
...request.headers
|
|
28
|
+
},
|
|
26
29
|
host: request.host,
|
|
27
30
|
referer: request.referer
|
|
28
|
-
}
|
|
29
|
-
mode: ssrContext.mode,
|
|
30
|
-
loaderFailureMode: ssrContext.loaderFailureMode
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function createRscSafeRequestContext(ssrContext) {
|
|
34
|
-
const safeSsrContext = createRscSafeSsrContext(ssrContext);
|
|
35
|
-
return {
|
|
36
|
-
request: safeSsrContext?.request || {},
|
|
31
|
+
},
|
|
37
32
|
response: {
|
|
38
|
-
locals:
|
|
33
|
+
locals: response.locals ?? {}
|
|
39
34
|
}
|
|
40
35
|
};
|
|
41
36
|
}
|
|
@@ -51,14 +46,14 @@ function wrapRuntimeContextProvider(App, contextValue) {
|
|
|
51
46
|
...rest
|
|
52
47
|
};
|
|
53
48
|
stripRuntimeContextExtensions(runtimeContextValue);
|
|
54
|
-
if (getGlobalEnableRsc() &&
|
|
49
|
+
if (true === getGlobalEnableRsc() && false === isBrowser) {
|
|
55
50
|
const rscSafeRequestContext = createRscSafeRequestContext(ssrContext);
|
|
56
51
|
const rscInternalContextValue = {
|
|
57
52
|
...internalContextValue,
|
|
58
53
|
context: rscSafeRequestContext,
|
|
59
|
-
requestContext: rscSafeRequestContext
|
|
60
|
-
ssrContext: createRscSafeSsrContext(ssrContext)
|
|
54
|
+
requestContext: rscSafeRequestContext
|
|
61
55
|
};
|
|
56
|
+
delete rscInternalContextValue.ssrContext;
|
|
62
57
|
const rscRuntimeContextValue = {
|
|
63
58
|
...runtimeContextValue,
|
|
64
59
|
context: rscSafeRequestContext,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getRouterServerSnapshot } from "../../router/runtime/lifecycle.mjs";
|
|
2
|
-
import { handleRSCRedirect } from "../../router/runtime/
|
|
2
|
+
import { handleRSCRedirect } from "../../router/runtime/redirect.mjs";
|
|
3
3
|
import { SSRErrors } from "./tracer.mjs";
|
|
4
4
|
const isRedirectStatus = (status)=>status >= 300 && status <= 399;
|
|
5
5
|
const isNullBodyStatus = (status)=>204 === status || 205 === status || 304 === status;
|
|
@@ -13,12 +13,12 @@ const processRedirect = (headers, status, ctx)=>{
|
|
|
13
13
|
const applyRouterSnapshotResult = (context, onError)=>{
|
|
14
14
|
const routerServerSnapshot = getRouterServerSnapshot(context);
|
|
15
15
|
const routerStatusCode = routerServerSnapshot?.statusCode ?? context.routerContext?.statusCode;
|
|
16
|
-
if (routerStatusCode && 200 !== routerStatusCode) context.ssrContext?.response.status(routerStatusCode);
|
|
16
|
+
if (void 0 !== routerStatusCode && 0 !== routerStatusCode && !Number.isNaN(routerStatusCode) && 200 !== routerStatusCode) context.ssrContext?.response.status(routerStatusCode);
|
|
17
17
|
const errors = Object.values(routerServerSnapshot?.errors || context.routerContext?.errors || {});
|
|
18
18
|
if (errors.length > 0) onError(errors[0], SSRErrors.LOADER_ERROR);
|
|
19
19
|
};
|
|
20
20
|
const createLoaderRedirectResponse = (beforeRenderResult, redirectCtx)=>{
|
|
21
|
-
if (
|
|
21
|
+
if (void 0 === beforeRenderResult || !isRedirectStatus(beforeRenderResult.status)) return;
|
|
22
22
|
if (beforeRenderResult.headers.has('X-Modernjs-Redirect')) return beforeRenderResult;
|
|
23
23
|
const redirectUrl = beforeRenderResult.headers.get('Location') || '/';
|
|
24
24
|
return processRedirect(new Headers({
|
|
@@ -26,7 +26,7 @@ const createLoaderRedirectResponse = (beforeRenderResult, redirectCtx)=>{
|
|
|
26
26
|
}), beforeRenderResult.status, redirectCtx);
|
|
27
27
|
};
|
|
28
28
|
const finalizeRenderResponse = (response, responseProxy, redirectCtx, routerCleanup)=>{
|
|
29
|
-
if (-1 !== responseProxy.status && isRedirectStatus(responseProxy.status) && responseProxy.headers.Location) return processRedirect(new Headers(responseProxy.headers), responseProxy.status, redirectCtx);
|
|
29
|
+
if (-1 !== responseProxy.status && isRedirectStatus(responseProxy.status) && void 0 !== responseProxy.headers.Location && '' !== responseProxy.headers.Location) return processRedirect(new Headers(responseProxy.headers), responseProxy.status, redirectCtx);
|
|
30
30
|
Object.entries(responseProxy.headers).forEach(([key, value])=>{
|
|
31
31
|
response.headers.set(key, value);
|
|
32
32
|
});
|
|
@@ -43,7 +43,7 @@ function getMatchedRouteAssets(runtimeContext, routeManifest) {
|
|
|
43
43
|
return matchedRouteIds.flatMap((routeId)=>routeAssets[routeId]?.assets ?? []);
|
|
44
44
|
}
|
|
45
45
|
function getMatchedRouteChunks(runtimeContext, routeManifest, routeAssetToChunk) {
|
|
46
|
-
if (
|
|
46
|
+
if (void 0 === routeManifest) return [];
|
|
47
47
|
return getMatchedRouteAssets(runtimeContext, routeManifest).map(routeAssetToChunk);
|
|
48
48
|
}
|
|
49
49
|
const orderHydrationScriptChunks = ({ asyncEntryChunks, collectedChunks, matchedRouteChunks, entryName })=>{
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { matchRoutes } from "@modern-js/runtime-utils/router";
|
|
2
1
|
import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
3
2
|
import { CHUNK_CSS_PLACEHOLDER } from "../constants.mjs";
|
|
4
3
|
import { createFederatedCssLinks } from "../federatedCss.mjs";
|
|
@@ -27,20 +26,12 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
|
27
26
|
});
|
|
28
27
|
return safeReplace(template, CHUNK_CSS_PLACEHOLDER, css);
|
|
29
28
|
async function getCssChunks() {
|
|
30
|
-
const { routeManifest
|
|
29
|
+
const { routeManifest } = runtimeContext;
|
|
31
30
|
const routeAssets = routeManifest?.routeAssets;
|
|
32
31
|
if (!routeAssets) return '';
|
|
33
32
|
let matchedRouteManifests = [];
|
|
34
33
|
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
|
|
35
34
|
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
36
|
-
else if (routerContext && routes) {
|
|
37
|
-
const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
|
|
38
|
-
matchedRouteManifests = matches?.map((match, index)=>{
|
|
39
|
-
if (!index) return;
|
|
40
|
-
const routeId = match.route.id;
|
|
41
|
-
if (routeId) return routeAssets[routeId];
|
|
42
|
-
}).filter((routeManifest)=>void 0 !== routeManifest) ?? [];
|
|
43
|
-
}
|
|
44
35
|
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
45
36
|
if (asyncEntry) matchedRouteManifests.push(asyncEntry);
|
|
46
37
|
const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRouteErrorResponse } from "
|
|
1
|
+
import { isRouteErrorResponse } from "../../router/runtime/routerHelper.mjs";
|
|
2
2
|
function attributesToString(attributes) {
|
|
3
3
|
return Object.entries(attributes).reduce((str, [key, value])=>void 0 === value ? str : `${str} ${key}="${value}"`, '');
|
|
4
4
|
}
|
|
@@ -7,24 +7,24 @@ function distributedSsrFragmentKey(remote, expose) {
|
|
|
7
7
|
}
|
|
8
8
|
function getDistributedSsrFragmentContext(response) {
|
|
9
9
|
const locals = response?.locals;
|
|
10
|
-
if (
|
|
11
|
-
const context = locals[DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY];
|
|
12
|
-
if (
|
|
10
|
+
if ('object' != typeof locals || null === locals) return;
|
|
11
|
+
const context = DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY in locals ? locals[DISTRIBUTED_SSR_FRAGMENTS_LOCALS_KEY] : void 0;
|
|
12
|
+
if ('object' != typeof context || null === context) return;
|
|
13
13
|
return context;
|
|
14
14
|
}
|
|
15
15
|
function useDistributedSsrFragmentProps({ boundaryId, expose }) {
|
|
16
16
|
const runtimeContext = useRuntimeContext();
|
|
17
17
|
const locals = runtimeContext.requestContext?.response?.locals;
|
|
18
|
-
const request =
|
|
19
|
-
if (
|
|
20
|
-
const props = request.props;
|
|
21
|
-
if (
|
|
18
|
+
const request = 'object' == typeof locals && null !== locals && DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY in locals ? locals[DISTRIBUTED_SSR_FRAGMENT_REQUEST_LOCALS_KEY] : void 0;
|
|
19
|
+
if ('object' != typeof request || null === request || !('boundaryId' in request) || request.boundaryId !== boundaryId || !('expose' in request) || request.expose !== expose) throw new Error(`Distributed SSR fragment request contract mismatch for ${boundaryId} ${expose}.`);
|
|
20
|
+
const props = 'props' in request ? request.props : void 0;
|
|
21
|
+
if ('object' != typeof props || null === props || Array.isArray(props)) throw new Error(`Distributed SSR fragment request props must be an object for ${boundaryId} ${expose}.`);
|
|
22
22
|
return props;
|
|
23
23
|
}
|
|
24
24
|
function isThenable(value) {
|
|
25
|
-
return 'function' == typeof value.then;
|
|
25
|
+
return void 0 !== value && 'then' in value && 'function' == typeof value.then;
|
|
26
26
|
}
|
|
27
|
-
function DistributedSsrBoundary({ children, expose, fallback, fragmentProps
|
|
27
|
+
function DistributedSsrBoundary({ children, expose, fallback, fragmentProps, remote }) {
|
|
28
28
|
const runtimeContext = useRuntimeContext();
|
|
29
29
|
const key = distributedSsrFragmentKey(remote, expose);
|
|
30
30
|
const attributes = {
|
|
@@ -35,12 +35,13 @@ function DistributedSsrBoundary({ children, expose, fallback, fragmentProps = {}
|
|
|
35
35
|
children: children
|
|
36
36
|
});
|
|
37
37
|
const fragmentContext = getDistributedSsrFragmentContext(runtimeContext.requestContext?.response);
|
|
38
|
-
if (
|
|
38
|
+
if (void 0 === fragmentContext) return /*#__PURE__*/ jsx("div", {
|
|
39
39
|
...attributes,
|
|
40
40
|
children: children
|
|
41
41
|
});
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const resolverFragmentProps = void 0 === fragmentProps ? {} : Object.fromEntries(Object.entries(fragmentProps));
|
|
43
|
+
const fragmentOrPromise = fragmentContext.resolve?.(remote, expose, resolverFragmentProps) ?? fragmentContext.fragments?.[key];
|
|
44
|
+
if (isThenable(fragmentOrPromise)) throw fragmentOrPromise;
|
|
44
45
|
const fragment = fragmentOrPromise;
|
|
45
46
|
if (fragment?.status === 'ready') return /*#__PURE__*/ jsx("div", {
|
|
46
47
|
...attributes,
|
|
@@ -33,7 +33,7 @@ function staleRecordResult(ref, env, ageMs, maxStaleMs) {
|
|
|
33
33
|
}
|
|
34
34
|
function createLastKnownGoodProvider(options) {
|
|
35
35
|
const storage = options.storage ?? createInMemoryLkgStorage();
|
|
36
|
-
const now = options.now ?? (()=>
|
|
36
|
+
const now = options.now ?? (()=>Math.floor(performance.timeOrigin + performance.now()));
|
|
37
37
|
const maxStaleMs = options.freshness?.maxStaleMs;
|
|
38
38
|
async function serveFromCache(ref, env, fallback) {
|
|
39
39
|
const key = deliveryUnitResolutionKey(ref.unitId, env);
|