@bleedingdev/modern-js-runtime 3.2.0-ultramodern.8 → 3.2.0-ultramodern.80
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
|
@@ -77,9 +77,21 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
77
77
|
const topLevel = rootModern ? rootModern.children || [] : routes;
|
|
78
78
|
const imports = [];
|
|
79
79
|
const statements = [];
|
|
80
|
+
const componentImportMap = new Map();
|
|
80
81
|
const loaderImportMap = new Map();
|
|
82
|
+
const usedRouteVarNames = new Set();
|
|
83
|
+
let componentIndex = 0;
|
|
81
84
|
let loaderIndex = 0;
|
|
82
85
|
let routeIndex = 0;
|
|
86
|
+
const getImportNameForComponent = (componentPath)=>{
|
|
87
|
+
if ('string' != typeof componentPath || 0 === componentPath.length) return null;
|
|
88
|
+
const existing = componentImportMap.get(componentPath);
|
|
89
|
+
if (existing) return existing;
|
|
90
|
+
const componentName = `component_${componentIndex++}`;
|
|
91
|
+
imports.push(`import ${componentName} from ${quote(componentPath)};`);
|
|
92
|
+
componentImportMap.set(componentPath, componentName);
|
|
93
|
+
return componentName;
|
|
94
|
+
};
|
|
83
95
|
const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
|
|
84
96
|
const key = `${inline ? 'inline' : 'default'}:${hasAction ? 'action' : 'loader'}:${aliasedNoExtPath}`;
|
|
85
97
|
const existing = loaderImportMap.get(key);
|
|
@@ -111,10 +123,17 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
111
123
|
actionName
|
|
112
124
|
};
|
|
113
125
|
};
|
|
126
|
+
const reserveRouteVarName = (preferred)=>{
|
|
127
|
+
let candidate = preferred;
|
|
128
|
+
let suffix = 1;
|
|
129
|
+
while(usedRouteVarNames.has(candidate))candidate = `${preferred}_${suffix++}`;
|
|
130
|
+
usedRouteVarNames.add(candidate);
|
|
131
|
+
return candidate;
|
|
132
|
+
};
|
|
114
133
|
const createRouteVarName = (route)=>{
|
|
115
134
|
const id = route.id;
|
|
116
135
|
const base = id ? makeLegalIdentifier(id) : `r_${routeIndex++}`;
|
|
117
|
-
return `route_${base}
|
|
136
|
+
return reserveRouteVarName(`route_${base}`);
|
|
118
137
|
};
|
|
119
138
|
const buildRoute = async (opts)=>{
|
|
120
139
|
const { parentVar, route } = opts;
|
|
@@ -129,6 +148,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
129
148
|
const routeOpts = [
|
|
130
149
|
`getParentRoute: () => ${parentVar},`
|
|
131
150
|
];
|
|
151
|
+
const componentName = getImportNameForComponent(route._component);
|
|
152
|
+
if (componentName) routeOpts.push(`component: ${componentName},`);
|
|
132
153
|
if (isPathlessLayout(route)) {
|
|
133
154
|
const id = route.id;
|
|
134
155
|
routeOpts.push(`id: ${quote(id || 'pathless')},`);
|
|
@@ -143,14 +164,16 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
143
164
|
actionName
|
|
144
165
|
});
|
|
145
166
|
if (staticDataSnippet) routeOpts.push(staticDataSnippet);
|
|
146
|
-
statements.push(`const ${varName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
147
167
|
const children = route.children;
|
|
168
|
+
const hasChildren = Boolean(children && children.length > 0);
|
|
169
|
+
const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
|
|
170
|
+
statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
148
171
|
if (children && children.length > 0) {
|
|
149
172
|
const childVars = await Promise.all(children.map((child)=>buildRoute({
|
|
150
|
-
parentVar:
|
|
173
|
+
parentVar: routeCtorVarName,
|
|
151
174
|
route: child
|
|
152
175
|
})));
|
|
153
|
-
statements.push(
|
|
176
|
+
statements.push(`const ${varName} = ${routeCtorVarName}.addChildren([${childVars.join(', ')}]);`);
|
|
154
177
|
}
|
|
155
178
|
return varName;
|
|
156
179
|
};
|
|
@@ -164,6 +187,8 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
164
187
|
route
|
|
165
188
|
})));
|
|
166
189
|
const rootOpts = [];
|
|
190
|
+
const rootComponentName = getImportNameForComponent(rootModern?._component);
|
|
191
|
+
if (rootComponentName) rootOpts.push(`component: ${rootComponentName},`);
|
|
167
192
|
if (rootLoaderName) rootOpts.push(`loader: modernLoaderToTanstack({ hasSplat: false }, ${rootLoaderName}),`);
|
|
168
193
|
const routerGenTs = `/* eslint-disable */
|
|
169
194
|
// This file is auto-generated by Modern.js. Do not edit manually.
|
|
@@ -197,7 +222,7 @@ function isRedirectResponse(res: Response) {
|
|
|
197
222
|
}
|
|
198
223
|
|
|
199
224
|
function throwTanstackRedirect(location: string) {
|
|
200
|
-
const target = location
|
|
225
|
+
const target = location.length > 0 ? location : '/';
|
|
201
226
|
try {
|
|
202
227
|
void new URL(target);
|
|
203
228
|
throw redirect({ href: target });
|
|
@@ -223,21 +248,87 @@ function createRouteStaticData(opts: {
|
|
|
223
248
|
modernRouteAction?: unknown;
|
|
224
249
|
modernRouteLoader?: unknown;
|
|
225
250
|
}) {
|
|
226
|
-
const staticData:
|
|
251
|
+
const staticData: {
|
|
252
|
+
modernRouteId?: string;
|
|
253
|
+
modernRouteAction?: unknown;
|
|
254
|
+
modernRouteLoader?: unknown;
|
|
255
|
+
} = {};
|
|
227
256
|
|
|
228
|
-
if (opts.modernRouteId) {
|
|
257
|
+
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
229
258
|
staticData.modernRouteId = opts.modernRouteId;
|
|
230
259
|
}
|
|
231
260
|
|
|
232
|
-
if (opts.modernRouteLoader) {
|
|
261
|
+
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
233
262
|
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
234
263
|
}
|
|
235
264
|
|
|
236
|
-
if (opts.modernRouteAction) {
|
|
265
|
+
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
237
266
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
238
267
|
}
|
|
239
268
|
|
|
240
|
-
return
|
|
269
|
+
return staticData;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function getLoaderSignal(ctx: any): AbortSignal {
|
|
273
|
+
const abortSignal = ctx?.abortController?.signal;
|
|
274
|
+
if (abortSignal instanceof AbortSignal) {
|
|
275
|
+
return abortSignal;
|
|
276
|
+
}
|
|
277
|
+
if (ctx?.signal instanceof AbortSignal) {
|
|
278
|
+
return ctx.signal;
|
|
279
|
+
}
|
|
280
|
+
return new AbortController().signal;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function getLoaderHref(ctx: any): string {
|
|
284
|
+
if (typeof ctx?.location === 'string') {
|
|
285
|
+
return ctx.location;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const publicHref = ctx?.location?.publicHref;
|
|
289
|
+
if (typeof publicHref === 'string') {
|
|
290
|
+
return publicHref;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const href = ctx?.location?.href;
|
|
294
|
+
if (typeof href === 'string') {
|
|
295
|
+
return href;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const urlHref = ctx?.location?.url?.href;
|
|
299
|
+
return typeof urlHref === 'string' ? urlHref : '';
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function getLoaderParams(ctx: any): Record<string, string> {
|
|
303
|
+
return typeof ctx?.params === 'object' && ctx.params !== null ? ctx.params : {};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult {
|
|
307
|
+
if (isResponse(result)) {
|
|
308
|
+
if (isRedirectResponse(result)) {
|
|
309
|
+
const location = result.headers.get('Location') ?? '/';
|
|
310
|
+
throwTanstackRedirect(location);
|
|
311
|
+
}
|
|
312
|
+
if (result.status === 404) {
|
|
313
|
+
throw notFound();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return result;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function handleModernLoaderError(err: unknown): never {
|
|
321
|
+
if (isResponse(err)) {
|
|
322
|
+
if (isRedirectResponse(err)) {
|
|
323
|
+
const location = err.headers.get('Location') ?? '/';
|
|
324
|
+
throwTanstackRedirect(location);
|
|
325
|
+
}
|
|
326
|
+
if (err.status === 404) {
|
|
327
|
+
throw notFound();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
throw err;
|
|
241
332
|
}
|
|
242
333
|
|
|
243
334
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
@@ -246,57 +337,31 @@ function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
|
246
337
|
) {
|
|
247
338
|
type LoaderResult = Awaited<ReturnType<TLoader>>;
|
|
248
339
|
|
|
249
|
-
return
|
|
340
|
+
return (ctx: any): Promise<LoaderResult> => {
|
|
250
341
|
try {
|
|
251
|
-
const signal
|
|
252
|
-
ctx?.abortController?.signal ||
|
|
253
|
-
ctx?.signal ||
|
|
254
|
-
new AbortController().signal;
|
|
342
|
+
const signal = getLoaderSignal(ctx);
|
|
255
343
|
const baseRequest: Request | undefined =
|
|
256
344
|
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
257
345
|
|
|
258
|
-
const href =
|
|
259
|
-
typeof ctx?.location === 'string'
|
|
260
|
-
? ctx.location
|
|
261
|
-
: ctx?.location?.publicHref ||
|
|
262
|
-
ctx?.location?.href ||
|
|
263
|
-
ctx?.location?.url?.href ||
|
|
264
|
-
'';
|
|
346
|
+
const href = getLoaderHref(ctx);
|
|
265
347
|
|
|
266
|
-
const request = baseRequest
|
|
348
|
+
const request = baseRequest !== undefined
|
|
267
349
|
? new Request(baseRequest, { signal })
|
|
268
350
|
: new Request(href, { signal });
|
|
269
351
|
|
|
270
|
-
const params = mapParamsForModernLoader(ctx
|
|
271
|
-
|
|
272
|
-
const result = await (modernLoader as any)({
|
|
273
|
-
request,
|
|
274
|
-
params,
|
|
275
|
-
context: ctx?.context?.requestContext,
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
if (isResponse(result)) {
|
|
279
|
-
if (isRedirectResponse(result)) {
|
|
280
|
-
const location = result.headers.get('Location') || '/';
|
|
281
|
-
throwTanstackRedirect(location);
|
|
282
|
-
}
|
|
283
|
-
if (result.status === 404) {
|
|
284
|
-
throw notFound();
|
|
285
|
-
}
|
|
286
|
-
}
|
|
352
|
+
const params = mapParamsForModernLoader(getLoaderParams(ctx), opts.hasSplat);
|
|
287
353
|
|
|
288
|
-
return
|
|
354
|
+
return Promise.resolve(
|
|
355
|
+
(modernLoader as any)({
|
|
356
|
+
request,
|
|
357
|
+
params,
|
|
358
|
+
context: ctx?.context?.requestContext,
|
|
359
|
+
}),
|
|
360
|
+
)
|
|
361
|
+
.then((result: LoaderResult) => handleModernLoaderResult(result))
|
|
362
|
+
.catch(handleModernLoaderError);
|
|
289
363
|
} catch (err) {
|
|
290
|
-
|
|
291
|
-
if (isRedirectResponse(err)) {
|
|
292
|
-
const location = err.headers.get('Location') || '/';
|
|
293
|
-
throwTanstackRedirect(location);
|
|
294
|
-
}
|
|
295
|
-
if (err.status === 404) {
|
|
296
|
-
throw notFound();
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
throw err;
|
|
364
|
+
handleModernLoaderError(err);
|
|
300
365
|
}
|
|
301
366
|
};
|
|
302
367
|
}
|
|
@@ -170,16 +170,9 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
170
170
|
webpackChunkName: true
|
|
171
171
|
});
|
|
172
172
|
component = 'string' === ssrMode ? `loadable(${lazyImport})` : `lazy(${lazyImport})`;
|
|
173
|
-
} else
|
|
173
|
+
} else {
|
|
174
174
|
components.push(route._component);
|
|
175
175
|
component = `component_${components.length - 1}`;
|
|
176
|
-
} else {
|
|
177
|
-
lazyImport = createLazyImport({
|
|
178
|
-
componentPath: route._component,
|
|
179
|
-
routeId: route.id,
|
|
180
|
-
eager: true
|
|
181
|
-
});
|
|
182
|
-
component = `lazy(${lazyImport})`;
|
|
183
176
|
}
|
|
184
177
|
} else if (route._component) if (splitRouteChunks) {
|
|
185
178
|
lazyImport = `() => import('${route._component}')`;
|
|
@@ -3,14 +3,15 @@ import { merge } from "@modern-js/runtime-utils/merge";
|
|
|
3
3
|
import { normalizePathname } from "@modern-js/runtime-utils/url";
|
|
4
4
|
import { RouterProvider, createBrowserHistory, createHashHistory, createRouter, useLocation, useMatches, useNavigate, useRouter } from "@tanstack/react-router";
|
|
5
5
|
import { RouterClient } from "@tanstack/react-router/ssr/client";
|
|
6
|
+
import { useContext, useMemo } from "react";
|
|
6
7
|
import { InternalRuntimeContext, getGlobalEnableRsc, getGlobalLayoutApp, getGlobalRoutes } from "../../../core/context/index.mjs";
|
|
7
8
|
import { onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeHydrateRouter } from "../hooks.mjs";
|
|
8
9
|
import { applyRouterRuntimeState } from "../lifecycle.mjs";
|
|
9
10
|
import { createRouteObjectsFromConfig, urlJoin } from "../utils.mjs";
|
|
10
11
|
import { createModernBasepathRewrite } from "./basepathRewrite.mjs";
|
|
12
|
+
import { Link } from "./prefetchLink.mjs";
|
|
11
13
|
import { createRouteTreeFromRouteObjects } from "./routeTree.mjs";
|
|
12
14
|
import { getTanstackRscSerializationAdapters } from "./rsc/client.mjs";
|
|
13
|
-
import * as __rspack_external_react from "react";
|
|
14
15
|
const BLOCKING_SUBSCRIBE_SYMBOL = Symbol.for('@modern-js/plugin-runtime:tanstack-blocking-subscribe');
|
|
15
16
|
const BLOCKING_STATE_SYMBOL = Symbol.for('@modern-js/plugin-runtime:tanstack-blocking-state');
|
|
16
17
|
function normalizeBase(b) {
|
|
@@ -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,
|
|
@@ -104,10 +106,10 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
104
106
|
let cachedRouter = null;
|
|
105
107
|
let cachedRouterBasepath = null;
|
|
106
108
|
const RouterWrapper = ()=>{
|
|
107
|
-
const runtimeContext =
|
|
109
|
+
const runtimeContext = useContext(InternalRuntimeContext);
|
|
108
110
|
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
109
111
|
const _basename = '/' === baseUrl ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
110
|
-
const routeTree =
|
|
112
|
+
const routeTree = useMemo(()=>{
|
|
111
113
|
if (cachedRouteTree) return cachedRouteTree;
|
|
112
114
|
const routeObjects = getRouteObjects();
|
|
113
115
|
if (!routeObjects.length) return null;
|
|
@@ -115,7 +117,7 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
115
117
|
return cachedRouteTree;
|
|
116
118
|
}, []);
|
|
117
119
|
if (!routeTree) return App ? /*#__PURE__*/ jsx(App, {}) : null;
|
|
118
|
-
const router =
|
|
120
|
+
const router = useMemo(()=>{
|
|
119
121
|
const lifecycleContext = {
|
|
120
122
|
framework: 'tanstack',
|
|
121
123
|
phase: 'client-create',
|
|
@@ -180,11 +182,8 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
180
182
|
router,
|
|
181
183
|
runtimeContext: runtimeState
|
|
182
184
|
});
|
|
183
|
-
const RouterContent = hasSSRBootstrap ? /*#__PURE__*/ jsx(
|
|
184
|
-
|
|
185
|
-
children: /*#__PURE__*/ jsx(RouterClient, {
|
|
186
|
-
router: router
|
|
187
|
-
})
|
|
185
|
+
const RouterContent = hasSSRBootstrap ? /*#__PURE__*/ jsx(RouterClient, {
|
|
186
|
+
router: router
|
|
188
187
|
}) : /*#__PURE__*/ jsx(RouterProvider, {
|
|
189
188
|
router: router
|
|
190
189
|
});
|
|
@@ -5,7 +5,7 @@ import { time } from "@modern-js/runtime-utils/time";
|
|
|
5
5
|
import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
|
|
6
6
|
import { RouterProvider, createMemoryHistory, createRouter } from "@tanstack/react-router";
|
|
7
7
|
import { attachRouterServerSsrUtils } from "@tanstack/react-router/ssr/server";
|
|
8
|
-
import {
|
|
8
|
+
import { useContext } from "react";
|
|
9
9
|
import { InternalRuntimeContext, getGlobalEnableRsc, getGlobalLayoutApp, getGlobalRoutes } from "../../../core/context/index.mjs";
|
|
10
10
|
import { applyRouterServerPrepareResult, createRouterServerSnapshot } from "../lifecycle.mjs";
|
|
11
11
|
import { createRouteObjectsFromConfig, urlJoin } from "../utils.mjs";
|
|
@@ -37,13 +37,6 @@ async function preloadMatchedRouteComponents(tanstackRouter) {
|
|
|
37
37
|
]);
|
|
38
38
|
}));
|
|
39
39
|
}
|
|
40
|
-
async function waitForRouterSerialization(tanstackRouter) {
|
|
41
|
-
const serverSsr = tanstackRouter.serverSsr;
|
|
42
|
-
if (!serverSsr || 'function' != typeof serverSsr.onSerializationFinished || serverSsr.isSerializationFinished?.()) return;
|
|
43
|
-
await new Promise((resolve)=>{
|
|
44
|
-
serverSsr.onSerializationFinished?.(resolve);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
40
|
function htmlEscapeAttr(value) {
|
|
48
41
|
return value.replace(/&/g, '&').replace(/"/g, '"');
|
|
49
42
|
}
|
|
@@ -189,7 +182,6 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
189
182
|
await preloadMatchedRouteComponents(serverRouter);
|
|
190
183
|
context.ssrContext?.response.status(tanstackRouter.state.statusCode);
|
|
191
184
|
await serverRouter.serverSsr?.dehydrate?.();
|
|
192
|
-
await waitForRouterSerialization(serverRouter);
|
|
193
185
|
const ssrScriptTags = serverRouter.serverSsr?.takeBufferedScripts?.();
|
|
194
186
|
const hydrationScripts = routerManagedTagsToHtml(ssrScriptTags);
|
|
195
187
|
const matchedRouteIds = getModernRouteIdsFromMatches(serverRouter);
|
|
@@ -227,11 +219,8 @@ const tanstackRouterPlugin = (userConfig = {})=>({
|
|
|
227
219
|
if (!router) return App ? /*#__PURE__*/ jsx(App, {
|
|
228
220
|
...props
|
|
229
221
|
}) : null;
|
|
230
|
-
const routerWrapper = /*#__PURE__*/ jsx(
|
|
231
|
-
|
|
232
|
-
children: /*#__PURE__*/ jsx(RouterProvider, {
|
|
233
|
-
router: router
|
|
234
|
-
})
|
|
222
|
+
const routerWrapper = /*#__PURE__*/ jsx(RouterProvider, {
|
|
223
|
+
router: router
|
|
235
224
|
});
|
|
236
225
|
return App ? /*#__PURE__*/ jsx(App, {
|
|
237
226
|
children: routerWrapper
|
|
@@ -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 {
|
|
@@ -111,7 +139,7 @@ function wrapModernLoader(modernRoute, modernLoader, revalidationState) {
|
|
|
111
139
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
112
140
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
113
141
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
114
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
142
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
115
143
|
signal
|
|
116
144
|
}) : createModernRequest(href, signal);
|
|
117
145
|
const params = mapParamsForModernLoader({
|
|
@@ -174,7 +202,7 @@ function wrapRouteObjectLoader(route, revalidationState) {
|
|
|
174
202
|
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
175
203
|
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
176
204
|
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
177
|
-
const request = baseRequest ? new Request(baseRequest, {
|
|
205
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
178
206
|
signal
|
|
179
207
|
}) : createModernRequest(href, signal);
|
|
180
208
|
const params = mapParamsForRouteObjectLoader({
|
|
@@ -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";
|