@bleedingdev/modern-js-runtime 3.9.0-ultramodern.4 → 3.9.0-ultramodern.5
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 +2 -74
- package/dist/cjs/core/context/index.js +4 -43
- package/dist/cjs/core/context/public.js +4 -8
- package/dist/cjs/core/context/runtime.js +17 -6
- package/dist/cjs/core/react/wrapper.js +22 -65
- package/dist/cjs/core/server/helmet.js +5 -4
- 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 +34 -25
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +28 -21
- package/dist/cjs/core/server/stream/createReadableStream.js +208 -123
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +159 -90
- package/dist/cjs/core/server/stream/deferredScript.js +3 -3
- package/dist/cjs/core/server/stream/shared.js +2 -2
- package/dist/cjs/core/server/string/index.js +100 -64
- package/dist/cjs/core/server/string/loadable.js +34 -19
- 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/router/runtime/PrefetchLink.js +67 -123
- 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 +2 -8
- package/dist/cjs/router/runtime/plugin.node.js +2 -30
- package/dist/cjs/router/runtime/redirect.js +1 -1
- package/dist/esm/cli/ssr/index.mjs +3 -72
- package/dist/esm/core/context/index.mjs +2 -5
- package/dist/esm/core/context/public.mjs +1 -6
- package/dist/esm/core/context/runtime.mjs +12 -4
- package/dist/esm/core/react/wrapper.mjs +21 -67
- package/dist/esm/core/server/helmet.mjs +5 -4
- 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 +37 -28
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +31 -24
- package/dist/esm/core/server/stream/createReadableStream.mjs +207 -122
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +149 -90
- package/dist/esm/core/server/stream/deferredScript.mjs +3 -3
- package/dist/esm/core/server/stream/shared.mjs +2 -2
- package/dist/esm/core/server/string/index.mjs +104 -68
- package/dist/esm/core/server/string/loadable.mjs +34 -19
- 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/router/runtime/PrefetchLink.mjs +67 -123
- 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 +1 -7
- package/dist/esm/router/runtime/plugin.node.mjs +1 -29
- package/dist/esm/router/runtime/redirect.mjs +1 -1
- package/dist/esm-node/cli/ssr/index.mjs +3 -72
- package/dist/esm-node/core/context/index.mjs +2 -5
- package/dist/esm-node/core/context/public.mjs +1 -6
- package/dist/esm-node/core/context/runtime.mjs +12 -4
- package/dist/esm-node/core/react/wrapper.mjs +21 -67
- package/dist/esm-node/core/server/helmet.mjs +5 -4
- 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 +37 -28
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +31 -24
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +207 -122
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +149 -90
- package/dist/esm-node/core/server/stream/deferredScript.mjs +3 -3
- package/dist/esm-node/core/server/stream/shared.mjs +2 -2
- package/dist/esm-node/core/server/string/index.mjs +104 -68
- package/dist/esm-node/core/server/string/loadable.mjs +34 -19
- 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/router/runtime/PrefetchLink.mjs +67 -123
- 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 +1 -7
- package/dist/esm-node/router/runtime/plugin.node.mjs +1 -29
- 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/react/wrapper.d.ts +6 -0
- package/dist/types/core/server/helmet.d.ts +4 -5
- package/dist/types/core/server/shared.d.ts +23 -0
- 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 +1 -1
- 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/exports/head.d.ts +2 -2
- 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 +9 -38
- package/rstest.config.mts +32 -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/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-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/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
|
@@ -70,7 +70,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
70
70
|
NavLink: ()=>NavLink
|
|
71
71
|
});
|
|
72
72
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
73
|
-
const runtime_extensions_namespaceObject = require("@modern-js/runtime-extensions");
|
|
74
73
|
const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
75
74
|
const external_react_namespaceObject = require("react");
|
|
76
75
|
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
|
|
@@ -90,62 +89,6 @@ function composeEventHandlers(theirHandler, ourHandler) {
|
|
|
90
89
|
};
|
|
91
90
|
}
|
|
92
91
|
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
|
93
|
-
const DEFAULT_PREFETCH_BEHAVIOR = 'render';
|
|
94
|
-
const INTENT_DELAY = 100;
|
|
95
|
-
const VIEWPORT_ROOT_MARGIN = '200px';
|
|
96
|
-
const MAX_CONCURRENT_WARMUPS = 4;
|
|
97
|
-
const WARMUP_TTL = 30000;
|
|
98
|
-
const SLOW_EFFECTIVE_TYPES = new Set([
|
|
99
|
-
'slow-2g',
|
|
100
|
-
'2g'
|
|
101
|
-
]);
|
|
102
|
-
const warmupCache = new Map();
|
|
103
|
-
const warmupQueue = [];
|
|
104
|
-
let activeWarmups = 0;
|
|
105
|
-
const getWarmupTimestamp = ()=>performance.now();
|
|
106
|
-
const getConnection = ()=>{
|
|
107
|
-
const nav = globalThis.navigator;
|
|
108
|
-
return nav?.connection || nav?.mozConnection || nav?.webkitConnection;
|
|
109
|
-
};
|
|
110
|
-
const shouldWarmupOnCurrentNetwork = ()=>{
|
|
111
|
-
const connection = getConnection();
|
|
112
|
-
if (connection?.saveData) return false;
|
|
113
|
-
if ('string' == typeof connection?.effectiveType && SLOW_EFFECTIVE_TYPES.has(connection.effectiveType)) return false;
|
|
114
|
-
return true;
|
|
115
|
-
};
|
|
116
|
-
const pruneWarmupCache = (now = getWarmupTimestamp())=>{
|
|
117
|
-
for (const [key, timestamp] of warmupCache)if (now - timestamp > WARMUP_TTL) warmupCache.delete(key);
|
|
118
|
-
};
|
|
119
|
-
const runNextWarmup = ()=>{
|
|
120
|
-
while(activeWarmups < MAX_CONCURRENT_WARMUPS && warmupQueue.length > 0){
|
|
121
|
-
const task = warmupQueue.shift();
|
|
122
|
-
if (task.cancelled) continue;
|
|
123
|
-
activeWarmups += 1;
|
|
124
|
-
task.run().catch(()=>{
|
|
125
|
-
warmupCache.delete(task.key);
|
|
126
|
-
}).finally(()=>{
|
|
127
|
-
activeWarmups -= 1;
|
|
128
|
-
runNextWarmup();
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
const scheduleWarmup = (key, run)=>{
|
|
133
|
-
if (!shouldWarmupOnCurrentNetwork()) return ()=>{};
|
|
134
|
-
pruneWarmupCache();
|
|
135
|
-
if (warmupCache.has(key)) return ()=>{};
|
|
136
|
-
warmupCache.set(key, getWarmupTimestamp());
|
|
137
|
-
const task = {
|
|
138
|
-
key,
|
|
139
|
-
run,
|
|
140
|
-
cancelled: false
|
|
141
|
-
};
|
|
142
|
-
warmupQueue.push(task);
|
|
143
|
-
runNextWarmup();
|
|
144
|
-
return ()=>{
|
|
145
|
-
task.cancelled = true;
|
|
146
|
-
if (warmupQueue.includes(task)) warmupCache.delete(task.key);
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
92
|
const setRef = (ref, value)=>{
|
|
150
93
|
if (!ref) return;
|
|
151
94
|
if ('function' == typeof ref) return void ref(value);
|
|
@@ -153,70 +96,65 @@ const setRef = (ref, value)=>{
|
|
|
153
96
|
ref.current = value;
|
|
154
97
|
} catch {}
|
|
155
98
|
};
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const [
|
|
163
|
-
const
|
|
164
|
-
const [viewportElement, setViewportElement] = external_react_default().useState(null);
|
|
99
|
+
function usePrefetchBehavior(prefetch, preload, theirElementProps, policy) {
|
|
100
|
+
const [maybePrefetch, setMaybePrefetch] = external_react_default().useState(false);
|
|
101
|
+
const [state, setState] = external_react_default().useState({
|
|
102
|
+
code: false,
|
|
103
|
+
data: false
|
|
104
|
+
});
|
|
105
|
+
const [element, setElement] = external_react_default().useState(null);
|
|
106
|
+
const observerRef = external_react_default().useRef(void 0);
|
|
165
107
|
const { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } = theirElementProps;
|
|
166
108
|
external_react_default().useEffect(()=>{
|
|
167
|
-
if (
|
|
168
|
-
|
|
109
|
+
if (!policy) return void setState({
|
|
110
|
+
code: 'render' === prefetch,
|
|
111
|
+
data: 'render' === prefetch
|
|
112
|
+
});
|
|
113
|
+
const observer = policy.observe({
|
|
114
|
+
element,
|
|
115
|
+
prefetch,
|
|
116
|
+
preload,
|
|
117
|
+
notify: (next)=>setState((previous)=>previous.code === next.code && previous.data === next.data ? previous : next)
|
|
118
|
+
});
|
|
119
|
+
observerRef.current = observer;
|
|
120
|
+
return ()=>{
|
|
121
|
+
observerRef.current = void 0;
|
|
122
|
+
observer.dispose();
|
|
123
|
+
};
|
|
169
124
|
}, [
|
|
125
|
+
policy,
|
|
170
126
|
prefetch,
|
|
171
|
-
preload
|
|
127
|
+
preload,
|
|
128
|
+
element
|
|
129
|
+
]);
|
|
130
|
+
external_react_default().useEffect(()=>{
|
|
131
|
+
if (policy || !maybePrefetch) return;
|
|
132
|
+
const timer = setTimeout(()=>setState({
|
|
133
|
+
code: true,
|
|
134
|
+
data: true
|
|
135
|
+
}), 100);
|
|
136
|
+
return ()=>clearTimeout(timer);
|
|
137
|
+
}, [
|
|
138
|
+
policy,
|
|
139
|
+
maybePrefetch
|
|
172
140
|
]);
|
|
173
141
|
const setIntent = ()=>{
|
|
174
|
-
if (
|
|
142
|
+
if (policy) observerRef.current?.onIntent();
|
|
143
|
+
else if ('intent' === prefetch) setMaybePrefetch(true);
|
|
175
144
|
};
|
|
176
145
|
const cancelIntent = ()=>{
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
146
|
+
if (policy) observerRef.current?.onCancel();
|
|
147
|
+
else if ('intent' === prefetch) {
|
|
148
|
+
setMaybePrefetch(false);
|
|
149
|
+
setState({
|
|
150
|
+
code: false,
|
|
151
|
+
data: false
|
|
152
|
+
});
|
|
181
153
|
}
|
|
182
154
|
};
|
|
183
|
-
external_react_default().useEffect(()=>{
|
|
184
|
-
if (maybeWarmup) {
|
|
185
|
-
const id = setTimeout(()=>{
|
|
186
|
-
if ('intent' === prefetch) setShouldPrefetch(true);
|
|
187
|
-
if ('intent' === preload) setShouldPreload(true);
|
|
188
|
-
}, INTENT_DELAY);
|
|
189
|
-
return ()=>{
|
|
190
|
-
clearTimeout(id);
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
}, [
|
|
194
|
-
maybeWarmup,
|
|
195
|
-
prefetch,
|
|
196
|
-
preload
|
|
197
|
-
]);
|
|
198
|
-
external_react_default().useEffect(()=>{
|
|
199
|
-
if (!viewportElement || 'viewport' !== prefetch && 'viewport' !== preload || "u" < typeof IntersectionObserver) return;
|
|
200
|
-
const observer = new IntersectionObserver((entries)=>{
|
|
201
|
-
if (!entries.some((entry)=>entry.isIntersecting)) return;
|
|
202
|
-
if ('viewport' === prefetch) setShouldPrefetch(true);
|
|
203
|
-
if ('viewport' === preload) setShouldPreload(true);
|
|
204
|
-
observer.disconnect();
|
|
205
|
-
}, {
|
|
206
|
-
rootMargin: VIEWPORT_ROOT_MARGIN
|
|
207
|
-
});
|
|
208
|
-
observer.observe(viewportElement);
|
|
209
|
-
return ()=>{
|
|
210
|
-
observer.disconnect();
|
|
211
|
-
};
|
|
212
|
-
}, [
|
|
213
|
-
prefetch,
|
|
214
|
-
preload,
|
|
215
|
-
viewportElement
|
|
216
|
-
]);
|
|
217
155
|
return [
|
|
218
|
-
|
|
219
|
-
|
|
156
|
+
state.data,
|
|
157
|
+
state.code,
|
|
220
158
|
{
|
|
221
159
|
onFocus: composeEventHandlers(onFocus, setIntent),
|
|
222
160
|
onBlur: composeEventHandlers(onBlur, cancelIntent),
|
|
@@ -224,7 +162,7 @@ function usePrefetchBehavior(prefetch, preload, theirElementProps) {
|
|
|
224
162
|
onMouseLeave: composeEventHandlers(onMouseLeave, cancelIntent),
|
|
225
163
|
onTouchStart: composeEventHandlers(onTouchStart, setIntent)
|
|
226
164
|
},
|
|
227
|
-
|
|
165
|
+
setElement
|
|
228
166
|
];
|
|
229
167
|
}
|
|
230
168
|
async function loadRouteModule(route, routeAssets, chunkLoader) {
|
|
@@ -265,7 +203,8 @@ const PrefetchPageLinks = ({ path, includeData })=>{
|
|
|
265
203
|
const context = (0, external_react_namespaceObject.useContext)(index_js_namespaceObject.InternalRuntimeContext);
|
|
266
204
|
const { routeManifest, routes } = context;
|
|
267
205
|
const { routeAssets } = routeManifest || {};
|
|
268
|
-
const
|
|
206
|
+
const policy = context.linkPrefetchPolicy;
|
|
207
|
+
const allowNetworkWarmup = policy?.canWarmup() ?? true;
|
|
269
208
|
const matches = (0, external_react_namespaceObject.useMemo)(()=>Array.isArray(routes) ? (0, router_namespaceObject.matchRoutes)(routes, pathname) : [], [
|
|
270
209
|
pathname,
|
|
271
210
|
routes
|
|
@@ -285,7 +224,16 @@ const PrefetchPageLinks = ({ path, includeData })=>{
|
|
|
285
224
|
const routeAsset = routeId ? routeAssets[routeId] : void 0;
|
|
286
225
|
const chunkIds = routeAsset?.chunkIds;
|
|
287
226
|
if (!routeId || !Array.isArray(chunkIds) || 0 === chunkIds.length) return ()=>{};
|
|
288
|
-
|
|
227
|
+
const run = ()=>loadRouteModule(match.route, routeAssets, chunkLoader);
|
|
228
|
+
if (policy) return policy.schedule({
|
|
229
|
+
runtimeContext: context,
|
|
230
|
+
chunkLoader,
|
|
231
|
+
publicPath: getWebpackPublicPath(),
|
|
232
|
+
key: `route-module:${routeId}:${chunkIds.join(',')}`,
|
|
233
|
+
run
|
|
234
|
+
});
|
|
235
|
+
run().catch(()=>{});
|
|
236
|
+
return ()=>{};
|
|
289
237
|
});
|
|
290
238
|
return ()=>{
|
|
291
239
|
cancellations.forEach((cancel)=>cancel());
|
|
@@ -294,6 +242,7 @@ const PrefetchPageLinks = ({ path, includeData })=>{
|
|
|
294
242
|
allowNetworkWarmup,
|
|
295
243
|
chunkLoader,
|
|
296
244
|
context,
|
|
245
|
+
policy,
|
|
297
246
|
routeAssetGeneration
|
|
298
247
|
]);
|
|
299
248
|
if (!allowNetworkWarmup || !includeData || !window._SSR_DATA) return null;
|
|
@@ -305,10 +254,11 @@ const PrefetchPageLinks = ({ path, includeData })=>{
|
|
|
305
254
|
};
|
|
306
255
|
const PrefetchDataLinks = ({ matches, path, routeManifest })=>{
|
|
307
256
|
const { pathname, search, hash } = path;
|
|
257
|
+
const policy = (0, external_react_namespaceObject.useContext)(index_js_namespaceObject.InternalRuntimeContext).linkPrefetchPolicy;
|
|
308
258
|
const currentMatches = (0, router_namespaceObject.useMatches)();
|
|
309
259
|
const basename = (0, router_namespaceObject.useHref)('/');
|
|
310
260
|
const dataHrefs = (0, external_react_namespaceObject.useMemo)(()=>matches?.filter((match, index)=>{
|
|
311
|
-
if (
|
|
261
|
+
if (policy?.allowData(match.route) === false || !match.route.loader || 'function' != typeof match.route.loader || 0 === match.route.loader.length) return false;
|
|
312
262
|
if (match.route.shouldRevalidate) {
|
|
313
263
|
const currentUrl = new URL(location.pathname + location.search + location.hash, window.origin);
|
|
314
264
|
const nextUrl = new URL(pathname + search + hash, window.origin);
|
|
@@ -335,16 +285,10 @@ const PrefetchDataLinks = ({ matches, path, routeManifest })=>{
|
|
|
335
285
|
children: dataHrefs
|
|
336
286
|
});
|
|
337
287
|
};
|
|
338
|
-
const
|
|
339
|
-
if (false === preload || 'none' === preload) return 'none';
|
|
340
|
-
if (void 0 !== preload) return preload;
|
|
341
|
-
if ('none' === prefetch) return 'none';
|
|
342
|
-
return prefetch;
|
|
343
|
-
};
|
|
344
|
-
const createPrefetchLink = (Link)=>/*#__PURE__*/ (external_react_default()).forwardRef(({ to, prefetch = DEFAULT_PREFETCH_BEHAVIOR, preload, ...props }, forwardedRef)=>{
|
|
288
|
+
const createPrefetchLink = (Link)=>/*#__PURE__*/ (external_react_default()).forwardRef(({ to, prefetch, preload, ...props }, forwardedRef)=>{
|
|
345
289
|
const isAbsolute = 'string' == typeof to && ABSOLUTE_URL_REGEX.test(to);
|
|
346
|
-
const
|
|
347
|
-
const [shouldPrefetch, shouldPreload, prefetchHandlers, setViewportElement] = usePrefetchBehavior(prefetch,
|
|
290
|
+
const policy = (0, external_react_namespaceObject.useContext)(index_js_namespaceObject.InternalRuntimeContext).linkPrefetchPolicy;
|
|
291
|
+
const [shouldPrefetch, shouldPreload, prefetchHandlers, setViewportElement] = usePrefetchBehavior(prefetch, preload, props, policy);
|
|
348
292
|
const setAnchorRef = external_react_default().useCallback((element)=>{
|
|
349
293
|
setViewportElement(element);
|
|
350
294
|
setRef(forwardedRef, element);
|
|
@@ -33,7 +33,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
33
33
|
onAfterHydrateRouter: ()=>onAfterHydrateRouter,
|
|
34
34
|
onBeforeCreateRouter: ()=>onBeforeCreateRouter,
|
|
35
35
|
onBeforeCreateRoutes: ()=>onBeforeCreateRoutes,
|
|
36
|
-
onBeforeHydrateRouter: ()=>onBeforeHydrateRouter
|
|
36
|
+
onBeforeHydrateRouter: ()=>onBeforeHydrateRouter,
|
|
37
|
+
routerProviderRegistryHooks: ()=>routerProviderRegistryHooks
|
|
37
38
|
});
|
|
38
39
|
const plugin_namespaceObject = require("@modern-js/plugin");
|
|
39
40
|
const createRouterSyncHook = ()=>(0, plugin_namespaceObject.createSyncHook)();
|
|
@@ -43,19 +44,29 @@ const onBeforeCreateRouter = createRouterSyncHook();
|
|
|
43
44
|
const onAfterCreateRouter = createRouterSyncHook();
|
|
44
45
|
const onBeforeHydrateRouter = createRouterSyncHook();
|
|
45
46
|
const onAfterHydrateRouter = createRouterSyncHook();
|
|
47
|
+
const routerProviderRegistryHooks = {
|
|
48
|
+
modifyRoutes,
|
|
49
|
+
onBeforeCreateRoutes,
|
|
50
|
+
onBeforeCreateRouter,
|
|
51
|
+
onAfterCreateRouter,
|
|
52
|
+
onBeforeHydrateRouter,
|
|
53
|
+
onAfterHydrateRouter
|
|
54
|
+
};
|
|
46
55
|
exports.modifyRoutes = __webpack_exports__.modifyRoutes;
|
|
47
56
|
exports.onAfterCreateRouter = __webpack_exports__.onAfterCreateRouter;
|
|
48
57
|
exports.onAfterHydrateRouter = __webpack_exports__.onAfterHydrateRouter;
|
|
49
58
|
exports.onBeforeCreateRouter = __webpack_exports__.onBeforeCreateRouter;
|
|
50
59
|
exports.onBeforeCreateRoutes = __webpack_exports__.onBeforeCreateRoutes;
|
|
51
60
|
exports.onBeforeHydrateRouter = __webpack_exports__.onBeforeHydrateRouter;
|
|
61
|
+
exports.routerProviderRegistryHooks = __webpack_exports__.routerProviderRegistryHooks;
|
|
52
62
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
53
63
|
"modifyRoutes",
|
|
54
64
|
"onAfterCreateRouter",
|
|
55
65
|
"onAfterHydrateRouter",
|
|
56
66
|
"onBeforeCreateRouter",
|
|
57
67
|
"onBeforeCreateRoutes",
|
|
58
|
-
"onBeforeHydrateRouter"
|
|
68
|
+
"onBeforeHydrateRouter",
|
|
69
|
+
"routerProviderRegistryHooks"
|
|
59
70
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
60
71
|
Object.defineProperty(exports, '__esModule', {
|
|
61
72
|
value: true
|
|
@@ -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
|
|
@@ -39,9 +39,8 @@ const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
|
39
39
|
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
|
-
const
|
|
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: []
|
|
@@ -203,11 +202,6 @@ function useRouterCreation(props, options) {
|
|
|
203
202
|
basename: _basename,
|
|
204
203
|
hydrationData
|
|
205
204
|
});
|
|
206
|
-
(0, external_lifecycle_js_namespaceObject.applyRouterRuntimeState)(runtimeContext, {
|
|
207
|
-
framework: 'react-router',
|
|
208
|
-
basename: _basename,
|
|
209
|
-
instance: router
|
|
210
|
-
});
|
|
211
205
|
hooks.onAfterCreateRouter.call({
|
|
212
206
|
...routerLifecycleContext,
|
|
213
207
|
router,
|
|
@@ -51,9 +51,8 @@ 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)=>{
|
|
@@ -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;
|
|
@@ -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,
|
|
@@ -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 };
|
|
@@ -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, RuntimeComponentResolverContext, RuntimeContext, getInitialContext } 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,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { createContext, useContext } from "react";
|
|
3
|
-
const RuntimeContext = getRuntimeReactContext('public', ()=>createContext({}));
|
|
4
|
-
const ReactRuntimeContext = RuntimeContext;
|
|
5
|
-
const useRuntimeContext = ()=>useContext(RuntimeContext);
|
|
6
|
-
export { ReactRuntimeContext, RuntimeContext, useRuntimeContext };
|
|
1
|
+
export { ReactRuntimeContext, RuntimeContext, useRuntimeContext } from "./runtime.mjs";
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createContext } from "react";
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
3
2
|
const ROUTE_MANIFEST = '_MODERNJS_ROUTE_MANIFEST';
|
|
3
|
+
function getRuntimeReactContext(kind, create) {
|
|
4
|
+
const key = Symbol.for(`@modern-js/runtime:react-context:v1:${kind}`);
|
|
5
|
+
const contexts = globalThis;
|
|
6
|
+
contexts[key] ??= create();
|
|
7
|
+
return contexts[key];
|
|
8
|
+
}
|
|
4
9
|
const InternalRuntimeContext = getRuntimeReactContext('internal', ()=>createContext({}));
|
|
10
|
+
const RuntimeContext = getRuntimeReactContext('public', ()=>createContext({}));
|
|
11
|
+
const RuntimeComponentResolverContext = getRuntimeReactContext('component-resolver', ()=>createContext(void 0));
|
|
12
|
+
const ReactRuntimeContext = RuntimeContext;
|
|
13
|
+
const useRuntimeContext = ()=>useContext(RuntimeContext);
|
|
5
14
|
const getInitialContext = (isBrowser = true, routeManifest)=>{
|
|
6
15
|
const requestContext = {
|
|
7
16
|
request: {
|
|
@@ -25,5 +34,4 @@ const getInitialContext = (isBrowser = true, routeManifest)=>{
|
|
|
25
34
|
context: requestContext
|
|
26
35
|
};
|
|
27
36
|
};
|
|
28
|
-
export { ReactRuntimeContext, RuntimeContext, useRuntimeContext }
|
|
29
|
-
export { InternalRuntimeContext, getInitialContext };
|
|
37
|
+
export { InternalRuntimeContext, ReactRuntimeContext, RuntimeComponentResolverContext, RuntimeContext, getInitialContext, useRuntimeContext };
|