@bleedingdev/modern-js-runtime 3.5.0-ultramodern.10 → 3.5.0-ultramodern.101
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/boundary-debugger/index.js +13 -3
- package/dist/cjs/cli/index.js +1 -11
- package/dist/cjs/cli/registry.js +18 -0
- package/dist/cjs/cli/ssr/index.js +3 -2
- package/dist/cjs/cli/ssr/loadable-bundler-plugin.js +8 -4
- package/dist/cjs/core/browser/hydrate.js +16 -2
- package/dist/cjs/core/browser/index.js +19 -18
- package/dist/cjs/core/context/index.js +3 -0
- package/dist/cjs/core/context/public.js +49 -0
- package/dist/cjs/core/context/runtime.js +6 -8
- package/dist/cjs/core/react/wrapper.js +57 -0
- package/dist/cjs/core/server/federatedCss.js +7 -3
- package/dist/cjs/core/server/requestHandler.js +15 -45
- package/dist/cjs/core/server/requestResponse.js +83 -0
- package/dist/cjs/core/server/routerCleanup.js +16 -6
- package/dist/cjs/core/server/scriptOrder.js +13 -10
- package/dist/cjs/core/server/stream/afterTemplate.js +9 -5
- package/dist/cjs/core/server/stream/template.js +3 -3
- package/dist/cjs/core/server/string/index.js +3 -3
- package/dist/cjs/core/server/string/loadable.js +3 -11
- package/dist/cjs/document/cli/index.js +5 -2
- package/dist/cjs/index.js +7 -6
- package/dist/cjs/module-federation/consume-surface.js +199 -0
- package/dist/cjs/module-federation/distributed-ssr.js +134 -0
- package/dist/cjs/module-federation/index.js +258 -120
- package/dist/cjs/module-federation/last-known-good.js +124 -0
- package/dist/cjs/module-federation/manifest-recovery-runtime-plugin.js +140 -0
- package/dist/cjs/module-federation/surface-resolution-types.js +61 -0
- package/dist/cjs/router/cli/code/nestedRoutes.js +3 -0
- package/dist/cjs/router/cli/code/templates.js +3 -2
- package/dist/cjs/router/cli/constants.js +1 -0
- package/dist/cjs/router/cli/nestedRoutesSpec.js +3 -1
- package/dist/cjs/router/runtime/hooks.js +7 -6
- package/dist/cjs/router/runtime/internal.js +30 -16
- package/dist/cjs/router/runtime/plugin.js +6 -7
- package/dist/cjs/router/runtime/provider.js +58 -12
- package/dist/esm/boundary-debugger/index.mjs +13 -3
- package/dist/esm/cli/code.mjs +12 -12
- package/dist/esm/cli/index.mjs +2 -12
- package/dist/esm/cli/registry.mjs +0 -0
- package/dist/esm/cli/ssr/index.mjs +3 -2
- package/dist/esm/cli/ssr/loadable-bundler-plugin.mjs +8 -4
- package/dist/esm/core/browser/hydrate.mjs +15 -4
- package/dist/esm/core/browser/index.mjs +15 -17
- package/dist/esm/core/context/index.mjs +1 -1
- package/dist/esm/core/context/public.mjs +5 -0
- package/dist/esm/core/context/runtime.mjs +4 -6
- package/dist/esm/core/react/wrapper.mjs +58 -1
- package/dist/esm/core/server/federatedCss.mjs +7 -3
- package/dist/esm/core/server/requestHandler.mjs +15 -45
- package/dist/esm/core/server/requestResponse.mjs +39 -0
- package/dist/esm/core/server/routerCleanup.mjs +11 -4
- package/dist/esm/core/server/scriptOrder.mjs +11 -8
- package/dist/esm/core/server/stream/afterTemplate.mjs +10 -6
- package/dist/esm/core/server/stream/template.mjs +3 -3
- package/dist/esm/core/server/string/index.mjs +3 -3
- package/dist/esm/core/server/string/loadable.mjs +3 -8
- package/dist/esm/document/cli/index.mjs +1 -1
- package/dist/esm/exports/loadable.mjs +3 -3
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/module-federation/consume-surface.mjs +158 -0
- package/dist/esm/module-federation/distributed-ssr.mjs +81 -0
- package/dist/esm/module-federation/index.mjs +6 -0
- package/dist/esm/module-federation/last-known-good.mjs +80 -0
- package/dist/esm/module-federation/manifest-recovery-runtime-plugin.mjs +100 -0
- package/dist/esm/module-federation/surface-resolution-types.mjs +8 -0
- package/dist/esm/router/cli/code/index.mjs +5 -5
- package/dist/esm/router/cli/code/nestedRoutes.mjs +3 -0
- package/dist/esm/router/cli/code/templates.mjs +3 -2
- package/dist/esm/router/cli/constants.mjs +1 -0
- package/dist/esm/router/cli/handler.mjs +3 -3
- package/dist/esm/router/cli/nestedRoutesSpec.mjs +3 -1
- package/dist/esm/router/runtime/hooks.mjs +7 -6
- package/dist/esm/router/runtime/internal.mjs +26 -18
- package/dist/esm/router/runtime/plugin.mjs +6 -7
- package/dist/esm/router/runtime/provider.mjs +56 -13
- package/dist/esm-node/boundary-debugger/index.mjs +13 -3
- package/dist/esm-node/cli/code.mjs +12 -12
- package/dist/esm-node/cli/index.mjs +2 -12
- package/dist/esm-node/cli/registry.mjs +1 -0
- package/dist/esm-node/cli/ssr/index.mjs +3 -2
- package/dist/esm-node/cli/ssr/loadable-bundler-plugin.mjs +8 -4
- package/dist/esm-node/core/browser/hydrate.mjs +15 -4
- package/dist/esm-node/core/browser/index.mjs +15 -17
- package/dist/esm-node/core/context/index.mjs +1 -1
- package/dist/esm-node/core/context/public.mjs +6 -0
- package/dist/esm-node/core/context/runtime.mjs +4 -6
- package/dist/esm-node/core/react/wrapper.mjs +58 -1
- package/dist/esm-node/core/server/federatedCss.mjs +7 -3
- package/dist/esm-node/core/server/requestHandler.mjs +15 -45
- package/dist/esm-node/core/server/requestResponse.mjs +40 -0
- package/dist/esm-node/core/server/routerCleanup.mjs +11 -4
- package/dist/esm-node/core/server/scriptOrder.mjs +11 -8
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +10 -6
- package/dist/esm-node/core/server/stream/template.mjs +3 -3
- package/dist/esm-node/core/server/string/index.mjs +3 -3
- package/dist/esm-node/core/server/string/loadable.mjs +3 -8
- package/dist/esm-node/document/cli/index.mjs +1 -1
- package/dist/esm-node/exports/loadable.mjs +3 -3
- package/dist/esm-node/index.mjs +2 -1
- package/dist/esm-node/module-federation/consume-surface.mjs +159 -0
- package/dist/esm-node/module-federation/distributed-ssr.mjs +82 -0
- package/dist/esm-node/module-federation/index.mjs +6 -0
- package/dist/esm-node/module-federation/last-known-good.mjs +81 -0
- package/dist/esm-node/module-federation/manifest-recovery-runtime-plugin.mjs +101 -0
- package/dist/esm-node/module-federation/surface-resolution-types.mjs +9 -0
- package/dist/esm-node/router/cli/code/index.mjs +5 -5
- package/dist/esm-node/router/cli/code/nestedRoutes.mjs +3 -0
- package/dist/esm-node/router/cli/code/templates.mjs +3 -2
- package/dist/esm-node/router/cli/constants.mjs +1 -0
- package/dist/esm-node/router/cli/handler.mjs +3 -3
- package/dist/esm-node/router/cli/nestedRoutesSpec.mjs +3 -1
- package/dist/esm-node/router/runtime/hooks.mjs +7 -6
- package/dist/esm-node/router/runtime/internal.mjs +26 -18
- package/dist/esm-node/router/runtime/plugin.mjs +6 -7
- package/dist/esm-node/router/runtime/provider.mjs +56 -13
- package/dist/types/boundary-debugger/index.d.ts +1 -1
- package/dist/types/cli/registry.d.ts +2 -0
- package/dist/types/common.d.ts +8 -1
- package/dist/types/core/browser/hydrate.d.ts +2 -1
- package/dist/types/core/browser/index.d.ts +4 -1
- package/dist/types/core/context/index.d.ts +26 -10
- package/dist/types/core/context/monitors/default.d.ts +10 -2
- package/dist/types/core/context/monitors/index.d.ts +1 -1
- package/dist/types/core/context/monitors/index.server.d.ts +2 -2
- package/dist/types/core/context/public.d.ts +27 -0
- package/dist/types/core/context/runtime.d.ts +12 -22
- package/dist/types/core/react/index.d.ts +1 -1
- package/dist/types/core/server/requestResponse.d.ts +15 -0
- package/dist/types/core/server/routerCleanup.d.ts +2 -1
- package/dist/types/core/server/scriptOrder.d.ts +1 -1
- package/dist/types/core/server/stream/shared.d.ts +2 -2
- package/dist/types/core/server/string/loadable.d.ts +0 -2
- package/dist/types/document/cli/index.d.ts +1 -0
- package/dist/types/exports/head.d.ts +1 -1
- package/dist/types/index.d.ts +5 -5
- package/dist/types/internal.d.ts +0 -1
- package/dist/types/module-federation/consume-surface.d.ts +104 -0
- package/dist/types/module-federation/distributed-ssr.d.ts +61 -0
- package/dist/types/module-federation/index.d.ts +6 -0
- package/dist/types/module-federation/last-known-good.d.ts +72 -0
- package/dist/types/module-federation/manifest-recovery-runtime-plugin.d.ts +25 -0
- package/dist/types/module-federation/surface-resolution-types.d.ts +23 -0
- package/dist/types/router/cli/constants.d.ts +1 -0
- package/dist/types/router/runtime/hooks.d.ts +10 -6
- package/dist/types/router/runtime/internal.d.ts +13 -3
- package/dist/types/router/runtime/plugin.d.ts +1 -1
- package/dist/types/router/runtime/plugin.node.d.ts +1 -1
- package/dist/types/router/runtime/provider.d.ts +28 -11
- package/dist/types/router/runtime/types.d.ts +27 -5
- package/package.json +47 -27
- package/dist/cjs/exports/tanstack-router.js +0 -83
- package/dist/esm/exports/tanstack-router.mjs +0 -30
- package/dist/esm-node/exports/tanstack-router.mjs +0 -31
- package/dist/types/exports/tanstack-router.d.ts +0 -88
|
@@ -142,9 +142,20 @@ function BoundaryDebugger({ controlMode = 'visible', enabledByDefault = false, l
|
|
|
142
142
|
]);
|
|
143
143
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
144
144
|
if (!enabled) return void setBoxes([]);
|
|
145
|
+
let resizeObserver;
|
|
146
|
+
const observedElements = new Set();
|
|
147
|
+
const observeBoundaryElements = (elements)=>{
|
|
148
|
+
if (void 0 === resizeObserver) return;
|
|
149
|
+
for (const element of elements)if (!observedElements.has(element)) {
|
|
150
|
+
observedElements.add(element);
|
|
151
|
+
resizeObserver.observe(element);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
145
154
|
const readBoxes = ()=>{
|
|
155
|
+
const elements = collectBoundaryElements(legacySelector);
|
|
156
|
+
observeBoundaryElements(elements);
|
|
146
157
|
const seenBoxes = new Set();
|
|
147
|
-
const nextBoxes =
|
|
158
|
+
const nextBoxes = elements.map((element)=>{
|
|
148
159
|
const boundaryId = getBoundaryId(element);
|
|
149
160
|
if (void 0 === boundaryId || '' === boundaryId) return;
|
|
150
161
|
const rect = element.getBoundingClientRect();
|
|
@@ -172,9 +183,8 @@ function BoundaryDebugger({ controlMode = 'visible', enabledByDefault = false, l
|
|
|
172
183
|
}).filter((box)=>void 0 !== box);
|
|
173
184
|
setBoxes(nextBoxes);
|
|
174
185
|
};
|
|
186
|
+
resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(readBoxes);
|
|
175
187
|
readBoxes();
|
|
176
|
-
const resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(readBoxes);
|
|
177
|
-
for (const element of collectBoundaryElements(legacySelector))resizeObserver?.observe(element);
|
|
178
188
|
const mutationObserver = new MutationObserver(readBoxes);
|
|
179
189
|
mutationObserver.observe(document.body, {
|
|
180
190
|
childList: true,
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -112,12 +112,10 @@ const runtimePlugin = (params)=>({
|
|
|
112
112
|
});
|
|
113
113
|
api.config(()=>{
|
|
114
114
|
const { appDirectory, metaName } = api.getAppContext();
|
|
115
|
-
const isReact18 = (0, utils_namespaceObject.isReact18)(appDirectory);
|
|
116
|
-
process.env.IS_REACT18 = isReact18.toString();
|
|
117
115
|
return {
|
|
118
116
|
source: {
|
|
119
117
|
globalVars: {
|
|
120
|
-
'process.env.IS_REACT18':
|
|
118
|
+
'process.env.IS_REACT18': 'true'
|
|
121
119
|
},
|
|
122
120
|
include: [
|
|
123
121
|
new RegExp(`[\\\\/]node_modules[\\\\/]@${metaName}[\\\\/]runtime[\\\\/].*[\\\\/]head\\.`)
|
|
@@ -126,14 +124,6 @@ const runtimePlugin = (params)=>({
|
|
|
126
124
|
tools: {
|
|
127
125
|
bundlerChain: (chain)=>{
|
|
128
126
|
chain.module.rule('modern-entry').test(/\.jsx?$/).include.add(external_path_default().resolve(appDirectory, 'node_modules', `.${metaName}`)).end().sideEffects(true);
|
|
129
|
-
},
|
|
130
|
-
rspack: (_config, { appendPlugins, rspack })=>{
|
|
131
|
-
if (!isReact18) appendPlugins([
|
|
132
|
-
new rspack.IgnorePlugin({
|
|
133
|
-
resourceRegExp: /^react-dom\/client$/,
|
|
134
|
-
contextRegExp: /@modern-js\/runtime/
|
|
135
|
-
})
|
|
136
|
-
]);
|
|
137
127
|
}
|
|
138
128
|
}
|
|
139
129
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -129,14 +129,13 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
129
129
|
const hasServerRendering = hasServerRenderingConfig(userConfig);
|
|
130
130
|
const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
|
|
131
131
|
const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
|
|
132
|
-
const isCloudflareWorkerSSR = 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare';
|
|
133
132
|
const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
|
|
134
133
|
if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
|
|
135
134
|
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.';
|
|
136
135
|
if (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
137
136
|
console.warn(warningMessage);
|
|
138
137
|
}
|
|
139
|
-
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag
|
|
138
|
+
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
|
|
140
139
|
const ssrEnv = userConfig.deploy?.worker?.ssr || userConfig.server?.rsc ? 'edge' : 'node';
|
|
141
140
|
const appContext = modernAPI.getAppContext();
|
|
142
141
|
const { appDirectory, entrypoints } = appContext;
|
|
@@ -150,6 +149,8 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
150
149
|
define: {
|
|
151
150
|
'process.env.MODERN_TARGET': isServerEnvironment ? JSON.stringify('node') : JSON.stringify('browser'),
|
|
152
151
|
'process.env.MODERN_SSR_ENV': JSON.stringify(ssrEnv),
|
|
152
|
+
'process.env.MODERN_ENABLE_HYDRATION': JSON.stringify((0, utils_namespaceObject.isUseSSRBundle)(userConfig)),
|
|
153
|
+
'process.env.MODERN_ENABLE_RSC': JSON.stringify(Boolean(userConfig.server?.rsc)),
|
|
153
154
|
'process.env.MODERN_MF_APP_SSR': JSON.stringify(isModuleFederationAppSSR)
|
|
154
155
|
}
|
|
155
156
|
},
|
|
@@ -43,6 +43,7 @@ const utils_namespaceObject = require("@modern-js/utils");
|
|
|
43
43
|
const external_path_namespaceObject = require("path");
|
|
44
44
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
45
45
|
const normalizeChunkId = (id)=>'string' == typeof id && /^\d+$/.test(id) ? Number(id) : id;
|
|
46
|
+
const DEFAULT_CHUNK_LOADING_GLOBAL = '__LOADABLE_LOADED_CHUNKS__';
|
|
46
47
|
const normalizeChunkGroup = (group)=>({
|
|
47
48
|
...group,
|
|
48
49
|
chunks: (group.chunks || []).map(normalizeChunkId)
|
|
@@ -50,7 +51,11 @@ const normalizeChunkGroup = (group)=>({
|
|
|
50
51
|
class LoadablePlugin {
|
|
51
52
|
apply(compiler) {
|
|
52
53
|
this.compiler = compiler;
|
|
53
|
-
compiler.options.output.chunkLoadingGlobal
|
|
54
|
+
const chunkLoadingGlobal = this.opts.chunkLoadingGlobal ?? compiler.options.output.chunkLoadingGlobal ?? DEFAULT_CHUNK_LOADING_GLOBAL;
|
|
55
|
+
compiler.options.output.chunkLoadingGlobal = chunkLoadingGlobal;
|
|
56
|
+
new compiler.webpack.DefinePlugin({
|
|
57
|
+
'process.env.MODERN_CHUNK_LOADING_GLOBAL': JSON.stringify(chunkLoadingGlobal)
|
|
58
|
+
}).apply(compiler);
|
|
54
59
|
if (this.opts.outputAsset || this.opts.writeToDisk) compiler.hooks.make.tap(LoadablePlugin.name, (compilation)=>{
|
|
55
60
|
compilation.hooks.processAssets.tap({
|
|
56
61
|
name: LoadablePlugin.name,
|
|
@@ -110,10 +115,9 @@ class LoadablePlugin {
|
|
|
110
115
|
const outputFile = external_path_default().resolve(outputFolder || '', this.opts.filename);
|
|
111
116
|
utils_namespaceObject.fs.outputFileSync(outputFile, manifest);
|
|
112
117
|
}
|
|
113
|
-
constructor({ filename = 'loadable-stats.json', path, writeToDisk, outputAsset = true, chunkLoadingGlobal
|
|
118
|
+
constructor({ filename = 'loadable-stats.json', path, writeToDisk, outputAsset = true, chunkLoadingGlobal } = {
|
|
114
119
|
filename: 'loadable-stats.json',
|
|
115
|
-
outputAsset: true
|
|
116
|
-
chunkLoadingGlobal: '__LOADABLE_LOADED_CHUNKS__'
|
|
120
|
+
outputAsset: true
|
|
117
121
|
}){
|
|
118
122
|
this.opts = {
|
|
119
123
|
filename,
|
|
@@ -29,14 +29,26 @@ var __webpack_exports__ = {};
|
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
hydrateRoot: ()=>hydrateRoot,
|
|
32
|
+
hydrateWithReact: ()=>hydrateWithReact,
|
|
32
33
|
isReact18: ()=>isReact18
|
|
33
34
|
});
|
|
34
35
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
35
36
|
const component_namespaceObject = require("@loadable/component");
|
|
37
|
+
const constants_namespaceObject = require("@modern-js/utils/universal/constants");
|
|
38
|
+
const client_namespaceObject = require("react-dom/client");
|
|
36
39
|
const external_constants_js_namespaceObject = require("../constants.js");
|
|
37
40
|
const wrapper_js_namespaceObject = require("../react/wrapper.js");
|
|
38
41
|
const external_withCallback_js_namespaceObject = require("./withCallback.js");
|
|
39
42
|
const isReact18 = ()=>'true' === process.env.IS_REACT18;
|
|
43
|
+
const runtimeProcess = Reflect.get(globalThis, 'process');
|
|
44
|
+
const loadableReadyOptions = {
|
|
45
|
+
chunkLoadingGlobal: runtimeProcess?.env?.MODERN_CHUNK_LOADING_GLOBAL || '__LOADABLE_LOADED_CHUNKS__'
|
|
46
|
+
};
|
|
47
|
+
async function hydrateWithReact(App, rootElement) {
|
|
48
|
+
return (0, client_namespaceObject.hydrateRoot)(rootElement, App, {
|
|
49
|
+
identifierPrefix: constants_namespaceObject.SSR_HYDRATION_ID_PREFIX
|
|
50
|
+
});
|
|
51
|
+
}
|
|
40
52
|
function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
41
53
|
const hydrateContext = {
|
|
42
54
|
...context,
|
|
@@ -73,21 +85,23 @@ function hydrateRoot(App, context, ModernRender, ModernHydrate) {
|
|
|
73
85
|
ModernHydrate((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SSRApp, {}), hydrateContext)).then((root)=>{
|
|
74
86
|
resolve(root);
|
|
75
87
|
});
|
|
76
|
-
});
|
|
88
|
+
}, loadableReadyOptions);
|
|
77
89
|
else (0, component_namespaceObject.loadableReady)(()=>{
|
|
78
90
|
ModernHydrate((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, hydrateContext), callback).then((root)=>{
|
|
79
91
|
resolve(root);
|
|
80
92
|
});
|
|
81
|
-
});
|
|
93
|
+
}, loadableReadyOptions);
|
|
82
94
|
});
|
|
83
95
|
console.warn(`unknow render level: ${renderLevel}, execute render()`);
|
|
84
96
|
return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
|
|
85
97
|
}
|
|
86
98
|
}
|
|
87
99
|
exports.hydrateRoot = __webpack_exports__.hydrateRoot;
|
|
100
|
+
exports.hydrateWithReact = __webpack_exports__.hydrateWithReact;
|
|
88
101
|
exports.isReact18 = __webpack_exports__.isReact18;
|
|
89
102
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
90
103
|
"hydrateRoot",
|
|
104
|
+
"hydrateWithReact",
|
|
91
105
|
"isReact18"
|
|
92
106
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
93
107
|
Object.defineProperty(exports, '__esModule', {
|
|
@@ -28,14 +28,15 @@ var __webpack_require__ = {};
|
|
|
28
28
|
var __webpack_exports__ = {};
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
createNestedAppRenderer: ()=>createNestedAppRenderer,
|
|
32
|
+
hydrateWithReact: ()=>external_hydrate_js_namespaceObject.hydrateWithReact,
|
|
31
33
|
hydrateWithReact17: ()=>hydrateWithReact17,
|
|
32
|
-
hydrateWithReact18: ()=>hydrateWithReact18,
|
|
33
34
|
render: ()=>render,
|
|
34
35
|
renderWithReact17: ()=>renderWithReact17,
|
|
35
36
|
renderWithReact18: ()=>renderWithReact18
|
|
36
37
|
});
|
|
37
|
-
const constants_namespaceObject = require("@modern-js/utils/universal/constants");
|
|
38
38
|
const external_cookie_namespaceObject = require("cookie");
|
|
39
|
+
const client_namespaceObject = require("react-dom/client");
|
|
39
40
|
const index_js_namespaceObject = require("../context/index.js");
|
|
40
41
|
const runtime_js_namespaceObject = require("../context/runtime.js");
|
|
41
42
|
const wrapper_js_namespaceObject = require("../react/wrapper.js");
|
|
@@ -83,10 +84,9 @@ function getSSRData() {
|
|
|
83
84
|
function isClientArgs(id) {
|
|
84
85
|
return void 0 === id || 'string' == typeof id || "u" > typeof HTMLElement && id instanceof HTMLElement;
|
|
85
86
|
}
|
|
86
|
-
async function
|
|
87
|
+
async function renderApp(App, id, hydrateFromSsrData, internalRuntimeContext) {
|
|
87
88
|
const context = (0, runtime_js_namespaceObject.getInitialContext)();
|
|
88
89
|
const runBeforeRender = async (context)=>{
|
|
89
|
-
const internalRuntimeContext = (0, index_js_namespaceObject.getGlobalInternalRuntimeContext)();
|
|
90
90
|
const api = internalRuntimeContext.pluginAPI;
|
|
91
91
|
api.updateRuntimeContext(context);
|
|
92
92
|
const hooks = internalRuntimeContext.hooks;
|
|
@@ -106,17 +106,23 @@ async function render(App, id) {
|
|
|
106
106
|
return renderFunc(App, rootElement);
|
|
107
107
|
}
|
|
108
108
|
async function ModernHydrate(App, callback) {
|
|
109
|
-
|
|
110
|
-
return
|
|
109
|
+
if (IS_REACT18) return (0, external_hydrate_js_namespaceObject.hydrateWithReact)(App, rootElement);
|
|
110
|
+
return hydrateWithReact17(App, rootElement, callback);
|
|
111
111
|
}
|
|
112
|
-
if (window._SSR_DATA) return (0, external_hydrate_js_namespaceObject.hydrateRoot)(App, context, ModernRender, ModernHydrate);
|
|
112
|
+
if (hydrateFromSsrData && process.env.MODERN_ENABLE_HYDRATION && window._SSR_DATA) return (0, external_hydrate_js_namespaceObject.hydrateRoot)(App, context, ModernRender, ModernHydrate);
|
|
113
113
|
return ModernRender((0, wrapper_js_namespaceObject.wrapRuntimeContextProvider)(App, context));
|
|
114
114
|
}
|
|
115
115
|
throw Error('`render` function needs id in browser environment, it needs to be string or element');
|
|
116
116
|
}
|
|
117
|
+
async function render(App, id) {
|
|
118
|
+
return renderApp(App, id, true, (0, index_js_namespaceObject.getGlobalInternalRuntimeContext)());
|
|
119
|
+
}
|
|
120
|
+
function createNestedAppRenderer() {
|
|
121
|
+
const internalRuntimeContext = (0, index_js_namespaceObject.getGlobalInternalRuntimeContext)();
|
|
122
|
+
return (App, id)=>renderApp(App, id, false, internalRuntimeContext);
|
|
123
|
+
}
|
|
117
124
|
async function renderWithReact18(App, rootElement) {
|
|
118
|
-
const
|
|
119
|
-
const root = ReactDOM.createRoot(rootElement);
|
|
125
|
+
const root = (0, client_namespaceObject.createRoot)(rootElement);
|
|
120
126
|
root.render(App);
|
|
121
127
|
return root;
|
|
122
128
|
}
|
|
@@ -125,26 +131,21 @@ async function renderWithReact17(App, rootElement) {
|
|
|
125
131
|
ReactDOM.render(App, rootElement);
|
|
126
132
|
return rootElement;
|
|
127
133
|
}
|
|
128
|
-
async function hydrateWithReact18(App, rootElement) {
|
|
129
|
-
const ReactDOM = await import("react-dom/client");
|
|
130
|
-
const root = ReactDOM.hydrateRoot(rootElement, App, {
|
|
131
|
-
identifierPrefix: constants_namespaceObject.SSR_HYDRATION_ID_PREFIX
|
|
132
|
-
});
|
|
133
|
-
return root;
|
|
134
|
-
}
|
|
135
134
|
async function hydrateWithReact17(App, rootElement, callback) {
|
|
136
135
|
const ReactDOM = await import("react-dom");
|
|
137
136
|
const root = ReactDOM.hydrate(App, rootElement, callback);
|
|
138
137
|
return root;
|
|
139
138
|
}
|
|
139
|
+
exports.createNestedAppRenderer = __webpack_exports__.createNestedAppRenderer;
|
|
140
|
+
exports.hydrateWithReact = __webpack_exports__.hydrateWithReact;
|
|
140
141
|
exports.hydrateWithReact17 = __webpack_exports__.hydrateWithReact17;
|
|
141
|
-
exports.hydrateWithReact18 = __webpack_exports__.hydrateWithReact18;
|
|
142
142
|
exports.render = __webpack_exports__.render;
|
|
143
143
|
exports.renderWithReact17 = __webpack_exports__.renderWithReact17;
|
|
144
144
|
exports.renderWithReact18 = __webpack_exports__.renderWithReact18;
|
|
145
145
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
146
|
+
"createNestedAppRenderer",
|
|
147
|
+
"hydrateWithReact",
|
|
146
148
|
"hydrateWithReact17",
|
|
147
|
-
"hydrateWithReact18",
|
|
148
149
|
"render",
|
|
149
150
|
"renderWithReact17",
|
|
150
151
|
"renderWithReact18"
|
|
@@ -34,6 +34,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
34
34
|
applyRouterRuntimeState: ()=>lifecycle_js_namespaceObject.applyRouterRuntimeState,
|
|
35
35
|
applyRouterServerPrepareResult: ()=>lifecycle_js_namespaceObject.applyRouterServerPrepareResult,
|
|
36
36
|
cleanupRouterRuntimeState: ()=>lifecycle_js_namespaceObject.cleanupRouterRuntimeState,
|
|
37
|
+
createRouterProviderRealm: ()=>provider_js_namespaceObject.createRouterProviderRealm,
|
|
37
38
|
createRouterRuntimeState: ()=>lifecycle_js_namespaceObject.createRouterRuntimeState,
|
|
38
39
|
createRouterServerSnapshot: ()=>lifecycle_js_namespaceObject.createRouterServerSnapshot,
|
|
39
40
|
createRuntimeContextExtension: ()=>external_extensions_js_namespaceObject.createRuntimeContextExtension,
|
|
@@ -120,6 +121,7 @@ exports.RuntimeContext = __webpack_exports__.RuntimeContext;
|
|
|
120
121
|
exports.applyRouterRuntimeState = __webpack_exports__.applyRouterRuntimeState;
|
|
121
122
|
exports.applyRouterServerPrepareResult = __webpack_exports__.applyRouterServerPrepareResult;
|
|
122
123
|
exports.cleanupRouterRuntimeState = __webpack_exports__.cleanupRouterRuntimeState;
|
|
124
|
+
exports.createRouterProviderRealm = __webpack_exports__.createRouterProviderRealm;
|
|
123
125
|
exports.createRouterRuntimeState = __webpack_exports__.createRouterRuntimeState;
|
|
124
126
|
exports.createRouterServerSnapshot = __webpack_exports__.createRouterServerSnapshot;
|
|
125
127
|
exports.createRuntimeContextExtension = __webpack_exports__.createRuntimeContextExtension;
|
|
@@ -157,6 +159,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
157
159
|
"applyRouterRuntimeState",
|
|
158
160
|
"applyRouterServerPrepareResult",
|
|
159
161
|
"cleanupRouterRuntimeState",
|
|
162
|
+
"createRouterProviderRealm",
|
|
160
163
|
"createRouterRuntimeState",
|
|
161
164
|
"createRouterServerSnapshot",
|
|
162
165
|
"createRuntimeContextExtension",
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
ReactRuntimeContext: ()=>ReactRuntimeContext,
|
|
32
|
+
RuntimeContext: ()=>RuntimeContext,
|
|
33
|
+
useRuntimeContext: ()=>useRuntimeContext
|
|
34
|
+
});
|
|
35
|
+
const external_react_namespaceObject = require("react");
|
|
36
|
+
const RuntimeContext = (0, external_react_namespaceObject.createContext)({});
|
|
37
|
+
const ReactRuntimeContext = RuntimeContext;
|
|
38
|
+
const useRuntimeContext = ()=>(0, external_react_namespaceObject.useContext)(RuntimeContext);
|
|
39
|
+
exports.ReactRuntimeContext = __webpack_exports__.ReactRuntimeContext;
|
|
40
|
+
exports.RuntimeContext = __webpack_exports__.RuntimeContext;
|
|
41
|
+
exports.useRuntimeContext = __webpack_exports__.useRuntimeContext;
|
|
42
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
43
|
+
"ReactRuntimeContext",
|
|
44
|
+
"RuntimeContext",
|
|
45
|
+
"useRuntimeContext"
|
|
46
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
47
|
+
Object.defineProperty(exports, '__esModule', {
|
|
48
|
+
value: true
|
|
49
|
+
});
|
|
@@ -29,16 +29,15 @@ var __webpack_exports__ = {};
|
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
InternalRuntimeContext: ()=>InternalRuntimeContext,
|
|
32
|
-
ReactRuntimeContext: ()=>ReactRuntimeContext,
|
|
33
|
-
RuntimeContext: ()=>RuntimeContext,
|
|
32
|
+
ReactRuntimeContext: ()=>external_public_js_namespaceObject.ReactRuntimeContext,
|
|
33
|
+
RuntimeContext: ()=>external_public_js_namespaceObject.RuntimeContext,
|
|
34
34
|
getInitialContext: ()=>getInitialContext,
|
|
35
|
-
useRuntimeContext: ()=>useRuntimeContext
|
|
35
|
+
useRuntimeContext: ()=>external_public_js_namespaceObject.useRuntimeContext
|
|
36
36
|
});
|
|
37
|
-
const constants_namespaceObject = require("@modern-js/utils/universal/constants");
|
|
38
37
|
const external_react_namespaceObject = require("react");
|
|
38
|
+
const external_public_js_namespaceObject = require("./public.js");
|
|
39
|
+
const ROUTE_MANIFEST = '_MODERNJS_ROUTE_MANIFEST';
|
|
39
40
|
const InternalRuntimeContext = (0, external_react_namespaceObject.createContext)({});
|
|
40
|
-
const RuntimeContext = (0, external_react_namespaceObject.createContext)({});
|
|
41
|
-
const ReactRuntimeContext = RuntimeContext;
|
|
42
41
|
const getInitialContext = (isBrowser = true, routeManifest)=>{
|
|
43
42
|
const requestContext = {
|
|
44
43
|
request: {},
|
|
@@ -46,12 +45,11 @@ const getInitialContext = (isBrowser = true, routeManifest)=>{
|
|
|
46
45
|
};
|
|
47
46
|
return {
|
|
48
47
|
isBrowser,
|
|
49
|
-
routeManifest: routeManifest || "u" > typeof window && window[
|
|
48
|
+
routeManifest: routeManifest || "u" > typeof window && window[ROUTE_MANIFEST],
|
|
50
49
|
requestContext,
|
|
51
50
|
context: requestContext
|
|
52
51
|
};
|
|
53
52
|
};
|
|
54
|
-
const useRuntimeContext = ()=>(0, external_react_namespaceObject.useContext)(RuntimeContext);
|
|
55
53
|
exports.InternalRuntimeContext = __webpack_exports__.InternalRuntimeContext;
|
|
56
54
|
exports.ReactRuntimeContext = __webpack_exports__.ReactRuntimeContext;
|
|
57
55
|
exports.RuntimeContext = __webpack_exports__.RuntimeContext;
|
|
@@ -35,6 +35,42 @@ const external_react_helmet_async_namespaceObject = require("react-helmet-async"
|
|
|
35
35
|
const index_js_namespaceObject = require("../context/index.js");
|
|
36
36
|
const extensions_js_namespaceObject = require("../context/extensions.js");
|
|
37
37
|
const helmetContext_js_namespaceObject = require("../context/helmetContext.js");
|
|
38
|
+
function toRscSafeRecord(value) {
|
|
39
|
+
if (!value || 'object' != typeof value) return value;
|
|
40
|
+
return Object.fromEntries(Object.entries(value));
|
|
41
|
+
}
|
|
42
|
+
function createRscSafeSsrContext(ssrContext) {
|
|
43
|
+
if (!ssrContext) return ssrContext;
|
|
44
|
+
const { request } = ssrContext;
|
|
45
|
+
return {
|
|
46
|
+
nonce: ssrContext.nonce,
|
|
47
|
+
useJsonScript: ssrContext.useJsonScript,
|
|
48
|
+
htmlModifiers: [],
|
|
49
|
+
baseUrl: ssrContext.baseUrl,
|
|
50
|
+
request: request ? {
|
|
51
|
+
url: request.url,
|
|
52
|
+
userAgent: request.userAgent,
|
|
53
|
+
cookie: request.cookie,
|
|
54
|
+
pathname: request.pathname,
|
|
55
|
+
query: toRscSafeRecord(request.query),
|
|
56
|
+
params: toRscSafeRecord(request.params),
|
|
57
|
+
headers: toRscSafeRecord(request.headers),
|
|
58
|
+
host: request.host,
|
|
59
|
+
referer: request.referer
|
|
60
|
+
} : request,
|
|
61
|
+
mode: ssrContext.mode,
|
|
62
|
+
loaderFailureMode: ssrContext.loaderFailureMode
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function createRscSafeRequestContext(ssrContext) {
|
|
66
|
+
const safeSsrContext = createRscSafeSsrContext(ssrContext);
|
|
67
|
+
return {
|
|
68
|
+
request: safeSsrContext?.request || {},
|
|
69
|
+
response: {
|
|
70
|
+
locals: ssrContext?.response?.locals || {}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
38
74
|
function wrapRuntimeContextProvider(App, contextValue) {
|
|
39
75
|
const { isBrowser, initialData, routes, context, routeManifest, routerContext, unstable_getBlockNavState, ssrContext, _internalContext, _internalRouterBaseName, ...rest } = contextValue;
|
|
40
76
|
const internalContextValue = contextValue;
|
|
@@ -47,6 +83,27 @@ function wrapRuntimeContextProvider(App, contextValue) {
|
|
|
47
83
|
...rest
|
|
48
84
|
};
|
|
49
85
|
(0, extensions_js_namespaceObject.stripRuntimeContextExtensions)(runtimeContextValue);
|
|
86
|
+
if ((0, index_js_namespaceObject.getGlobalEnableRsc)() && !isBrowser) {
|
|
87
|
+
const rscSafeRequestContext = createRscSafeRequestContext(ssrContext);
|
|
88
|
+
const rscInternalContextValue = {
|
|
89
|
+
...internalContextValue,
|
|
90
|
+
context: rscSafeRequestContext,
|
|
91
|
+
requestContext: rscSafeRequestContext,
|
|
92
|
+
ssrContext: createRscSafeSsrContext(ssrContext)
|
|
93
|
+
};
|
|
94
|
+
const rscRuntimeContextValue = {
|
|
95
|
+
...runtimeContextValue,
|
|
96
|
+
context: rscSafeRequestContext,
|
|
97
|
+
requestContext: rscSafeRequestContext
|
|
98
|
+
};
|
|
99
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.InternalRuntimeContext.Provider, {
|
|
100
|
+
value: rscInternalContextValue,
|
|
101
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.RuntimeContext.Provider, {
|
|
102
|
+
value: rscRuntimeContextValue,
|
|
103
|
+
children: App
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
}
|
|
50
107
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.InternalRuntimeContext.Provider, {
|
|
51
108
|
value: internalContextValue,
|
|
52
109
|
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_js_namespaceObject.RuntimeContext.Provider, {
|
|
@@ -31,14 +31,18 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
createFederatedCssLinks: ()=>createFederatedCssLinks
|
|
32
32
|
});
|
|
33
33
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
34
|
+
const escapeHtmlAttribute = (value)=>value.replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<').replaceAll('>', '>');
|
|
34
35
|
const createFederatedCssLinks = (assets, options)=>{
|
|
35
36
|
if (void 0 === assets || 0 === assets.length) return '';
|
|
36
37
|
const seen = new Set(options.existingAssets || []);
|
|
37
38
|
const attributes = (0, external_utils_js_namespaceObject.attributesToString)(options.attributes || {});
|
|
38
39
|
const links = [];
|
|
39
|
-
for (const asset of assets)
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
for (const asset of assets){
|
|
41
|
+
const href = escapeHtmlAttribute(asset);
|
|
42
|
+
if (!('' === asset || seen.has(asset) || options.template.includes(asset) || options.template.includes(href))) {
|
|
43
|
+
seen.add(asset);
|
|
44
|
+
links.push(`<link${attributes} href="${href}" rel="stylesheet" />`);
|
|
45
|
+
}
|
|
42
46
|
}
|
|
43
47
|
return links.join('');
|
|
44
48
|
};
|
|
@@ -44,15 +44,13 @@ const node_namespaceObject = require("@modern-js/runtime-utils/node");
|
|
|
44
44
|
const request_namespaceObject = require("@modern-js/runtime-utils/universal/request");
|
|
45
45
|
const external_react_namespaceObject = require("react");
|
|
46
46
|
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
|
|
47
|
-
const lifecycle_js_namespaceObject = require("../../router/runtime/lifecycle.js");
|
|
48
|
-
const rsc_router_js_namespaceObject = require("../../router/runtime/rsc-router.js");
|
|
49
47
|
const index_js_namespaceObject = require("../context/index.js");
|
|
50
48
|
const runtime_js_namespaceObject = require("../context/runtime.js");
|
|
51
49
|
const serverPayload_index_js_namespaceObject = require("../context/serverPayload/index.js");
|
|
52
50
|
const external_react_index_js_namespaceObject = require("../react/index.js");
|
|
53
51
|
const external_constants_js_namespaceObject = require("./constants.js");
|
|
52
|
+
const external_requestResponse_js_namespaceObject = require("./requestResponse.js");
|
|
54
53
|
const external_routerCleanup_js_namespaceObject = require("./routerCleanup.js");
|
|
55
|
-
const external_tracer_js_namespaceObject = require("./tracer.js");
|
|
56
54
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
57
55
|
async function handleRSCRequest(request, Root, context, options, handleRequest) {
|
|
58
56
|
const serverPayload = (0, serverPayload_index_js_namespaceObject.getServerPayload)();
|
|
@@ -72,29 +70,6 @@ async function handleRSCRequest(request, Root, context, options, handleRequest)
|
|
|
72
70
|
runtimeContext: context
|
|
73
71
|
});
|
|
74
72
|
}
|
|
75
|
-
const isRedirectStatus = (status)=>status >= 300 && status <= 399;
|
|
76
|
-
const processRedirect = (headers, status, ctx)=>{
|
|
77
|
-
if (ctx.enableRsc && ctx.isRSCNavigation) return (0, rsc_router_js_namespaceObject.handleRSCRedirect)(headers, ctx.basename, status);
|
|
78
|
-
return new Response(null, {
|
|
79
|
-
status,
|
|
80
|
-
headers
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
const applyRouterSnapshotResult = (context, onError)=>{
|
|
84
|
-
const routerServerSnapshot = (0, lifecycle_js_namespaceObject.getRouterServerSnapshot)(context);
|
|
85
|
-
const routerStatusCode = routerServerSnapshot?.statusCode ?? context.routerContext?.statusCode;
|
|
86
|
-
if (routerStatusCode && 200 !== routerStatusCode) context.ssrContext?.response.status(routerStatusCode);
|
|
87
|
-
const errors = Object.values(routerServerSnapshot?.errors || context.routerContext?.errors || {});
|
|
88
|
-
if (errors.length > 0) onError(errors[0], external_tracer_js_namespaceObject.SSRErrors.LOADER_ERROR);
|
|
89
|
-
};
|
|
90
|
-
const createLoaderRedirectResponse = (beforeRenderResult, redirectCtx)=>{
|
|
91
|
-
if (!beforeRenderResult || !isRedirectStatus(beforeRenderResult.status)) return;
|
|
92
|
-
if (beforeRenderResult.headers.has('X-Modernjs-Redirect')) return beforeRenderResult;
|
|
93
|
-
const redirectUrl = beforeRenderResult.headers.get('Location') || '/';
|
|
94
|
-
return processRedirect(new Headers({
|
|
95
|
-
Location: redirectUrl
|
|
96
|
-
}), beforeRenderResult.status, redirectCtx);
|
|
97
|
-
};
|
|
98
73
|
const renderRequest = async (request, Root, context, options, handleRequest, enableRsc)=>{
|
|
99
74
|
if (enableRsc) return handleRSCRequest(request, Root, context, options, handleRequest);
|
|
100
75
|
return handleRequest(request, Root, {
|
|
@@ -102,17 +77,6 @@ const renderRequest = async (request, Root, context, options, handleRequest, ena
|
|
|
102
77
|
runtimeContext: context
|
|
103
78
|
});
|
|
104
79
|
};
|
|
105
|
-
const finalizeRenderResponse = (response, responseProxy, redirectCtx, routerCleanup)=>{
|
|
106
|
-
if (-1 !== responseProxy.status && isRedirectStatus(responseProxy.status) && responseProxy.headers.Location) return processRedirect(new Headers(responseProxy.headers), responseProxy.status, redirectCtx);
|
|
107
|
-
Object.entries(responseProxy.headers).forEach(([key, value])=>{
|
|
108
|
-
response.headers.set(key, value);
|
|
109
|
-
});
|
|
110
|
-
if (-1 !== responseProxy.status) return routerCleanup.deferUntilBodyDone(new Response(response.body, {
|
|
111
|
-
status: responseProxy.status,
|
|
112
|
-
headers: response.headers
|
|
113
|
-
}));
|
|
114
|
-
return routerCleanup.deferUntilBodyDone(response);
|
|
115
|
-
};
|
|
116
80
|
function createSSRContext(request, options) {
|
|
117
81
|
const { config, loaderContext, onError, onTiming, locals, resource, params, responseProxy, reporter } = options;
|
|
118
82
|
const { nonce, useJsonScript } = config;
|
|
@@ -208,20 +172,26 @@ const createRequestHandler = async (handleRequest, createRequestOptions)=>{
|
|
|
208
172
|
isRSCNavigation: 'true' === request.headers.get('x-rsc-tree'),
|
|
209
173
|
basename: ssrContext.baseUrl || '/'
|
|
210
174
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
175
|
+
const routerCleanup = (0, external_routerCleanup_js_namespaceObject.createRouterCleanup)(context, options.onError);
|
|
176
|
+
const beforeRenderResult = await (0, external_routerCleanup_js_namespaceObject.runWithRouterCleanupOnError)(routerCleanup, ()=>runBeforeRender(context));
|
|
177
|
+
await (0, external_routerCleanup_js_namespaceObject.runWithRouterCleanupOnError)(routerCleanup, ()=>{
|
|
178
|
+
(0, external_requestResponse_js_namespaceObject.applyRouterSnapshotResult)(context, options.onError);
|
|
179
|
+
});
|
|
180
|
+
if ("u" > typeof Response) {
|
|
181
|
+
const redirectResponse = await (0, external_routerCleanup_js_namespaceObject.runWithRouterCleanupOnError)(routerCleanup, ()=>(0, external_requestResponse_js_namespaceObject.createLoaderRedirectResponse)(beforeRenderResult, redirectCtx));
|
|
182
|
+
if (redirectResponse) {
|
|
183
|
+
await routerCleanup.run();
|
|
184
|
+
return redirectResponse;
|
|
217
185
|
}
|
|
186
|
+
}
|
|
187
|
+
await (0, external_routerCleanup_js_namespaceObject.runWithRouterCleanupOnError)(routerCleanup, ()=>{
|
|
218
188
|
if (!createRequestOptions?.enableRsc) {
|
|
219
189
|
const { htmlTemplate } = options.resource;
|
|
220
190
|
options.resource.htmlTemplate = htmlTemplate.replace('</head>', `${external_constants_js_namespaceObject.CHUNK_CSS_PLACEHOLDER}</head>`);
|
|
221
191
|
}
|
|
222
|
-
const response = await renderRequest(request, Root, context, options, handleRequest, !!createRequestOptions?.enableRsc);
|
|
223
|
-
return finalizeRenderResponse(response, responseProxy, redirectCtx, routerCleanup);
|
|
224
192
|
});
|
|
193
|
+
const response = await (0, external_routerCleanup_js_namespaceObject.runWithRouterCleanupOnError)(routerCleanup, ()=>renderRequest(request, Root, context, options, handleRequest, !!createRequestOptions?.enableRsc));
|
|
194
|
+
return (0, external_routerCleanup_js_namespaceObject.finishWithRouterCleanup)(routerCleanup, ()=>(0, external_requestResponse_js_namespaceObject.finalizeRenderResponse)(response, responseProxy, redirectCtx, routerCleanup));
|
|
225
195
|
});
|
|
226
196
|
};
|
|
227
197
|
return requestHandler;
|