@bleedingdev/modern-js-runtime 3.2.0-ultramodern.17 → 3.2.0-ultramodern.22
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 +3 -2
- package/dist/cjs/core/server/helmet.js +2 -2
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +105 -0
- package/dist/cjs/router/cli/code/tanstackTypes.js +14 -4
- package/dist/cjs/router/runtime/tanstack/plugin.js +2 -0
- package/dist/cjs/router/runtime/tanstack/routeTree.js +38 -2
- package/dist/cjs/rsc/server.worker.js +58 -0
- package/dist/esm/cli/ssr/index.mjs +3 -2
- package/dist/esm/core/server/helmet.mjs +1 -1
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +61 -0
- package/dist/esm/router/cli/code/tanstackTypes.mjs +14 -4
- package/dist/esm/router/runtime/tanstack/plugin.mjs +2 -0
- package/dist/esm/router/runtime/tanstack/routeTree.mjs +38 -2
- package/dist/esm/rsc/server.worker.mjs +1 -0
- package/dist/esm-node/cli/ssr/index.mjs +3 -2
- package/dist/esm-node/core/server/helmet.mjs +1 -1
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +62 -0
- package/dist/esm-node/router/cli/code/tanstackTypes.mjs +14 -4
- package/dist/esm-node/router/runtime/tanstack/plugin.mjs +2 -0
- package/dist/esm-node/router/runtime/tanstack/routeTree.mjs +38 -2
- package/dist/esm-node/rsc/server.worker.mjs +2 -0
- package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +9 -0
- package/dist/types/rsc/server.worker.d.ts +1 -0
- package/package.json +15 -15
|
@@ -125,13 +125,14 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
125
125
|
const hasServerRendering = hasServerRenderingConfig(userConfig);
|
|
126
126
|
const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
|
|
127
127
|
const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
|
|
128
|
+
const isCloudflareWorkerSSR = 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare';
|
|
128
129
|
const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
|
|
129
130
|
if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
|
|
130
131
|
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.';
|
|
131
132
|
if (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
132
133
|
console.warn(warningMessage);
|
|
133
134
|
}
|
|
134
|
-
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
|
|
135
|
+
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag && !isCloudflareWorkerSSR;
|
|
135
136
|
const useModuleFederationNodeOutput = hasServerRendering && isModuleFederationAppSSR && isNodeEnvironmentTarget(config.output.target);
|
|
136
137
|
const ssrEnv = userConfig.deploy?.worker?.ssr || userConfig.server?.rsc ? 'edge' : 'node';
|
|
137
138
|
const appContext = modernAPI.getAppContext();
|
|
@@ -148,7 +149,7 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
148
149
|
} : void 0;
|
|
149
150
|
const useLoadablePlugin = (0, utils_namespaceObject.isUseSSRBundle)(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
150
151
|
const outputConfig = {
|
|
151
|
-
module: isServerEnvironment && !useModuleFederationNodeOutput && outputModule
|
|
152
|
+
module: isServerEnvironment && !useModuleFederationNodeOutput && (outputModule || 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare')
|
|
152
153
|
};
|
|
153
154
|
const useLoadableComponents = (0, utils_namespaceObject.isUseSSRBundle)(userConfig) && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
154
155
|
return mergeEnvironmentConfig(config, {
|
|
@@ -27,8 +27,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
createReplaceHelemt: ()=>createReplaceHelemt,
|
|
28
28
|
helmetReplace: ()=>helmetReplace
|
|
29
29
|
});
|
|
30
|
-
const external_os_namespaceObject = require("os");
|
|
31
30
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
31
|
+
const EOL = '\n';
|
|
32
32
|
const RE_HTML_ATTR = /<html[^>]*>/;
|
|
33
33
|
const RE_BODY_ATTR = /<body[^>]*>/;
|
|
34
34
|
const RE_LAST_IN_HEAD = /<\/head>/;
|
|
@@ -61,7 +61,7 @@ function helmetReplace(content, helmetData) {
|
|
|
61
61
|
script,
|
|
62
62
|
style,
|
|
63
63
|
!existTitleTag ? title : ''
|
|
64
|
-
].reduce((pre, cur)=>pre + (cur.length > 0 ? ` ${cur}${
|
|
64
|
+
].reduce((pre, cur)=>pre + (cur.length > 0 ? ` ${cur}${EOL}` : ''), '');
|
|
65
65
|
return (0, external_utils_js_namespaceObject.safeReplace)(result, RE_LAST_IN_HEAD, `${helmetStr}</head>`);
|
|
66
66
|
}
|
|
67
67
|
exports.createReplaceHelemt = __webpack_exports__.createReplaceHelemt;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
buildShellBeforeTemplate: ()=>buildShellBeforeTemplate
|
|
37
|
+
});
|
|
38
|
+
const router_namespaceObject = require("@modern-js/runtime-utils/router");
|
|
39
|
+
const external_react_helmet_namespaceObject = require("react-helmet");
|
|
40
|
+
var external_react_helmet_default = /*#__PURE__*/ __webpack_require__.n(external_react_helmet_namespaceObject);
|
|
41
|
+
const lifecycle_js_namespaceObject = require("../../../router/runtime/lifecycle.js");
|
|
42
|
+
const external_constants_js_namespaceObject = require("../constants.js");
|
|
43
|
+
const external_helmet_js_namespaceObject = require("../helmet.js");
|
|
44
|
+
const external_shared_js_namespaceObject = require("../shared.js");
|
|
45
|
+
const external_utils_js_namespaceObject = require("../utils.js");
|
|
46
|
+
const checkIsInline = (chunk, enableInline)=>{
|
|
47
|
+
if ('production' !== process.env.NODE_ENV) return false;
|
|
48
|
+
if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
49
|
+
return Boolean(enableInline);
|
|
50
|
+
};
|
|
51
|
+
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
52
|
+
const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
|
|
53
|
+
const helmetData = external_react_helmet_default().renderStatic();
|
|
54
|
+
const callbacks = [
|
|
55
|
+
(0, external_helmet_js_namespaceObject.createReplaceHelemt)(helmetData),
|
|
56
|
+
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
57
|
+
];
|
|
58
|
+
return (0, external_shared_js_namespaceObject.buildHtml)(beforeAppTemplate, callbacks);
|
|
59
|
+
async function injectCss(template, entryName, styledComponentsStyleTags) {
|
|
60
|
+
let css = await getCssChunks();
|
|
61
|
+
if (styledComponentsStyleTags) css += styledComponentsStyleTags;
|
|
62
|
+
return (0, external_utils_js_namespaceObject.safeReplace)(template, external_constants_js_namespaceObject.CHUNK_CSS_PLACEHOLDER, css);
|
|
63
|
+
async function getCssChunks() {
|
|
64
|
+
const { routeManifest, routerContext, routes } = runtimeContext;
|
|
65
|
+
if (!routeManifest) return '';
|
|
66
|
+
const { routeAssets } = routeManifest;
|
|
67
|
+
let matchedRouteManifests;
|
|
68
|
+
const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext);
|
|
69
|
+
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
70
|
+
else {
|
|
71
|
+
if (!routerContext || !routes) return '';
|
|
72
|
+
const matches = (0, router_namespaceObject.matchRoutes)(routes, routerContext.location, routerContext.basename);
|
|
73
|
+
matchedRouteManifests = matches?.map((match, index)=>{
|
|
74
|
+
if (!index) return;
|
|
75
|
+
const routeId = match.route.id;
|
|
76
|
+
if (routeId) return routeAssets[routeId];
|
|
77
|
+
}).filter(Boolean);
|
|
78
|
+
}
|
|
79
|
+
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
80
|
+
if (asyncEntry) matchedRouteManifests?.push(asyncEntry);
|
|
81
|
+
const cssChunks = matchedRouteManifests ? matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
82
|
+
const { referenceCssAssets = [] } = routeManifest;
|
|
83
|
+
const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
|
|
84
|
+
return [
|
|
85
|
+
...chunks,
|
|
86
|
+
..._cssChunks
|
|
87
|
+
];
|
|
88
|
+
}, []) : [];
|
|
89
|
+
const { inlineStyles } = config;
|
|
90
|
+
const styles = cssChunks.map((chunk)=>{
|
|
91
|
+
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
92
|
+
checkIsInline(chunk, inlineStyles);
|
|
93
|
+
return link;
|
|
94
|
+
});
|
|
95
|
+
return `${styles.join('')}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.buildShellBeforeTemplate = __webpack_exports__.buildShellBeforeTemplate;
|
|
100
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
101
|
+
"buildShellBeforeTemplate"
|
|
102
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
103
|
+
Object.defineProperty(exports, '__esModule', {
|
|
104
|
+
value: true
|
|
105
|
+
});
|
|
@@ -117,6 +117,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
117
117
|
const imports = [];
|
|
118
118
|
const statements = [];
|
|
119
119
|
const loaderImportMap = new Map();
|
|
120
|
+
const usedRouteVarNames = new Set();
|
|
120
121
|
let loaderIndex = 0;
|
|
121
122
|
let routeIndex = 0;
|
|
122
123
|
const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
|
|
@@ -150,10 +151,17 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
150
151
|
actionName
|
|
151
152
|
};
|
|
152
153
|
};
|
|
154
|
+
const reserveRouteVarName = (preferred)=>{
|
|
155
|
+
let candidate = preferred;
|
|
156
|
+
let suffix = 1;
|
|
157
|
+
while(usedRouteVarNames.has(candidate))candidate = `${preferred}_${suffix++}`;
|
|
158
|
+
usedRouteVarNames.add(candidate);
|
|
159
|
+
return candidate;
|
|
160
|
+
};
|
|
153
161
|
const createRouteVarName = (route)=>{
|
|
154
162
|
const id = route.id;
|
|
155
163
|
const base = id ? (0, external_makeLegalIdentifier_js_namespaceObject.makeLegalIdentifier)(id) : `r_${routeIndex++}`;
|
|
156
|
-
return `route_${base}
|
|
164
|
+
return reserveRouteVarName(`route_${base}`);
|
|
157
165
|
};
|
|
158
166
|
const buildRoute = async (opts)=>{
|
|
159
167
|
const { parentVar, route } = opts;
|
|
@@ -182,14 +190,16 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
182
190
|
actionName
|
|
183
191
|
});
|
|
184
192
|
if (staticDataSnippet) routeOpts.push(staticDataSnippet);
|
|
185
|
-
statements.push(`const ${varName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
186
193
|
const children = route.children;
|
|
194
|
+
const hasChildren = Boolean(children && children.length > 0);
|
|
195
|
+
const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
|
|
196
|
+
statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
187
197
|
if (children && children.length > 0) {
|
|
188
198
|
const childVars = await Promise.all(children.map((child)=>buildRoute({
|
|
189
|
-
parentVar:
|
|
199
|
+
parentVar: routeCtorVarName,
|
|
190
200
|
route: child
|
|
191
201
|
})));
|
|
192
|
-
statements.push(
|
|
202
|
+
statements.push(`const ${varName} = ${routeCtorVarName}.addChildren([${childVars.join(', ')}]);`);
|
|
193
203
|
}
|
|
194
204
|
return varName;
|
|
195
205
|
};
|
|
@@ -37,6 +37,7 @@ const external_hooks_js_namespaceObject = require("../hooks.js");
|
|
|
37
37
|
const external_lifecycle_js_namespaceObject = require("../lifecycle.js");
|
|
38
38
|
const external_utils_js_namespaceObject = require("../utils.js");
|
|
39
39
|
const external_basepathRewrite_js_namespaceObject = require("./basepathRewrite.js");
|
|
40
|
+
const external_prefetchLink_js_namespaceObject = require("./prefetchLink.js");
|
|
40
41
|
const external_routeTree_js_namespaceObject = require("./routeTree.js");
|
|
41
42
|
const client_js_namespaceObject = require("./rsc/client.js");
|
|
42
43
|
const BLOCKING_SUBSCRIBE_SYMBOL = Symbol.for('@modern-js/plugin-runtime:tanstack-blocking-subscribe');
|
|
@@ -98,6 +99,7 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
context.router = {
|
|
102
|
+
Link: external_prefetchLink_js_namespaceObject.Link,
|
|
101
103
|
useMatches: react_router_namespaceObject.useMatches,
|
|
102
104
|
useLocation: react_router_namespaceObject.useLocation,
|
|
103
105
|
useNavigate: react_router_namespaceObject.useNavigate,
|
|
@@ -29,6 +29,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
29
29
|
getModernRouteIdsFromMatches: ()=>getModernRouteIdsFromMatches
|
|
30
30
|
});
|
|
31
31
|
const react_router_namespaceObject = require("@tanstack/react-router");
|
|
32
|
+
const external_react_namespaceObject = require("react");
|
|
32
33
|
const external_DefaultNotFound_js_namespaceObject = require("../DefaultNotFound.js");
|
|
33
34
|
function createTanstackRoute(options) {
|
|
34
35
|
return (0, react_router_namespaceObject.createRoute)(options);
|
|
@@ -73,6 +74,33 @@ function isModernDeferredData(value) {
|
|
|
73
74
|
function normalizeModernLoaderResult(result) {
|
|
74
75
|
return isModernDeferredData(result) ? result.data : result;
|
|
75
76
|
}
|
|
77
|
+
function pickRouteModuleComponent(routeModule) {
|
|
78
|
+
if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
|
|
79
|
+
if (!routeModule || 'object' != typeof routeModule) return;
|
|
80
|
+
const module = routeModule;
|
|
81
|
+
const component = module.default || module.Component;
|
|
82
|
+
if ('function' == typeof component || component && 'object' == typeof component && '$$typeof' in component) return component;
|
|
83
|
+
}
|
|
84
|
+
function createServerLazyImportComponent(lazyImport, fallbackComponent) {
|
|
85
|
+
if ("u" > typeof document) return fallbackComponent;
|
|
86
|
+
let resolvedComponent;
|
|
87
|
+
let pendingLoad;
|
|
88
|
+
const load = async ()=>{
|
|
89
|
+
if (resolvedComponent) return resolvedComponent;
|
|
90
|
+
const routeModule = await lazyImport();
|
|
91
|
+
const component = pickRouteModuleComponent(routeModule);
|
|
92
|
+
if (component) resolvedComponent = component;
|
|
93
|
+
return resolvedComponent;
|
|
94
|
+
};
|
|
95
|
+
const Component = (props)=>{
|
|
96
|
+
if (resolvedComponent) return (0, external_react_namespaceObject.createElement)(resolvedComponent, props);
|
|
97
|
+
pendingLoad ||= load();
|
|
98
|
+
throw pendingLoad;
|
|
99
|
+
};
|
|
100
|
+
Component.load = load;
|
|
101
|
+
Component.preload = load;
|
|
102
|
+
return Component;
|
|
103
|
+
}
|
|
76
104
|
function throwTanstackRedirect(location) {
|
|
77
105
|
const target = location || '/';
|
|
78
106
|
try {
|
|
@@ -239,10 +267,18 @@ function wrapRouteObjectLoader(route, revalidationState) {
|
|
|
239
267
|
}
|
|
240
268
|
function toRouteComponent(routeObject) {
|
|
241
269
|
const route = routeObject;
|
|
270
|
+
const lazyImport = 'function' == typeof route.lazyImport ? route.lazyImport : void 0;
|
|
271
|
+
const fallbackComponent = route.Component ? route.Component : route.element ? ()=>route.element : void 0;
|
|
272
|
+
if (lazyImport && fallbackComponent) return createServerLazyImportComponent(lazyImport, fallbackComponent);
|
|
242
273
|
if (route.Component) return route.Component;
|
|
243
274
|
const element = route.element;
|
|
244
275
|
if (element) return ()=>element;
|
|
245
276
|
}
|
|
277
|
+
function toModernRouteComponent(route) {
|
|
278
|
+
const component = route.component || void 0;
|
|
279
|
+
if ('function' == typeof route.lazyImport && component) return createServerLazyImportComponent(route.lazyImport, component);
|
|
280
|
+
return component;
|
|
281
|
+
}
|
|
246
282
|
function toErrorComponent(routeObject) {
|
|
247
283
|
const route = routeObject;
|
|
248
284
|
if (route.ErrorBoundary) return route.ErrorBoundary;
|
|
@@ -322,7 +358,7 @@ function createRouteFromModernRoute(opts) {
|
|
|
322
358
|
const stableFallbackId = modernId || route._component || route.filename || route.data || ('function' == typeof route.loader ? route.id : void 0);
|
|
323
359
|
const pendingComponent = route.loading || route.pendingComponent;
|
|
324
360
|
const errorComponent = route.error || route.errorComponent;
|
|
325
|
-
const component = route
|
|
361
|
+
const component = toModernRouteComponent(route);
|
|
326
362
|
const modernLoader = route.loader;
|
|
327
363
|
const modernAction = route.action;
|
|
328
364
|
const modernShouldRevalidate = route.shouldRevalidate;
|
|
@@ -368,7 +404,7 @@ function createRouteFromModernRoute(opts) {
|
|
|
368
404
|
}
|
|
369
405
|
function createRouteTreeFromModernRoutes(routes) {
|
|
370
406
|
const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
|
|
371
|
-
const rootComponent = rootModern
|
|
407
|
+
const rootComponent = rootModern ? toModernRouteComponent(rootModern) : void 0;
|
|
372
408
|
const pendingComponent = rootModern?.loading;
|
|
373
409
|
const errorComponent = rootModern?.error;
|
|
374
410
|
const rootLoader = rootModern?.loader;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"@modern-js/render/rsc-worker" (module) {
|
|
4
|
+
module.exports = require("@modern-js/render/rsc-worker");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.n = (module)=>{
|
|
19
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
20
|
+
__webpack_require__.d(getter, {
|
|
21
|
+
a: getter
|
|
22
|
+
});
|
|
23
|
+
return getter;
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
28
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: definition[key]
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
(()=>{
|
|
35
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
36
|
+
})();
|
|
37
|
+
(()=>{
|
|
38
|
+
__webpack_require__.r = (exports1)=>{
|
|
39
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
40
|
+
value: 'Module'
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
43
|
+
value: true
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __webpack_exports__ = {};
|
|
48
|
+
(()=>{
|
|
49
|
+
__webpack_require__.r(__webpack_exports__);
|
|
50
|
+
var _modern_js_render_rsc_worker__rspack_import_0 = __webpack_require__("@modern-js/render/rsc-worker");
|
|
51
|
+
var __rspack_reexport = {};
|
|
52
|
+
for(const __rspack_import_key in _modern_js_render_rsc_worker__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_modern_js_render_rsc_worker__rspack_import_0[__rspack_import_key];
|
|
53
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
54
|
+
})();
|
|
55
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
56
|
+
Object.defineProperty(exports, '__esModule', {
|
|
57
|
+
value: true
|
|
58
|
+
});
|
|
@@ -84,13 +84,14 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
84
84
|
const hasServerRendering = hasServerRenderingConfig(userConfig);
|
|
85
85
|
const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
|
|
86
86
|
const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
|
|
87
|
+
const isCloudflareWorkerSSR = 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare';
|
|
87
88
|
const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
|
|
88
89
|
if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
|
|
89
90
|
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
91
|
if (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
91
92
|
console.warn(warningMessage);
|
|
92
93
|
}
|
|
93
|
-
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
|
|
94
|
+
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag && !isCloudflareWorkerSSR;
|
|
94
95
|
const useModuleFederationNodeOutput = hasServerRendering && isModuleFederationAppSSR && isNodeEnvironmentTarget(config.output.target);
|
|
95
96
|
const ssrEnv = userConfig.deploy?.worker?.ssr || userConfig.server?.rsc ? 'edge' : 'node';
|
|
96
97
|
const appContext = modernAPI.getAppContext();
|
|
@@ -107,7 +108,7 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
107
108
|
} : void 0;
|
|
108
109
|
const useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
109
110
|
const outputConfig = {
|
|
110
|
-
module: isServerEnvironment && !useModuleFederationNodeOutput && outputModule
|
|
111
|
+
module: isServerEnvironment && !useModuleFederationNodeOutput && (outputModule || 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare')
|
|
111
112
|
};
|
|
112
113
|
const useLoadableComponents = isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
113
114
|
return mergeEnvironmentConfig(config, {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { matchRoutes } from "@modern-js/runtime-utils/router";
|
|
2
|
+
import react_helmet from "react-helmet";
|
|
3
|
+
import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
4
|
+
import { CHUNK_CSS_PLACEHOLDER } from "../constants.mjs";
|
|
5
|
+
import { createReplaceHelemt } from "../helmet.mjs";
|
|
6
|
+
import { buildHtml } from "../shared.mjs";
|
|
7
|
+
import { safeReplace } from "../utils.mjs";
|
|
8
|
+
const checkIsInline = (chunk, enableInline)=>{
|
|
9
|
+
if ('production' !== process.env.NODE_ENV) return false;
|
|
10
|
+
if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
11
|
+
return Boolean(enableInline);
|
|
12
|
+
};
|
|
13
|
+
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
14
|
+
const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
|
|
15
|
+
const helmetData = react_helmet.renderStatic();
|
|
16
|
+
const callbacks = [
|
|
17
|
+
createReplaceHelemt(helmetData),
|
|
18
|
+
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
19
|
+
];
|
|
20
|
+
return buildHtml(beforeAppTemplate, callbacks);
|
|
21
|
+
async function injectCss(template, entryName, styledComponentsStyleTags) {
|
|
22
|
+
let css = await getCssChunks();
|
|
23
|
+
if (styledComponentsStyleTags) css += styledComponentsStyleTags;
|
|
24
|
+
return safeReplace(template, CHUNK_CSS_PLACEHOLDER, css);
|
|
25
|
+
async function getCssChunks() {
|
|
26
|
+
const { routeManifest, routerContext, routes } = runtimeContext;
|
|
27
|
+
if (!routeManifest) return '';
|
|
28
|
+
const { routeAssets } = routeManifest;
|
|
29
|
+
let matchedRouteManifests;
|
|
30
|
+
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
|
|
31
|
+
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
32
|
+
else {
|
|
33
|
+
if (!routerContext || !routes) return '';
|
|
34
|
+
const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
|
|
35
|
+
matchedRouteManifests = matches?.map((match, index)=>{
|
|
36
|
+
if (!index) return;
|
|
37
|
+
const routeId = match.route.id;
|
|
38
|
+
if (routeId) return routeAssets[routeId];
|
|
39
|
+
}).filter(Boolean);
|
|
40
|
+
}
|
|
41
|
+
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
42
|
+
if (asyncEntry) matchedRouteManifests?.push(asyncEntry);
|
|
43
|
+
const cssChunks = matchedRouteManifests ? matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
44
|
+
const { referenceCssAssets = [] } = routeManifest;
|
|
45
|
+
const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
|
|
46
|
+
return [
|
|
47
|
+
...chunks,
|
|
48
|
+
..._cssChunks
|
|
49
|
+
];
|
|
50
|
+
}, []) : [];
|
|
51
|
+
const { inlineStyles } = config;
|
|
52
|
+
const styles = cssChunks.map((chunk)=>{
|
|
53
|
+
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
54
|
+
checkIsInline(chunk, inlineStyles);
|
|
55
|
+
return link;
|
|
56
|
+
});
|
|
57
|
+
return `${styles.join('')}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export { buildShellBeforeTemplate };
|
|
@@ -78,6 +78,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
78
78
|
const imports = [];
|
|
79
79
|
const statements = [];
|
|
80
80
|
const loaderImportMap = new Map();
|
|
81
|
+
const usedRouteVarNames = new Set();
|
|
81
82
|
let loaderIndex = 0;
|
|
82
83
|
let routeIndex = 0;
|
|
83
84
|
const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
|
|
@@ -111,10 +112,17 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
111
112
|
actionName
|
|
112
113
|
};
|
|
113
114
|
};
|
|
115
|
+
const reserveRouteVarName = (preferred)=>{
|
|
116
|
+
let candidate = preferred;
|
|
117
|
+
let suffix = 1;
|
|
118
|
+
while(usedRouteVarNames.has(candidate))candidate = `${preferred}_${suffix++}`;
|
|
119
|
+
usedRouteVarNames.add(candidate);
|
|
120
|
+
return candidate;
|
|
121
|
+
};
|
|
114
122
|
const createRouteVarName = (route)=>{
|
|
115
123
|
const id = route.id;
|
|
116
124
|
const base = id ? makeLegalIdentifier(id) : `r_${routeIndex++}`;
|
|
117
|
-
return `route_${base}
|
|
125
|
+
return reserveRouteVarName(`route_${base}`);
|
|
118
126
|
};
|
|
119
127
|
const buildRoute = async (opts)=>{
|
|
120
128
|
const { parentVar, route } = opts;
|
|
@@ -143,14 +151,16 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
143
151
|
actionName
|
|
144
152
|
});
|
|
145
153
|
if (staticDataSnippet) routeOpts.push(staticDataSnippet);
|
|
146
|
-
statements.push(`const ${varName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
147
154
|
const children = route.children;
|
|
155
|
+
const hasChildren = Boolean(children && children.length > 0);
|
|
156
|
+
const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
|
|
157
|
+
statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
148
158
|
if (children && children.length > 0) {
|
|
149
159
|
const childVars = await Promise.all(children.map((child)=>buildRoute({
|
|
150
|
-
parentVar:
|
|
160
|
+
parentVar: routeCtorVarName,
|
|
151
161
|
route: child
|
|
152
162
|
})));
|
|
153
|
-
statements.push(
|
|
163
|
+
statements.push(`const ${varName} = ${routeCtorVarName}.addChildren([${childVars.join(', ')}]);`);
|
|
154
164
|
}
|
|
155
165
|
return varName;
|
|
156
166
|
};
|
|
@@ -8,6 +8,7 @@ import { onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBefo
|
|
|
8
8
|
import { applyRouterRuntimeState } from "../lifecycle.mjs";
|
|
9
9
|
import { createRouteObjectsFromConfig, urlJoin } from "../utils.mjs";
|
|
10
10
|
import { createModernBasepathRewrite } from "./basepathRewrite.mjs";
|
|
11
|
+
import { Link } from "./prefetchLink.mjs";
|
|
11
12
|
import { createRouteTreeFromRouteObjects } from "./routeTree.mjs";
|
|
12
13
|
import { getTanstackRscSerializationAdapters } from "./rsc/client.mjs";
|
|
13
14
|
import * as __rspack_external_react from "react";
|
|
@@ -70,6 +71,7 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
context.router = {
|
|
74
|
+
Link: Link,
|
|
73
75
|
useMatches: useMatches,
|
|
74
76
|
useLocation: useLocation,
|
|
75
77
|
useNavigate: useNavigate,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createRootRoute, createRoute, notFound, redirect } from "@tanstack/react-router";
|
|
2
|
+
import { createElement } from "react";
|
|
2
3
|
import { DefaultNotFound } from "../DefaultNotFound.mjs";
|
|
3
4
|
function createTanstackRoute(options) {
|
|
4
5
|
return createRoute(options);
|
|
@@ -43,6 +44,33 @@ function isModernDeferredData(value) {
|
|
|
43
44
|
function normalizeModernLoaderResult(result) {
|
|
44
45
|
return isModernDeferredData(result) ? result.data : result;
|
|
45
46
|
}
|
|
47
|
+
function pickRouteModuleComponent(routeModule) {
|
|
48
|
+
if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
|
|
49
|
+
if (!routeModule || 'object' != typeof routeModule) return;
|
|
50
|
+
const module = routeModule;
|
|
51
|
+
const component = module.default || module.Component;
|
|
52
|
+
if ('function' == typeof component || component && 'object' == typeof component && '$$typeof' in component) return component;
|
|
53
|
+
}
|
|
54
|
+
function createServerLazyImportComponent(lazyImport, fallbackComponent) {
|
|
55
|
+
if ("u" > typeof document) return fallbackComponent;
|
|
56
|
+
let resolvedComponent;
|
|
57
|
+
let pendingLoad;
|
|
58
|
+
const load = async ()=>{
|
|
59
|
+
if (resolvedComponent) return resolvedComponent;
|
|
60
|
+
const routeModule = await lazyImport();
|
|
61
|
+
const component = pickRouteModuleComponent(routeModule);
|
|
62
|
+
if (component) resolvedComponent = component;
|
|
63
|
+
return resolvedComponent;
|
|
64
|
+
};
|
|
65
|
+
const Component = (props)=>{
|
|
66
|
+
if (resolvedComponent) return createElement(resolvedComponent, props);
|
|
67
|
+
pendingLoad ||= load();
|
|
68
|
+
throw pendingLoad;
|
|
69
|
+
};
|
|
70
|
+
Component.load = load;
|
|
71
|
+
Component.preload = load;
|
|
72
|
+
return Component;
|
|
73
|
+
}
|
|
46
74
|
function throwTanstackRedirect(location) {
|
|
47
75
|
const target = location || '/';
|
|
48
76
|
try {
|
|
@@ -209,10 +237,18 @@ function wrapRouteObjectLoader(route, revalidationState) {
|
|
|
209
237
|
}
|
|
210
238
|
function toRouteComponent(routeObject) {
|
|
211
239
|
const route = routeObject;
|
|
240
|
+
const lazyImport = 'function' == typeof route.lazyImport ? route.lazyImport : void 0;
|
|
241
|
+
const fallbackComponent = route.Component ? route.Component : route.element ? ()=>route.element : void 0;
|
|
242
|
+
if (lazyImport && fallbackComponent) return createServerLazyImportComponent(lazyImport, fallbackComponent);
|
|
212
243
|
if (route.Component) return route.Component;
|
|
213
244
|
const element = route.element;
|
|
214
245
|
if (element) return ()=>element;
|
|
215
246
|
}
|
|
247
|
+
function toModernRouteComponent(route) {
|
|
248
|
+
const component = route.component || void 0;
|
|
249
|
+
if ('function' == typeof route.lazyImport && component) return createServerLazyImportComponent(route.lazyImport, component);
|
|
250
|
+
return component;
|
|
251
|
+
}
|
|
216
252
|
function toErrorComponent(routeObject) {
|
|
217
253
|
const route = routeObject;
|
|
218
254
|
if (route.ErrorBoundary) return route.ErrorBoundary;
|
|
@@ -292,7 +328,7 @@ function createRouteFromModernRoute(opts) {
|
|
|
292
328
|
const stableFallbackId = modernId || route._component || route.filename || route.data || ('function' == typeof route.loader ? route.id : void 0);
|
|
293
329
|
const pendingComponent = route.loading || route.pendingComponent;
|
|
294
330
|
const errorComponent = route.error || route.errorComponent;
|
|
295
|
-
const component = route
|
|
331
|
+
const component = toModernRouteComponent(route);
|
|
296
332
|
const modernLoader = route.loader;
|
|
297
333
|
const modernAction = route.action;
|
|
298
334
|
const modernShouldRevalidate = route.shouldRevalidate;
|
|
@@ -338,7 +374,7 @@ function createRouteFromModernRoute(opts) {
|
|
|
338
374
|
}
|
|
339
375
|
function createRouteTreeFromModernRoutes(routes) {
|
|
340
376
|
const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
|
|
341
|
-
const rootComponent = rootModern
|
|
377
|
+
const rootComponent = rootModern ? toModernRouteComponent(rootModern) : void 0;
|
|
342
378
|
const pendingComponent = rootModern?.loading;
|
|
343
379
|
const errorComponent = rootModern?.error;
|
|
344
380
|
const rootLoader = rootModern?.loader;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@modern-js/render/rsc-worker";
|
|
@@ -86,13 +86,14 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
86
86
|
const hasServerRendering = hasServerRenderingConfig(userConfig);
|
|
87
87
|
const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
|
|
88
88
|
const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
|
|
89
|
+
const isCloudflareWorkerSSR = 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare';
|
|
89
90
|
const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
|
|
90
91
|
if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
|
|
91
92
|
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.';
|
|
92
93
|
if (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
93
94
|
console.warn(warningMessage);
|
|
94
95
|
}
|
|
95
|
-
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
|
|
96
|
+
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag && !isCloudflareWorkerSSR;
|
|
96
97
|
const useModuleFederationNodeOutput = hasServerRendering && isModuleFederationAppSSR && isNodeEnvironmentTarget(config.output.target);
|
|
97
98
|
const ssrEnv = userConfig.deploy?.worker?.ssr || userConfig.server?.rsc ? 'edge' : 'node';
|
|
98
99
|
const appContext = modernAPI.getAppContext();
|
|
@@ -109,7 +110,7 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
109
110
|
} : void 0;
|
|
110
111
|
const useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
111
112
|
const outputConfig = {
|
|
112
|
-
module: isServerEnvironment && !useModuleFederationNodeOutput && outputModule
|
|
113
|
+
module: isServerEnvironment && !useModuleFederationNodeOutput && (outputModule || 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare')
|
|
113
114
|
};
|
|
114
115
|
const useLoadableComponents = isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
115
116
|
return mergeEnvironmentConfig(config, {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { matchRoutes } from "@modern-js/runtime-utils/router";
|
|
3
|
+
import react_helmet from "react-helmet";
|
|
4
|
+
import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
5
|
+
import { CHUNK_CSS_PLACEHOLDER } from "../constants.mjs";
|
|
6
|
+
import { createReplaceHelemt } from "../helmet.mjs";
|
|
7
|
+
import { buildHtml } from "../shared.mjs";
|
|
8
|
+
import { safeReplace } from "../utils.mjs";
|
|
9
|
+
const checkIsInline = (chunk, enableInline)=>{
|
|
10
|
+
if ('production' !== process.env.NODE_ENV) return false;
|
|
11
|
+
if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
12
|
+
return Boolean(enableInline);
|
|
13
|
+
};
|
|
14
|
+
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
15
|
+
const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
|
|
16
|
+
const helmetData = react_helmet.renderStatic();
|
|
17
|
+
const callbacks = [
|
|
18
|
+
createReplaceHelemt(helmetData),
|
|
19
|
+
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
20
|
+
];
|
|
21
|
+
return buildHtml(beforeAppTemplate, callbacks);
|
|
22
|
+
async function injectCss(template, entryName, styledComponentsStyleTags) {
|
|
23
|
+
let css = await getCssChunks();
|
|
24
|
+
if (styledComponentsStyleTags) css += styledComponentsStyleTags;
|
|
25
|
+
return safeReplace(template, CHUNK_CSS_PLACEHOLDER, css);
|
|
26
|
+
async function getCssChunks() {
|
|
27
|
+
const { routeManifest, routerContext, routes } = runtimeContext;
|
|
28
|
+
if (!routeManifest) return '';
|
|
29
|
+
const { routeAssets } = routeManifest;
|
|
30
|
+
let matchedRouteManifests;
|
|
31
|
+
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
|
|
32
|
+
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
33
|
+
else {
|
|
34
|
+
if (!routerContext || !routes) return '';
|
|
35
|
+
const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
|
|
36
|
+
matchedRouteManifests = matches?.map((match, index)=>{
|
|
37
|
+
if (!index) return;
|
|
38
|
+
const routeId = match.route.id;
|
|
39
|
+
if (routeId) return routeAssets[routeId];
|
|
40
|
+
}).filter(Boolean);
|
|
41
|
+
}
|
|
42
|
+
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
43
|
+
if (asyncEntry) matchedRouteManifests?.push(asyncEntry);
|
|
44
|
+
const cssChunks = matchedRouteManifests ? matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
45
|
+
const { referenceCssAssets = [] } = routeManifest;
|
|
46
|
+
const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
|
|
47
|
+
return [
|
|
48
|
+
...chunks,
|
|
49
|
+
..._cssChunks
|
|
50
|
+
];
|
|
51
|
+
}, []) : [];
|
|
52
|
+
const { inlineStyles } = config;
|
|
53
|
+
const styles = cssChunks.map((chunk)=>{
|
|
54
|
+
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
55
|
+
checkIsInline(chunk, inlineStyles);
|
|
56
|
+
return link;
|
|
57
|
+
});
|
|
58
|
+
return `${styles.join('')}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export { buildShellBeforeTemplate };
|
|
@@ -79,6 +79,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
79
79
|
const imports = [];
|
|
80
80
|
const statements = [];
|
|
81
81
|
const loaderImportMap = new Map();
|
|
82
|
+
const usedRouteVarNames = new Set();
|
|
82
83
|
let loaderIndex = 0;
|
|
83
84
|
let routeIndex = 0;
|
|
84
85
|
const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
|
|
@@ -112,10 +113,17 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
112
113
|
actionName
|
|
113
114
|
};
|
|
114
115
|
};
|
|
116
|
+
const reserveRouteVarName = (preferred)=>{
|
|
117
|
+
let candidate = preferred;
|
|
118
|
+
let suffix = 1;
|
|
119
|
+
while(usedRouteVarNames.has(candidate))candidate = `${preferred}_${suffix++}`;
|
|
120
|
+
usedRouteVarNames.add(candidate);
|
|
121
|
+
return candidate;
|
|
122
|
+
};
|
|
115
123
|
const createRouteVarName = (route)=>{
|
|
116
124
|
const id = route.id;
|
|
117
125
|
const base = id ? makeLegalIdentifier(id) : `r_${routeIndex++}`;
|
|
118
|
-
return `route_${base}
|
|
126
|
+
return reserveRouteVarName(`route_${base}`);
|
|
119
127
|
};
|
|
120
128
|
const buildRoute = async (opts)=>{
|
|
121
129
|
const { parentVar, route } = opts;
|
|
@@ -144,14 +152,16 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
144
152
|
actionName
|
|
145
153
|
});
|
|
146
154
|
if (staticDataSnippet) routeOpts.push(staticDataSnippet);
|
|
147
|
-
statements.push(`const ${varName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
148
155
|
const children = route.children;
|
|
156
|
+
const hasChildren = Boolean(children && children.length > 0);
|
|
157
|
+
const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
|
|
158
|
+
statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
149
159
|
if (children && children.length > 0) {
|
|
150
160
|
const childVars = await Promise.all(children.map((child)=>buildRoute({
|
|
151
|
-
parentVar:
|
|
161
|
+
parentVar: routeCtorVarName,
|
|
152
162
|
route: child
|
|
153
163
|
})));
|
|
154
|
-
statements.push(
|
|
164
|
+
statements.push(`const ${varName} = ${routeCtorVarName}.addChildren([${childVars.join(', ')}]);`);
|
|
155
165
|
}
|
|
156
166
|
return varName;
|
|
157
167
|
};
|
|
@@ -9,6 +9,7 @@ import { onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBefo
|
|
|
9
9
|
import { applyRouterRuntimeState } from "../lifecycle.mjs";
|
|
10
10
|
import { createRouteObjectsFromConfig, urlJoin } from "../utils.mjs";
|
|
11
11
|
import { createModernBasepathRewrite } from "./basepathRewrite.mjs";
|
|
12
|
+
import { Link } from "./prefetchLink.mjs";
|
|
12
13
|
import { createRouteTreeFromRouteObjects } from "./routeTree.mjs";
|
|
13
14
|
import { getTanstackRscSerializationAdapters } from "./rsc/client.mjs";
|
|
14
15
|
import * as __rspack_external_react from "react";
|
|
@@ -71,6 +72,7 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
context.router = {
|
|
75
|
+
Link: Link,
|
|
74
76
|
useMatches: useMatches,
|
|
75
77
|
useLocation: useLocation,
|
|
76
78
|
useNavigate: useNavigate,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { createRootRoute, createRoute, notFound, redirect } from "@tanstack/react-router";
|
|
3
|
+
import { createElement } from "react";
|
|
3
4
|
import { DefaultNotFound } from "../DefaultNotFound.mjs";
|
|
4
5
|
function createTanstackRoute(options) {
|
|
5
6
|
return createRoute(options);
|
|
@@ -44,6 +45,33 @@ function isModernDeferredData(value) {
|
|
|
44
45
|
function normalizeModernLoaderResult(result) {
|
|
45
46
|
return isModernDeferredData(result) ? result.data : result;
|
|
46
47
|
}
|
|
48
|
+
function pickRouteModuleComponent(routeModule) {
|
|
49
|
+
if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
|
|
50
|
+
if (!routeModule || 'object' != typeof routeModule) return;
|
|
51
|
+
const module = routeModule;
|
|
52
|
+
const component = module.default || module.Component;
|
|
53
|
+
if ('function' == typeof component || component && 'object' == typeof component && '$$typeof' in component) return component;
|
|
54
|
+
}
|
|
55
|
+
function createServerLazyImportComponent(lazyImport, fallbackComponent) {
|
|
56
|
+
if ("u" > typeof document) return fallbackComponent;
|
|
57
|
+
let resolvedComponent;
|
|
58
|
+
let pendingLoad;
|
|
59
|
+
const load = async ()=>{
|
|
60
|
+
if (resolvedComponent) return resolvedComponent;
|
|
61
|
+
const routeModule = await lazyImport();
|
|
62
|
+
const component = pickRouteModuleComponent(routeModule);
|
|
63
|
+
if (component) resolvedComponent = component;
|
|
64
|
+
return resolvedComponent;
|
|
65
|
+
};
|
|
66
|
+
const Component = (props)=>{
|
|
67
|
+
if (resolvedComponent) return createElement(resolvedComponent, props);
|
|
68
|
+
pendingLoad ||= load();
|
|
69
|
+
throw pendingLoad;
|
|
70
|
+
};
|
|
71
|
+
Component.load = load;
|
|
72
|
+
Component.preload = load;
|
|
73
|
+
return Component;
|
|
74
|
+
}
|
|
47
75
|
function throwTanstackRedirect(location) {
|
|
48
76
|
const target = location || '/';
|
|
49
77
|
try {
|
|
@@ -210,10 +238,18 @@ function wrapRouteObjectLoader(route, revalidationState) {
|
|
|
210
238
|
}
|
|
211
239
|
function toRouteComponent(routeObject) {
|
|
212
240
|
const route = routeObject;
|
|
241
|
+
const lazyImport = 'function' == typeof route.lazyImport ? route.lazyImport : void 0;
|
|
242
|
+
const fallbackComponent = route.Component ? route.Component : route.element ? ()=>route.element : void 0;
|
|
243
|
+
if (lazyImport && fallbackComponent) return createServerLazyImportComponent(lazyImport, fallbackComponent);
|
|
213
244
|
if (route.Component) return route.Component;
|
|
214
245
|
const element = route.element;
|
|
215
246
|
if (element) return ()=>element;
|
|
216
247
|
}
|
|
248
|
+
function toModernRouteComponent(route) {
|
|
249
|
+
const component = route.component || void 0;
|
|
250
|
+
if ('function' == typeof route.lazyImport && component) return createServerLazyImportComponent(route.lazyImport, component);
|
|
251
|
+
return component;
|
|
252
|
+
}
|
|
217
253
|
function toErrorComponent(routeObject) {
|
|
218
254
|
const route = routeObject;
|
|
219
255
|
if (route.ErrorBoundary) return route.ErrorBoundary;
|
|
@@ -293,7 +329,7 @@ function createRouteFromModernRoute(opts) {
|
|
|
293
329
|
const stableFallbackId = modernId || route._component || route.filename || route.data || ('function' == typeof route.loader ? route.id : void 0);
|
|
294
330
|
const pendingComponent = route.loading || route.pendingComponent;
|
|
295
331
|
const errorComponent = route.error || route.errorComponent;
|
|
296
|
-
const component = route
|
|
332
|
+
const component = toModernRouteComponent(route);
|
|
297
333
|
const modernLoader = route.loader;
|
|
298
334
|
const modernAction = route.action;
|
|
299
335
|
const modernShouldRevalidate = route.shouldRevalidate;
|
|
@@ -339,7 +375,7 @@ function createRouteFromModernRoute(opts) {
|
|
|
339
375
|
}
|
|
340
376
|
function createRouteTreeFromModernRoutes(routes) {
|
|
341
377
|
const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
|
|
342
|
-
const rootComponent = rootModern
|
|
378
|
+
const rootComponent = rootModern ? toModernRouteComponent(rootModern) : void 0;
|
|
343
379
|
const pendingComponent = rootModern?.loading;
|
|
344
380
|
const errorComponent = rootModern?.error;
|
|
345
381
|
const rootLoader = rootModern?.loader;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TInternalRuntimeContext } from '../../context';
|
|
2
|
+
import type { HandleRequestConfig } from '../requestHandler';
|
|
3
|
+
export interface BuildShellBeforeTemplateOptions {
|
|
4
|
+
runtimeContext: TInternalRuntimeContext;
|
|
5
|
+
entryName: string;
|
|
6
|
+
config: HandleRequestConfig;
|
|
7
|
+
styledComponentsStyleTags?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function buildShellBeforeTemplate(beforeAppTemplate: string, options: BuildShellBeforeTemplateOptions): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@modern-js/render/rsc-worker';
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.2.0-ultramodern.
|
|
20
|
+
"version": "3.2.0-ultramodern.22",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
@@ -212,11 +212,11 @@
|
|
|
212
212
|
"dependencies": {
|
|
213
213
|
"@loadable/component": "5.16.7",
|
|
214
214
|
"@loadable/server": "5.16.7",
|
|
215
|
-
"@swc/core": "1.15.
|
|
215
|
+
"@swc/core": "1.15.40",
|
|
216
216
|
"@swc/helpers": "^0.5.21",
|
|
217
|
-
"@swc/plugin-loadable-components": "^11.
|
|
218
|
-
"@tanstack/react-router": "1.170.
|
|
219
|
-
"@tanstack/router-core": "1.
|
|
217
|
+
"@swc/plugin-loadable-components": "^11.10.0",
|
|
218
|
+
"@tanstack/react-router": "1.170.8",
|
|
219
|
+
"@tanstack/router-core": "1.171.6",
|
|
220
220
|
"@types/loadable__component": "^5.13.10",
|
|
221
221
|
"@types/react-helmet": "^6.1.11",
|
|
222
222
|
"cookie": "1.1.1",
|
|
@@ -227,12 +227,12 @@
|
|
|
227
227
|
"isbot": "5.1.40",
|
|
228
228
|
"react-helmet": "^6.1.0",
|
|
229
229
|
"react-is": "^19.2.6",
|
|
230
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.
|
|
231
|
-
"@modern-js/
|
|
232
|
-
"@modern-js/
|
|
233
|
-
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.
|
|
234
|
-
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.
|
|
235
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.
|
|
230
|
+
"@modern-js/plugin-data-loader": "npm:@bleedingdev/modern-js-plugin-data-loader@3.2.0-ultramodern.22",
|
|
231
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.22",
|
|
232
|
+
"@modern-js/render": "npm:@bleedingdev/modern-js-render@3.2.0-ultramodern.22",
|
|
233
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.22",
|
|
234
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.22",
|
|
235
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.22"
|
|
236
236
|
},
|
|
237
237
|
"peerDependencies": {
|
|
238
238
|
"react": "^19.2.6",
|
|
@@ -240,18 +240,18 @@
|
|
|
240
240
|
},
|
|
241
241
|
"devDependencies": {
|
|
242
242
|
"@remix-run/web-fetch": "^4.4.2",
|
|
243
|
-
"@rsbuild/core": "2.0.
|
|
243
|
+
"@rsbuild/core": "2.0.7",
|
|
244
244
|
"@rslib/core": "0.21.5",
|
|
245
245
|
"@tanstack/history": "1.162.0",
|
|
246
246
|
"@testing-library/dom": "^10.4.1",
|
|
247
247
|
"@testing-library/react": "^16.3.2",
|
|
248
248
|
"@types/invariant": "^2.2.37",
|
|
249
249
|
"@types/loadable__server": "5.12.11",
|
|
250
|
-
"@types/node": "^25.
|
|
251
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
250
|
+
"@types/node": "^25.9.1",
|
|
251
|
+
"@typescript/native-preview": "7.0.0-dev.20260526.1",
|
|
252
252
|
"react": "^19.2.6",
|
|
253
253
|
"react-dom": "^19.2.6",
|
|
254
|
-
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.
|
|
254
|
+
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.22",
|
|
255
255
|
"@scripts/rstest-config": "2.66.0"
|
|
256
256
|
},
|
|
257
257
|
"sideEffects": false,
|