@bleedingdev/modern-js-runtime 3.2.0-ultramodern.8 → 3.2.0-ultramodern.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/boundary-debugger/index.js +298 -0
- package/dist/cjs/cli/ssr/index.js +3 -2
- package/dist/cjs/cli/template.server.js +1 -0
- package/dist/cjs/core/server/federatedCss.js +47 -0
- package/dist/cjs/core/server/helmet.js +2 -2
- package/dist/cjs/core/server/stream/afterTemplate.js +9 -6
- package/dist/cjs/core/server/stream/beforeTemplate.js +12 -8
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +109 -0
- package/dist/cjs/core/server/stream/createReadableStream.js +4 -2
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +4 -2
- package/dist/cjs/core/server/stream/shared.js +3 -1
- package/dist/cjs/core/server/string/index.js +3 -1
- package/dist/cjs/core/server/string/loadable.js +33 -7
- package/dist/cjs/router/cli/code/tanstackTypes.js +116 -51
- package/dist/cjs/router/cli/code/templates.js +1 -8
- package/dist/cjs/router/runtime/tanstack/plugin.js +4 -5
- package/dist/cjs/router/runtime/tanstack/plugin.node.js +2 -13
- package/dist/cjs/router/runtime/tanstack/routeTree.js +40 -4
- package/dist/cjs/rsc/server.worker.js +58 -0
- package/dist/esm/boundary-debugger/index.mjs +262 -0
- package/dist/esm/cli/ssr/index.mjs +3 -2
- package/dist/esm/cli/template.server.mjs +1 -0
- package/dist/esm/core/server/federatedCss.mjs +13 -0
- package/dist/esm/core/server/helmet.mjs +1 -1
- package/dist/esm/core/server/stream/afterTemplate.mjs +10 -7
- package/dist/esm/core/server/stream/beforeTemplate.mjs +12 -8
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +65 -0
- package/dist/esm/core/server/stream/createReadableStream.mjs +4 -2
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +4 -2
- package/dist/esm/core/server/stream/shared.mjs +3 -1
- package/dist/esm/core/server/string/index.mjs +3 -1
- package/dist/esm/core/server/string/loadable.mjs +33 -7
- package/dist/esm/router/cli/code/tanstackTypes.mjs +116 -51
- package/dist/esm/router/cli/code/templates.mjs +1 -8
- package/dist/esm/router/runtime/tanstack/plugin.mjs +8 -9
- package/dist/esm/router/runtime/tanstack/plugin.node.mjs +3 -14
- package/dist/esm/router/runtime/tanstack/routeTree.mjs +40 -4
- package/dist/esm/rsc/server.worker.mjs +1 -0
- package/dist/esm-node/boundary-debugger/index.mjs +263 -0
- package/dist/esm-node/cli/ssr/index.mjs +3 -2
- package/dist/esm-node/cli/template.server.mjs +1 -0
- package/dist/esm-node/core/server/federatedCss.mjs +14 -0
- package/dist/esm-node/core/server/helmet.mjs +1 -1
- package/dist/esm-node/core/server/stream/afterTemplate.mjs +10 -7
- package/dist/esm-node/core/server/stream/beforeTemplate.mjs +12 -8
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +66 -0
- package/dist/esm-node/core/server/stream/createReadableStream.mjs +4 -2
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +4 -2
- package/dist/esm-node/core/server/stream/shared.mjs +3 -1
- package/dist/esm-node/core/server/string/index.mjs +3 -1
- package/dist/esm-node/core/server/string/loadable.mjs +33 -7
- package/dist/esm-node/router/cli/code/tanstackTypes.mjs +116 -51
- package/dist/esm-node/router/cli/code/templates.mjs +1 -8
- package/dist/esm-node/router/runtime/tanstack/plugin.mjs +8 -9
- package/dist/esm-node/router/runtime/tanstack/plugin.node.mjs +3 -14
- package/dist/esm-node/router/runtime/tanstack/routeTree.mjs +40 -4
- package/dist/esm-node/rsc/server.worker.mjs +2 -0
- package/dist/types/boundary-debugger/index.d.ts +28 -0
- package/dist/types/core/server/federatedCss.d.ts +5 -0
- package/dist/types/core/server/stream/beforeTemplate.d.ts +1 -0
- package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +10 -0
- package/dist/types/core/server/stream/shared.d.ts +8 -0
- package/dist/types/core/server/string/loadable.d.ts +4 -0
- package/dist/types/rsc/server.worker.d.ts +1 -0
- package/package.json +22 -15
|
@@ -95,7 +95,7 @@ function createRenderStreaming(createReadableStreamPromise) {
|
|
|
95
95
|
const end = (0, time_namespaceObject.time)();
|
|
96
96
|
const { runtimeContext, config, resource } = options;
|
|
97
97
|
const { onError, onTiming } = options;
|
|
98
|
-
const { htmlTemplate, entryName } = resource;
|
|
98
|
+
const { htmlTemplate, entryName, moduleFederationCssAssets } = resource;
|
|
99
99
|
const ssrConfig = (0, external_utils_js_namespaceObject.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries);
|
|
100
100
|
const StreamServerRootWrapper = ({ children })=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
101
101
|
children: [
|
|
@@ -115,9 +115,11 @@ function createRenderStreaming(createReadableStreamPromise) {
|
|
|
115
115
|
runtimeContext,
|
|
116
116
|
ssrConfig,
|
|
117
117
|
entryName,
|
|
118
|
+
moduleFederationCssAssets,
|
|
118
119
|
rscClientManifest: options.rscClientManifest,
|
|
119
120
|
rscSSRManifest: options.rscSSRManifest,
|
|
120
121
|
rscServerManifest: options.rscServerManifest,
|
|
122
|
+
rscManifest: options.rscManifest,
|
|
121
123
|
rscRoot: options.rscRoot,
|
|
122
124
|
onShellReady () {
|
|
123
125
|
const cost = end();
|
|
@@ -58,7 +58,7 @@ const renderString = async (request, serverRoot, options)=>{
|
|
|
58
58
|
onTiming
|
|
59
59
|
};
|
|
60
60
|
const routerContext = runtimeContext.routerContext;
|
|
61
|
-
const { htmlTemplate, entryName, loadableStats, routeManifest } = resource;
|
|
61
|
+
const { htmlTemplate, entryName, loadableStats, routeManifest, moduleFederationCssAssets } = resource;
|
|
62
62
|
const ssrConfig = (0, external_utils_js_namespaceObject.getSSRConfigByEntry)(entryName, config.ssr, config.ssrByEntries);
|
|
63
63
|
const chunkSet = {
|
|
64
64
|
renderLevel: external_constants_js_namespaceObject.RenderLevel.CLIENT_RENDER,
|
|
@@ -71,8 +71,10 @@ const renderString = async (request, serverRoot, options)=>{
|
|
|
71
71
|
stats: loadableStats,
|
|
72
72
|
nonce: config.nonce,
|
|
73
73
|
routeManifest,
|
|
74
|
+
runtimeContext,
|
|
74
75
|
template: htmlTemplate,
|
|
75
76
|
entryName,
|
|
77
|
+
moduleFederationCssAssets,
|
|
76
78
|
chunkSet,
|
|
77
79
|
config
|
|
78
80
|
}),
|
|
@@ -27,6 +27,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
LoadableCollector: ()=>LoadableCollector
|
|
28
28
|
});
|
|
29
29
|
const server_namespaceObject = require("@loadable/server");
|
|
30
|
+
const lifecycle_js_namespaceObject = require("../../../router/runtime/lifecycle.js");
|
|
31
|
+
const external_federatedCss_js_namespaceObject = require("../federatedCss.js");
|
|
30
32
|
const external_utils_js_namespaceObject = require("../utils.js");
|
|
31
33
|
const extname = (uri)=>{
|
|
32
34
|
if ('string' != typeof uri || !uri.includes('.')) return '';
|
|
@@ -49,6 +51,20 @@ class LoadableCollector {
|
|
|
49
51
|
const { routeManifest, entryName } = this.options;
|
|
50
52
|
return routeManifest?.routeAssets?.[entryName]?.assets;
|
|
51
53
|
}
|
|
54
|
+
getMatchedRouteChunks() {
|
|
55
|
+
const { routeManifest, runtimeContext } = this.options;
|
|
56
|
+
const routeAssets = routeManifest?.routeAssets;
|
|
57
|
+
if (!routeAssets) return [];
|
|
58
|
+
const matchedRouteIds = (0, lifecycle_js_namespaceObject.getRouterMatchedRouteIds)(runtimeContext) ?? [];
|
|
59
|
+
return matchedRouteIds.flatMap((routeId)=>{
|
|
60
|
+
const routeAsset = routeAssets[routeId];
|
|
61
|
+
return (routeAsset?.assets ?? []).map((asset)=>({
|
|
62
|
+
filename: asset.replace(/^\//, ''),
|
|
63
|
+
path: asset,
|
|
64
|
+
url: asset
|
|
65
|
+
}));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
52
68
|
collect(comopnent) {
|
|
53
69
|
const { stats, entryName } = this.options;
|
|
54
70
|
if (!stats) return comopnent;
|
|
@@ -61,20 +77,21 @@ class LoadableCollector {
|
|
|
61
77
|
return this.extractor.collectChunks(comopnent);
|
|
62
78
|
}
|
|
63
79
|
async effect() {
|
|
64
|
-
if (!this.extractor) return;
|
|
65
80
|
const { extractor, options } = this;
|
|
66
81
|
const { entryName, config } = options;
|
|
67
82
|
const asyncChunks = [];
|
|
68
|
-
if (config.enableAsyncEntry) try {
|
|
83
|
+
if (extractor && config.enableAsyncEntry) try {
|
|
69
84
|
asyncChunks.push(...extractor.getChunkAssets([
|
|
70
85
|
`async-${entryName}`
|
|
71
86
|
]));
|
|
72
87
|
} catch (e) {}
|
|
73
|
-
const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
|
|
88
|
+
const chunks = [].concat(asyncChunks).concat(extractor ? extractor.getChunkAssets(extractor.chunks) : []).concat(this.getMatchedRouteChunks());
|
|
74
89
|
const scriptChunks = generateChunks(chunks, 'js');
|
|
75
90
|
const styleChunks = generateChunks(chunks, 'css');
|
|
76
|
-
|
|
77
|
-
|
|
91
|
+
if (extractor) {
|
|
92
|
+
this.emitLoadableScripts(extractor);
|
|
93
|
+
await this.emitScriptAssets(scriptChunks);
|
|
94
|
+
}
|
|
78
95
|
await this.emitStyleAssets(styleChunks);
|
|
79
96
|
}
|
|
80
97
|
emitLoadableScripts(extractor) {
|
|
@@ -109,19 +126,28 @@ class LoadableCollector {
|
|
|
109
126
|
chunkSet.jsChunk += scripts.filter((script)=>Boolean(script)).join('');
|
|
110
127
|
}
|
|
111
128
|
async emitStyleAssets(chunks) {
|
|
112
|
-
const { template, chunkSet, config,
|
|
129
|
+
const { template, chunkSet, config, moduleFederationCssAssets } = this.options;
|
|
113
130
|
const { inlineStyles } = config;
|
|
114
131
|
const atrributes = (0, external_utils_js_namespaceObject.attributesToString)(this.generateAttributes());
|
|
115
132
|
const linkRegExp = /<link .*?href="([^"]+)".*?>/g;
|
|
116
133
|
const matchs = template.matchAll(linkRegExp);
|
|
117
134
|
const existedLinks = [];
|
|
118
135
|
for (const match of matchs)existedLinks.push(match[1]);
|
|
119
|
-
const
|
|
136
|
+
const emittedChunks = chunks.filter((chunk)=>!existedLinks.includes(chunk.url) && !this.existsAssets?.includes(chunk.path));
|
|
137
|
+
const css = await Promise.all(emittedChunks.map(async (chunk)=>{
|
|
120
138
|
const link = `<link${atrributes} href="${chunk.url}" rel="stylesheet" />`;
|
|
121
139
|
if ((0, external_utils_js_namespaceObject.checkIsNode)() && checkIsInline(chunk, inlineStyles)) return readAsset(chunk).then((content)=>`<style>${content}</style>`).catch((_)=>link);
|
|
122
140
|
return link;
|
|
123
141
|
}));
|
|
124
142
|
chunkSet.cssChunk += css.filter((css)=>Boolean(css)).join('');
|
|
143
|
+
chunkSet.cssChunk += (0, external_federatedCss_js_namespaceObject.createFederatedCssLinks)(moduleFederationCssAssets, {
|
|
144
|
+
template,
|
|
145
|
+
attributes: this.generateAttributes(),
|
|
146
|
+
existingAssets: [
|
|
147
|
+
...existedLinks,
|
|
148
|
+
...emittedChunks.map((chunk)=>chunk.url)
|
|
149
|
+
]
|
|
150
|
+
});
|
|
125
151
|
}
|
|
126
152
|
generateAttributes(extraAtr = {}) {
|
|
127
153
|
const { config } = this.options;
|
|
@@ -116,9 +116,21 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
116
116
|
const topLevel = rootModern ? rootModern.children || [] : routes;
|
|
117
117
|
const imports = [];
|
|
118
118
|
const statements = [];
|
|
119
|
+
const componentImportMap = new Map();
|
|
119
120
|
const loaderImportMap = new Map();
|
|
121
|
+
const usedRouteVarNames = new Set();
|
|
122
|
+
let componentIndex = 0;
|
|
120
123
|
let loaderIndex = 0;
|
|
121
124
|
let routeIndex = 0;
|
|
125
|
+
const getImportNameForComponent = (componentPath)=>{
|
|
126
|
+
if ('string' != typeof componentPath || 0 === componentPath.length) return null;
|
|
127
|
+
const existing = componentImportMap.get(componentPath);
|
|
128
|
+
if (existing) return existing;
|
|
129
|
+
const componentName = `component_${componentIndex++}`;
|
|
130
|
+
imports.push(`import ${componentName} from ${quote(componentPath)};`);
|
|
131
|
+
componentImportMap.set(componentPath, componentName);
|
|
132
|
+
return componentName;
|
|
133
|
+
};
|
|
122
134
|
const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
|
|
123
135
|
const key = `${inline ? 'inline' : 'default'}:${hasAction ? 'action' : 'loader'}:${aliasedNoExtPath}`;
|
|
124
136
|
const existing = loaderImportMap.get(key);
|
|
@@ -150,10 +162,17 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
150
162
|
actionName
|
|
151
163
|
};
|
|
152
164
|
};
|
|
165
|
+
const reserveRouteVarName = (preferred)=>{
|
|
166
|
+
let candidate = preferred;
|
|
167
|
+
let suffix = 1;
|
|
168
|
+
while(usedRouteVarNames.has(candidate))candidate = `${preferred}_${suffix++}`;
|
|
169
|
+
usedRouteVarNames.add(candidate);
|
|
170
|
+
return candidate;
|
|
171
|
+
};
|
|
153
172
|
const createRouteVarName = (route)=>{
|
|
154
173
|
const id = route.id;
|
|
155
174
|
const base = id ? (0, external_makeLegalIdentifier_js_namespaceObject.makeLegalIdentifier)(id) : `r_${routeIndex++}`;
|
|
156
|
-
return `route_${base}
|
|
175
|
+
return reserveRouteVarName(`route_${base}`);
|
|
157
176
|
};
|
|
158
177
|
const buildRoute = async (opts)=>{
|
|
159
178
|
const { parentVar, route } = opts;
|
|
@@ -168,6 +187,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
168
187
|
const routeOpts = [
|
|
169
188
|
`getParentRoute: () => ${parentVar},`
|
|
170
189
|
];
|
|
190
|
+
const componentName = getImportNameForComponent(route._component);
|
|
191
|
+
if (componentName) routeOpts.push(`component: ${componentName},`);
|
|
171
192
|
if (isPathlessLayout(route)) {
|
|
172
193
|
const id = route.id;
|
|
173
194
|
routeOpts.push(`id: ${quote(id || 'pathless')},`);
|
|
@@ -182,14 +203,16 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
182
203
|
actionName
|
|
183
204
|
});
|
|
184
205
|
if (staticDataSnippet) routeOpts.push(staticDataSnippet);
|
|
185
|
-
statements.push(`const ${varName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
186
206
|
const children = route.children;
|
|
207
|
+
const hasChildren = Boolean(children && children.length > 0);
|
|
208
|
+
const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
|
|
209
|
+
statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
187
210
|
if (children && children.length > 0) {
|
|
188
211
|
const childVars = await Promise.all(children.map((child)=>buildRoute({
|
|
189
|
-
parentVar:
|
|
212
|
+
parentVar: routeCtorVarName,
|
|
190
213
|
route: child
|
|
191
214
|
})));
|
|
192
|
-
statements.push(
|
|
215
|
+
statements.push(`const ${varName} = ${routeCtorVarName}.addChildren([${childVars.join(', ')}]);`);
|
|
193
216
|
}
|
|
194
217
|
return varName;
|
|
195
218
|
};
|
|
@@ -203,6 +226,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
203
226
|
route
|
|
204
227
|
})));
|
|
205
228
|
const rootOpts = [];
|
|
229
|
+
const rootComponentName = getImportNameForComponent(rootModern?._component);
|
|
230
|
+
if (rootComponentName) rootOpts.push(`component: ${rootComponentName},`);
|
|
206
231
|
if (rootLoaderName) rootOpts.push(`loader: modernLoaderToTanstack({ hasSplat: false }, ${rootLoaderName}),`);
|
|
207
232
|
const routerGenTs = `/* eslint-disable */
|
|
208
233
|
// This file is auto-generated by Modern.js. Do not edit manually.
|
|
@@ -236,7 +261,7 @@ function isRedirectResponse(res: Response) {
|
|
|
236
261
|
}
|
|
237
262
|
|
|
238
263
|
function throwTanstackRedirect(location: string) {
|
|
239
|
-
const target = location
|
|
264
|
+
const target = location.length > 0 ? location : '/';
|
|
240
265
|
try {
|
|
241
266
|
void new URL(target);
|
|
242
267
|
throw redirect({ href: target });
|
|
@@ -262,21 +287,87 @@ function createRouteStaticData(opts: {
|
|
|
262
287
|
modernRouteAction?: unknown;
|
|
263
288
|
modernRouteLoader?: unknown;
|
|
264
289
|
}) {
|
|
265
|
-
const staticData:
|
|
290
|
+
const staticData: {
|
|
291
|
+
modernRouteId?: string;
|
|
292
|
+
modernRouteAction?: unknown;
|
|
293
|
+
modernRouteLoader?: unknown;
|
|
294
|
+
} = {};
|
|
266
295
|
|
|
267
|
-
if (opts.modernRouteId) {
|
|
296
|
+
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
268
297
|
staticData.modernRouteId = opts.modernRouteId;
|
|
269
298
|
}
|
|
270
299
|
|
|
271
|
-
if (opts.modernRouteLoader) {
|
|
300
|
+
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
272
301
|
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
273
302
|
}
|
|
274
303
|
|
|
275
|
-
if (opts.modernRouteAction) {
|
|
304
|
+
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
276
305
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
277
306
|
}
|
|
278
307
|
|
|
279
|
-
return
|
|
308
|
+
return staticData;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function getLoaderSignal(ctx: any): AbortSignal {
|
|
312
|
+
const abortSignal = ctx?.abortController?.signal;
|
|
313
|
+
if (abortSignal instanceof AbortSignal) {
|
|
314
|
+
return abortSignal;
|
|
315
|
+
}
|
|
316
|
+
if (ctx?.signal instanceof AbortSignal) {
|
|
317
|
+
return ctx.signal;
|
|
318
|
+
}
|
|
319
|
+
return new AbortController().signal;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function getLoaderHref(ctx: any): string {
|
|
323
|
+
if (typeof ctx?.location === 'string') {
|
|
324
|
+
return ctx.location;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const publicHref = ctx?.location?.publicHref;
|
|
328
|
+
if (typeof publicHref === 'string') {
|
|
329
|
+
return publicHref;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const href = ctx?.location?.href;
|
|
333
|
+
if (typeof href === 'string') {
|
|
334
|
+
return href;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const urlHref = ctx?.location?.url?.href;
|
|
338
|
+
return typeof urlHref === 'string' ? urlHref : '';
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function getLoaderParams(ctx: any): Record<string, string> {
|
|
342
|
+
return typeof ctx?.params === 'object' && ctx.params !== null ? ctx.params : {};
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult {
|
|
346
|
+
if (isResponse(result)) {
|
|
347
|
+
if (isRedirectResponse(result)) {
|
|
348
|
+
const location = result.headers.get('Location') ?? '/';
|
|
349
|
+
throwTanstackRedirect(location);
|
|
350
|
+
}
|
|
351
|
+
if (result.status === 404) {
|
|
352
|
+
throw notFound();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return result;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function handleModernLoaderError(err: unknown): never {
|
|
360
|
+
if (isResponse(err)) {
|
|
361
|
+
if (isRedirectResponse(err)) {
|
|
362
|
+
const location = err.headers.get('Location') ?? '/';
|
|
363
|
+
throwTanstackRedirect(location);
|
|
364
|
+
}
|
|
365
|
+
if (err.status === 404) {
|
|
366
|
+
throw notFound();
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
throw err;
|
|
280
371
|
}
|
|
281
372
|
|
|
282
373
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
@@ -285,57 +376,31 @@ function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
|
285
376
|
) {
|
|
286
377
|
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
287
378
|
|
|
288
|
-
return
|
|
379
|
+
return (ctx: any): Promise<LoaderResult> => {
|
|
289
380
|
try {
|
|
290
|
-
const signal
|
|
291
|
-
ctx?.abortController?.signal ||
|
|
292
|
-
ctx?.signal ||
|
|
293
|
-
new AbortController().signal;
|
|
381
|
+
const signal = getLoaderSignal(ctx);
|
|
294
382
|
const baseRequest: Request | undefined =
|
|
295
383
|
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
296
384
|
|
|
297
|
-
const href =
|
|
298
|
-
typeof ctx?.location === 'string'
|
|
299
|
-
? ctx.location
|
|
300
|
-
: ctx?.location?.publicHref ||
|
|
301
|
-
ctx?.location?.href ||
|
|
302
|
-
ctx?.location?.url?.href ||
|
|
303
|
-
'';
|
|
385
|
+
const href = getLoaderHref(ctx);
|
|
304
386
|
|
|
305
|
-
const request = baseRequest
|
|
387
|
+
const request = baseRequest !== undefined
|
|
306
388
|
? new Request(baseRequest, { signal })
|
|
307
389
|
: new Request(href, { signal });
|
|
308
390
|
|
|
309
|
-
const params = mapParamsForModernLoader(ctx
|
|
310
|
-
|
|
311
|
-
const result = await (modernLoader as any)({
|
|
312
|
-
request,
|
|
313
|
-
params,
|
|
314
|
-
context: ctx?.context?.requestContext,
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
if (isResponse(result)) {
|
|
318
|
-
if (isRedirectResponse(result)) {
|
|
319
|
-
const location = result.headers.get('Location') || '/';
|
|
320
|
-
throwTanstackRedirect(location);
|
|
321
|
-
}
|
|
322
|
-
if (result.status === 404) {
|
|
323
|
-
throw notFound();
|
|
324
|
-
}
|
|
325
|
-
}
|
|
391
|
+
const params = mapParamsForModernLoader(getLoaderParams(ctx), opts.hasSplat);
|
|
326
392
|
|
|
327
|
-
return
|
|
393
|
+
return Promise.resolve(
|
|
394
|
+
(modernLoader as any)({
|
|
395
|
+
request,
|
|
396
|
+
params,
|
|
397
|
+
context: ctx?.context?.requestContext,
|
|
398
|
+
}),
|
|
399
|
+
)
|
|
400
|
+
.then((result: LoaderResult) => handleModernLoaderResult(result))
|
|
401
|
+
.catch(handleModernLoaderError);
|
|
328
402
|
} catch (err) {
|
|
329
|
-
|
|
330
|
-
if (isRedirectResponse(err)) {
|
|
331
|
-
const location = err.headers.get('Location') || '/';
|
|
332
|
-
throwTanstackRedirect(location);
|
|
333
|
-
}
|
|
334
|
-
if (err.status === 404) {
|
|
335
|
-
throw notFound();
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
throw err;
|
|
403
|
+
handleModernLoaderError(err);
|
|
339
404
|
}
|
|
340
405
|
};
|
|
341
406
|
}
|
|
@@ -211,16 +211,9 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
211
211
|
webpackChunkName: true
|
|
212
212
|
});
|
|
213
213
|
component = 'string' === ssrMode ? `loadable(${lazyImport})` : `lazy(${lazyImport})`;
|
|
214
|
-
} else
|
|
214
|
+
} else {
|
|
215
215
|
components.push(route._component);
|
|
216
216
|
component = `component_${components.length - 1}`;
|
|
217
|
-
} else {
|
|
218
|
-
lazyImport = createLazyImport({
|
|
219
|
-
componentPath: route._component,
|
|
220
|
-
routeId: route.id,
|
|
221
|
-
eager: true
|
|
222
|
-
});
|
|
223
|
-
component = `lazy(${lazyImport})`;
|
|
224
217
|
}
|
|
225
218
|
} else if (route._component) if (splitRouteChunks) {
|
|
226
219
|
lazyImport = `() => import('${route._component}')`;
|
|
@@ -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,
|
|
@@ -208,11 +210,8 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
208
210
|
router,
|
|
209
211
|
runtimeContext: runtimeState
|
|
210
212
|
});
|
|
211
|
-
const RouterContent = hasSSRBootstrap ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(
|
|
212
|
-
|
|
213
|
-
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.RouterClient, {
|
|
214
|
-
router: router
|
|
215
|
-
})
|
|
213
|
+
const RouterContent = hasSSRBootstrap ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.RouterClient, {
|
|
214
|
+
router: router
|
|
216
215
|
}) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.RouterProvider, {
|
|
217
216
|
router: router
|
|
218
217
|
});
|
|
@@ -65,13 +65,6 @@ async function preloadMatchedRouteComponents(tanstackRouter) {
|
|
|
65
65
|
]);
|
|
66
66
|
}));
|
|
67
67
|
}
|
|
68
|
-
async function waitForRouterSerialization(tanstackRouter) {
|
|
69
|
-
const serverSsr = tanstackRouter.serverSsr;
|
|
70
|
-
if (!serverSsr || 'function' != typeof serverSsr.onSerializationFinished || serverSsr.isSerializationFinished?.()) return;
|
|
71
|
-
await new Promise((resolve)=>{
|
|
72
|
-
serverSsr.onSerializationFinished?.(resolve);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
68
|
function htmlEscapeAttr(value) {
|
|
76
69
|
return value.replace(/&/g, '&').replace(/"/g, '"');
|
|
77
70
|
}
|
|
@@ -217,7 +210,6 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
217
210
|
await preloadMatchedRouteComponents(serverRouter);
|
|
218
211
|
context.ssrContext?.response.status(tanstackRouter.state.statusCode);
|
|
219
212
|
await serverRouter.serverSsr?.dehydrate?.();
|
|
220
|
-
await waitForRouterSerialization(serverRouter);
|
|
221
213
|
const ssrScriptTags = serverRouter.serverSsr?.takeBufferedScripts?.();
|
|
222
214
|
const hydrationScripts = routerManagedTagsToHtml(ssrScriptTags);
|
|
223
215
|
const matchedRouteIds = (0, external_routeTree_js_namespaceObject.getModernRouteIdsFromMatches)(serverRouter);
|
|
@@ -255,11 +247,8 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
255
247
|
if (!router) return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
256
248
|
...props
|
|
257
249
|
}) : null;
|
|
258
|
-
const routerWrapper = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(
|
|
259
|
-
|
|
260
|
-
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.RouterProvider, {
|
|
261
|
-
router: router
|
|
262
|
-
})
|
|
250
|
+
const routerWrapper = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.RouterProvider, {
|
|
251
|
+
router: router
|
|
263
252
|
});
|
|
264
253
|
return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
265
254
|
children: routerWrapper
|
|
@@ -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 {
|
|
@@ -141,7 +169,7 @@ function wrapModernLoader(modernRoute, modernLoader, revalidationState) {
|
|
|
141
169
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
142
170
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
143
171
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
144
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
172
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
145
173
|
signal
|
|
146
174
|
}) : createModernRequest(href, signal);
|
|
147
175
|
const params = mapParamsForModernLoader({
|
|
@@ -204,7 +232,7 @@ function wrapRouteObjectLoader(route, revalidationState) {
|
|
|
204
232
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
205
233
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
206
234
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
207
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
235
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
208
236
|
signal
|
|
209
237
|
}) : createModernRequest(href, signal);
|
|
210
238
|
const params = mapParamsForRouteObjectLoader({
|
|
@@ -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
|
+
});
|