@bleedingdev/modern-js-runtime 3.2.0-ultramodern.6 → 3.2.0-ultramodern.61
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 +221 -0
- package/dist/cjs/cli/ssr/index.js +3 -2
- package/dist/cjs/cli/template.server.js +1 -0
- package/dist/cjs/core/plugin/index.js +3 -2
- 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 +6 -7
- package/dist/cjs/core/server/stream/beforeTemplate.worker.js +104 -0
- package/dist/cjs/core/server/stream/createReadableStream.worker.js +2 -1
- package/dist/cjs/core/server/stream/shared.js +1 -0
- package/dist/cjs/core/server/string/index.js +1 -0
- package/dist/cjs/core/server/string/loadable.js +16 -1
- package/dist/cjs/router/cli/code/tanstackTypes.js +20 -6
- package/dist/cjs/router/cli/code/templates.js +1 -8
- 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/boundary-debugger/index.mjs +185 -0
- package/dist/esm/cli/ssr/index.mjs +3 -2
- package/dist/esm/cli/template.server.mjs +1 -0
- package/dist/esm/core/plugin/index.mjs +3 -2
- 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 +6 -7
- package/dist/esm/core/server/stream/beforeTemplate.worker.mjs +60 -0
- package/dist/esm/core/server/stream/createReadableStream.worker.mjs +2 -1
- package/dist/esm/core/server/stream/shared.mjs +1 -0
- package/dist/esm/core/server/string/index.mjs +1 -0
- package/dist/esm/core/server/string/loadable.mjs +16 -1
- package/dist/esm/router/cli/code/tanstackTypes.mjs +20 -6
- package/dist/esm/router/cli/code/templates.mjs +1 -8
- 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/boundary-debugger/index.mjs +186 -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/plugin/index.mjs +3 -2
- 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 +6 -7
- package/dist/esm-node/core/server/stream/beforeTemplate.worker.mjs +61 -0
- package/dist/esm-node/core/server/stream/createReadableStream.worker.mjs +2 -1
- package/dist/esm-node/core/server/stream/shared.mjs +1 -0
- package/dist/esm-node/core/server/string/index.mjs +1 -0
- package/dist/esm-node/core/server/string/loadable.mjs +16 -1
- package/dist/esm-node/router/cli/code/tanstackTypes.mjs +20 -6
- package/dist/esm-node/router/cli/code/templates.mjs +1 -8
- 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/boundary-debugger/index.d.ts +25 -0
- package/dist/types/cache/index.d.ts +1 -0
- package/dist/types/cli/alias.d.ts +7 -0
- package/dist/types/cli/code.d.ts +3 -0
- package/dist/types/cli/constants.d.ts +9 -0
- package/dist/types/cli/entry.d.ts +2 -0
- package/dist/types/cli/index.d.ts +11 -0
- package/dist/types/cli/ssr/index.d.ts +6 -0
- package/dist/types/cli/ssr/loadable-bundler-plugin.d.ts +31 -0
- package/dist/types/cli/ssr/mode.d.ts +15 -0
- package/dist/types/cli/template.d.ts +50 -0
- package/dist/types/cli/template.server.d.ts +20 -0
- package/dist/types/common.d.ts +8 -0
- package/dist/types/core/browser/hydrate.d.ts +5 -0
- package/dist/types/core/browser/index.d.ts +9 -0
- package/dist/types/core/browser/withCallback.d.ts +5 -0
- package/dist/types/core/compat/hooks.d.ts +4 -0
- package/dist/types/core/compat/index.d.ts +2 -0
- package/dist/types/core/compat/requestContext.d.ts +5 -0
- package/dist/types/core/config.d.ts +6 -0
- package/dist/types/core/constants.d.ts +6 -0
- package/dist/types/core/context/index.d.ts +50 -0
- package/dist/types/core/context/monitors/default.d.ts +2 -0
- package/dist/types/core/context/monitors/index.d.ts +1 -0
- package/dist/types/core/context/monitors/index.server.d.ts +2 -0
- package/dist/types/core/context/request/index.d.ts +1 -0
- package/dist/types/core/context/request/index.server.d.ts +1 -0
- package/dist/types/core/context/response/index.d.ts +4 -0
- package/dist/types/core/context/response/index.server.d.ts +4 -0
- package/dist/types/core/context/runtime.d.ts +42 -0
- package/dist/types/core/context/serverPayload/index.d.ts +4 -0
- package/dist/types/core/context/serverPayload/index.server.d.ts +31 -0
- package/dist/types/core/index.d.ts +5 -0
- package/dist/types/core/plugin/index.d.ts +5 -0
- package/dist/types/core/plugin/types.d.ts +10 -0
- package/dist/types/core/react/index.d.ts +2 -0
- package/dist/types/core/react/wrapper.d.ts +3 -0
- package/dist/types/core/server/constants.d.ts +4 -0
- package/dist/types/core/server/helmet.d.ts +3 -0
- package/dist/types/core/server/index.d.ts +4 -0
- package/dist/types/core/server/react/index.d.ts +2 -0
- package/dist/types/core/server/react/no-ssr-cache/index.d.ts +2 -0
- package/dist/types/core/server/react/nossr/index.d.ts +4 -0
- package/dist/types/core/server/requestHandler.d.ts +13 -0
- package/dist/types/core/server/server.d.ts +4 -0
- package/dist/types/core/server/shared.d.ts +8 -0
- package/dist/types/core/server/stream/afterTemplate.d.ts +13 -0
- package/dist/types/core/server/stream/beforeTemplate.d.ts +9 -0
- package/dist/types/core/server/stream/beforeTemplate.worker.d.ts +9 -0
- package/dist/types/core/server/stream/createReadableStream.d.ts +2 -0
- package/dist/types/core/server/stream/createReadableStream.worker.d.ts +2 -0
- package/dist/types/core/server/stream/deferredScript.d.ts +15 -0
- package/dist/types/core/server/stream/index.d.ts +1 -0
- package/dist/types/core/server/stream/shared.d.ts +40 -0
- package/dist/types/core/server/stream/template.d.ts +9 -0
- package/dist/types/core/server/string/index.d.ts +2 -0
- package/dist/types/core/server/string/loadable.d.ts +39 -0
- package/dist/types/core/server/string/ssrData.d.ts +20 -0
- package/dist/types/core/server/string/types.d.ts +12 -0
- package/dist/types/core/server/tracer.d.ts +17 -0
- package/dist/types/core/server/utils.d.ts +19 -0
- package/dist/types/core/types.d.ts +49 -0
- package/dist/types/document/Body.d.ts +2 -0
- package/dist/types/document/Comment.d.ts +5 -0
- package/dist/types/document/DocumentContext.d.ts +13 -0
- package/dist/types/document/DocumentStructureContext.d.ts +12 -0
- package/dist/types/document/Head.d.ts +5 -0
- package/dist/types/document/Html.d.ts +4 -0
- package/dist/types/document/Links.d.ts +2 -0
- package/dist/types/document/Root.d.ts +7 -0
- package/dist/types/document/Script.d.ts +4 -0
- package/dist/types/document/Scripts.d.ts +2 -0
- package/dist/types/document/Style.d.ts +5 -0
- package/dist/types/document/Title.d.ts +1 -0
- package/dist/types/document/cli/index.d.ts +5 -0
- package/dist/types/document/constants.d.ts +25 -0
- package/dist/types/document/index.d.ts +12 -0
- package/dist/types/exports/config-routes.d.ts +9 -0
- package/dist/types/exports/head.d.ts +4 -0
- package/dist/types/exports/loadable.d.ts +3 -0
- package/dist/types/exports/tanstack-router.d.ts +5 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/internal.d.ts +2 -0
- package/dist/types/react-server.d.ts +3 -0
- package/dist/types/router/cli/code/getClientRoutes/getRoutes.d.ts +8 -0
- package/dist/types/router/cli/code/getClientRoutes/index.d.ts +1 -0
- package/dist/types/router/cli/code/getClientRoutes/utils.d.ts +4 -0
- package/dist/types/router/cli/code/index.d.ts +12 -0
- package/dist/types/router/cli/code/inspect.d.ts +22 -0
- package/dist/types/router/cli/code/makeLegalIdentifier.d.ts +1 -0
- package/dist/types/router/cli/code/nestedRoutes.d.ts +13 -0
- package/dist/types/router/cli/code/tanstackTypes.d.ts +10 -0
- package/dist/types/router/cli/code/templates.d.ts +28 -0
- package/dist/types/router/cli/code/utils.d.ts +12 -0
- package/dist/types/router/cli/config-routes/converter.d.ts +15 -0
- package/dist/types/router/cli/config-routes/parseRouteConfig.d.ts +32 -0
- package/dist/types/router/cli/constants.d.ts +31 -0
- package/dist/types/router/cli/entry.d.ts +18 -0
- package/dist/types/router/cli/handler.d.ts +28 -0
- package/dist/types/router/cli/index.d.ts +5 -0
- package/dist/types/router/index.d.ts +1 -0
- package/dist/types/router/internal.d.ts +2 -0
- package/dist/types/router/runtime/CSSLinks.d.ts +9 -0
- package/dist/types/router/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types/router/runtime/DeferredDataScripts.d.ts +2 -0
- package/dist/types/router/runtime/DeferredDataScripts.node.d.ts +11 -0
- package/dist/types/router/runtime/PrefetchLink.d.ts +27 -0
- package/dist/types/router/runtime/constants.d.ts +146 -0
- package/dist/types/router/runtime/hooks.d.ts +18 -0
- package/dist/types/router/runtime/index.d.ts +7 -0
- package/dist/types/router/runtime/internal.d.ts +11 -0
- package/dist/types/router/runtime/lifecycle.d.ts +25 -0
- package/dist/types/router/runtime/plugin.d.ts +9 -0
- package/dist/types/router/runtime/plugin.node.d.ts +7 -0
- package/dist/types/router/runtime/routerHelper.d.ts +5 -0
- package/dist/types/router/runtime/rsc-router.d.ts +20 -0
- package/dist/types/router/runtime/rsc.d.ts +1 -0
- package/dist/types/router/runtime/server.d.ts +1 -0
- package/dist/types/router/runtime/tanstack/basepathRewrite.d.ts +8 -0
- package/dist/types/router/runtime/tanstack/dataMutation.d.ts +29 -0
- package/dist/types/router/runtime/tanstack/plugin.d.ts +6 -0
- package/dist/types/router/runtime/tanstack/plugin.node.d.ts +6 -0
- package/dist/types/router/runtime/tanstack/prefetchLink.d.ts +11 -0
- package/dist/types/router/runtime/tanstack/routeTree.d.ts +8 -0
- package/dist/types/router/runtime/tanstack/rsc/ClientSlot.d.ts +5 -0
- package/dist/types/router/runtime/tanstack/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types/router/runtime/tanstack/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types/router/runtime/tanstack/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types/router/runtime/tanstack/rsc/SlotContext.d.ts +11 -0
- package/dist/types/router/runtime/tanstack/rsc/client.d.ts +11 -0
- package/dist/types/router/runtime/tanstack/rsc/createRscProxy.d.ts +7 -0
- package/dist/types/router/runtime/tanstack/rsc/index.d.ts +2 -0
- package/dist/types/router/runtime/tanstack/rsc/server.d.ts +14 -0
- package/dist/types/router/runtime/tanstack/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types/router/runtime/tanstack/rsc/symbols.d.ts +46 -0
- package/dist/types/router/runtime/types.d.ts +119 -0
- package/dist/types/router/runtime/utils.d.ts +48 -0
- package/dist/types/router/runtime/withRouter.d.ts +10 -0
- package/dist/types/rsc/client.d.ts +2 -0
- package/dist/types/rsc/server.d.ts +1 -0
- package/dist/types/rsc/server.worker.d.ts +1 -0
- package/package.json +22 -15
|
@@ -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}')`;
|
|
@@ -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";
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useMemo, useState } from "react";
|
|
4
|
+
const defaultStorageKey = 'modernjs:boundary-debugger:enabled';
|
|
5
|
+
const defaultLabels = {
|
|
6
|
+
cs: {
|
|
7
|
+
toggle: 'zobrazit hranice verticalů'
|
|
8
|
+
},
|
|
9
|
+
en: {
|
|
10
|
+
toggle: 'show vertical boundaries'
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const palette = [
|
|
14
|
+
'#ff5a5f',
|
|
15
|
+
'#30e27a',
|
|
16
|
+
'#f6cf45',
|
|
17
|
+
'#7c8cff',
|
|
18
|
+
'#29b6f6'
|
|
19
|
+
];
|
|
20
|
+
const readEnabled = (storageKey, fallback)=>{
|
|
21
|
+
if ("u" < typeof window) return fallback;
|
|
22
|
+
const stored = window.localStorage.getItem(storageKey);
|
|
23
|
+
return null === stored ? fallback : 'true' === stored;
|
|
24
|
+
};
|
|
25
|
+
const detectLanguage = ()=>{
|
|
26
|
+
if ("u" < typeof document) return 'en';
|
|
27
|
+
const htmlLanguage = document.documentElement.lang;
|
|
28
|
+
if (htmlLanguage) return htmlLanguage.split('-')[0] || 'en';
|
|
29
|
+
return window.location.pathname.split('/').filter(Boolean)[0] || 'en';
|
|
30
|
+
};
|
|
31
|
+
function BoundaryDebugger({ enabledByDefault = false, labels = defaultLabels, metadata, storageKey = defaultStorageKey }) {
|
|
32
|
+
const [mounted, setMounted] = useState(false);
|
|
33
|
+
const [enabled, setEnabled] = useState(false);
|
|
34
|
+
const [boxes, setBoxes] = useState([]);
|
|
35
|
+
const boundaries = useMemo(()=>new Map(metadata.boundaries.map((entry, index)=>[
|
|
36
|
+
entry.mfName,
|
|
37
|
+
{
|
|
38
|
+
...entry,
|
|
39
|
+
color: entry.color ?? palette[index % palette.length],
|
|
40
|
+
label: entry.label ?? entry.appId
|
|
41
|
+
}
|
|
42
|
+
])), [
|
|
43
|
+
metadata
|
|
44
|
+
]);
|
|
45
|
+
const language = mounted ? detectLanguage() : 'en';
|
|
46
|
+
const toggleLabel = labels[language]?.toggle ?? labels.en?.toggle ?? defaultLabels.en?.toggle ?? 'show vertical boundaries';
|
|
47
|
+
useEffect(()=>{
|
|
48
|
+
setMounted(true);
|
|
49
|
+
setEnabled(readEnabled(storageKey, enabledByDefault));
|
|
50
|
+
}, [
|
|
51
|
+
enabledByDefault,
|
|
52
|
+
storageKey
|
|
53
|
+
]);
|
|
54
|
+
useEffect(()=>{
|
|
55
|
+
if (!mounted) return;
|
|
56
|
+
window.localStorage.setItem(storageKey, String(enabled));
|
|
57
|
+
}, [
|
|
58
|
+
enabled,
|
|
59
|
+
mounted,
|
|
60
|
+
storageKey
|
|
61
|
+
]);
|
|
62
|
+
useEffect(()=>{
|
|
63
|
+
if (!enabled) return void setBoxes([]);
|
|
64
|
+
const readBoxes = ()=>{
|
|
65
|
+
const nextBoxes = Array.from(document.querySelectorAll('[data-modern-boundary-id]')).map((element, index)=>{
|
|
66
|
+
const boundaryId = element.dataset.modernBoundaryId;
|
|
67
|
+
if (!boundaryId) return;
|
|
68
|
+
const rect = element.getBoundingClientRect();
|
|
69
|
+
if (rect.width <= 0 || rect.height <= 0) return;
|
|
70
|
+
const boundary = boundaries.get(boundaryId);
|
|
71
|
+
const color = boundary?.color ?? palette[index % palette.length];
|
|
72
|
+
return {
|
|
73
|
+
color,
|
|
74
|
+
height: rect.height,
|
|
75
|
+
id: `${boundaryId}-${index}`,
|
|
76
|
+
label: boundary?.label ?? boundaryId,
|
|
77
|
+
left: rect.left,
|
|
78
|
+
top: rect.top,
|
|
79
|
+
width: rect.width
|
|
80
|
+
};
|
|
81
|
+
}).filter((box)=>void 0 !== box);
|
|
82
|
+
setBoxes(nextBoxes);
|
|
83
|
+
};
|
|
84
|
+
readBoxes();
|
|
85
|
+
const resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(readBoxes);
|
|
86
|
+
for (const element of document.querySelectorAll('[data-modern-boundary-id]'))resizeObserver?.observe(element);
|
|
87
|
+
const mutationObserver = new MutationObserver(readBoxes);
|
|
88
|
+
mutationObserver.observe(document.body, {
|
|
89
|
+
childList: true,
|
|
90
|
+
subtree: true
|
|
91
|
+
});
|
|
92
|
+
window.addEventListener('resize', readBoxes);
|
|
93
|
+
window.addEventListener('scroll', readBoxes, true);
|
|
94
|
+
return ()=>{
|
|
95
|
+
mutationObserver.disconnect();
|
|
96
|
+
resizeObserver?.disconnect();
|
|
97
|
+
window.removeEventListener('resize', readBoxes);
|
|
98
|
+
window.removeEventListener('scroll', readBoxes, true);
|
|
99
|
+
};
|
|
100
|
+
}, [
|
|
101
|
+
boundaries,
|
|
102
|
+
enabled
|
|
103
|
+
]);
|
|
104
|
+
if (!mounted) return null;
|
|
105
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
106
|
+
children: [
|
|
107
|
+
/*#__PURE__*/ jsxs("label", {
|
|
108
|
+
style: {
|
|
109
|
+
alignItems: 'center',
|
|
110
|
+
background: 'rgba(255, 255, 255, 0.96)',
|
|
111
|
+
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
112
|
+
borderRadius: 12,
|
|
113
|
+
bottom: 20,
|
|
114
|
+
boxShadow: '0 16px 40px rgba(0, 0, 0, 0.16)',
|
|
115
|
+
color: '#111827',
|
|
116
|
+
display: 'flex',
|
|
117
|
+
font: '600 14px/1.2 system-ui, sans-serif',
|
|
118
|
+
gap: 8,
|
|
119
|
+
left: 20,
|
|
120
|
+
padding: '12px 14px',
|
|
121
|
+
position: 'fixed',
|
|
122
|
+
zIndex: 2147483000
|
|
123
|
+
},
|
|
124
|
+
children: [
|
|
125
|
+
/*#__PURE__*/ jsx("input", {
|
|
126
|
+
checked: enabled,
|
|
127
|
+
onChange: (event)=>setEnabled(event.currentTarget.checked),
|
|
128
|
+
type: "checkbox"
|
|
129
|
+
}),
|
|
130
|
+
/*#__PURE__*/ jsx("span", {
|
|
131
|
+
children: toggleLabel
|
|
132
|
+
})
|
|
133
|
+
]
|
|
134
|
+
}),
|
|
135
|
+
enabled ? /*#__PURE__*/ jsx("div", {
|
|
136
|
+
"aria-hidden": "true",
|
|
137
|
+
children: boxes.map((box)=>/*#__PURE__*/ jsx("div", {
|
|
138
|
+
style: {
|
|
139
|
+
border: `2px solid ${box.color}`,
|
|
140
|
+
borderRadius: 8,
|
|
141
|
+
boxShadow: `0 0 0 1px rgba(255,255,255,.72), 0 6px 20px color-mix(in srgb, ${box.color} 20%, transparent)`,
|
|
142
|
+
height: box.height,
|
|
143
|
+
left: box.left,
|
|
144
|
+
pointerEvents: 'none',
|
|
145
|
+
position: 'fixed',
|
|
146
|
+
top: box.top,
|
|
147
|
+
width: box.width,
|
|
148
|
+
zIndex: 2147482999
|
|
149
|
+
},
|
|
150
|
+
children: /*#__PURE__*/ jsx("span", {
|
|
151
|
+
style: {
|
|
152
|
+
background: box.color,
|
|
153
|
+
borderRadius: 999,
|
|
154
|
+
color: '#111827',
|
|
155
|
+
font: '800 11px/1 system-ui, sans-serif',
|
|
156
|
+
padding: '5px 8px',
|
|
157
|
+
position: 'absolute',
|
|
158
|
+
right: 4,
|
|
159
|
+
top: 4,
|
|
160
|
+
whiteSpace: 'nowrap'
|
|
161
|
+
},
|
|
162
|
+
children: box.label
|
|
163
|
+
})
|
|
164
|
+
}, box.id))
|
|
165
|
+
}) : null
|
|
166
|
+
]
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const ultramodernBoundaryDebuggerPlugin = (options)=>({
|
|
170
|
+
name: '@modern-js/runtime/boundary-debugger',
|
|
171
|
+
setup: (api)=>{
|
|
172
|
+
api.wrapRoot((App)=>(props)=>/*#__PURE__*/ jsxs(Fragment, {
|
|
173
|
+
children: [
|
|
174
|
+
/*#__PURE__*/ jsx(App, {
|
|
175
|
+
...props
|
|
176
|
+
}),
|
|
177
|
+
/*#__PURE__*/ jsx(BoundaryDebugger, {
|
|
178
|
+
...options
|
|
179
|
+
})
|
|
180
|
+
]
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
const boundary_debugger = ultramodernBoundaryDebuggerPlugin;
|
|
185
|
+
export default boundary_debugger;
|
|
186
|
+
export { ultramodernBoundaryDebuggerPlugin };
|
|
@@ -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, {
|
|
@@ -17,8 +17,9 @@ function registerPlugin(internalPlugins, runtimeConfig) {
|
|
|
17
17
|
config: runtimeConfig || {},
|
|
18
18
|
handleSetupResult: handleSetupResult
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const internalRuntimeContext = runtimeContext;
|
|
21
|
+
setGlobalInternalRuntimeContext(internalRuntimeContext);
|
|
22
|
+
return internalRuntimeContext;
|
|
22
23
|
}
|
|
23
24
|
function mergeConfig(config, ...otherConfig) {
|
|
24
25
|
return merge({}, config, ...otherConfig);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
3
|
-
import { getRouterHydrationScripts } from "../../../router/runtime/lifecycle.mjs";
|
|
3
|
+
import { getRouterHydrationScripts, getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
4
4
|
import { SSR_DATA_JSON_ID } from "../../constants.mjs";
|
|
5
5
|
import { SSR_DATA_PLACEHOLDER } from "../constants.mjs";
|
|
6
6
|
import { buildHtml } from "../shared.mjs";
|
|
@@ -23,12 +23,15 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
23
23
|
if (!routeManifest) return template;
|
|
24
24
|
const { routeAssets } = routeManifest;
|
|
25
25
|
if (!routeAssets) return template;
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
|
|
27
|
+
const assetEntries = [
|
|
28
|
+
...matchedRouteIds.map((routeId)=>routeAssets[routeId]),
|
|
29
|
+
routeAssets[`async-${entryName}`]
|
|
30
|
+
].filter(Boolean);
|
|
31
|
+
const jsAssets = Array.from(new Set(assetEntries.flatMap((entry)=>(entry.assets ?? []).filter((asset)=>asset.endsWith('.js')))));
|
|
32
|
+
const nonceAttr = nonce ? ` nonce="${nonce}"` : '';
|
|
33
|
+
const jsChunkStr = jsAssets.filter((asset)=>!template.includes(asset)).map((asset)=>`<script src=${asset}${nonceAttr}></script>`).join(' ');
|
|
34
|
+
if (jsChunkStr) return safeReplace(template, '<!--<?- chunksMap.js ?>-->', jsChunkStr);
|
|
32
35
|
return template;
|
|
33
36
|
}
|
|
34
37
|
return buildHtml(afterAppTemplate, callbacks);
|
|
@@ -36,28 +36,27 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
|
36
36
|
const { routeManifest, routerContext, routes } = runtimeContext;
|
|
37
37
|
if (!routeManifest) return '';
|
|
38
38
|
const { routeAssets } = routeManifest;
|
|
39
|
-
let matchedRouteManifests;
|
|
39
|
+
let matchedRouteManifests = [];
|
|
40
40
|
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
|
|
41
41
|
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
42
|
-
else {
|
|
43
|
-
if (!routerContext || !routes) return '';
|
|
42
|
+
else if (routerContext && routes) {
|
|
44
43
|
const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
|
|
45
44
|
matchedRouteManifests = matches?.map((match, index)=>{
|
|
46
45
|
if (!index) return;
|
|
47
46
|
const routeId = match.route.id;
|
|
48
47
|
if (routeId) return routeAssets[routeId];
|
|
49
|
-
}).filter(Boolean);
|
|
48
|
+
}).filter(Boolean) ?? [];
|
|
50
49
|
}
|
|
51
50
|
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
52
|
-
if (asyncEntry) matchedRouteManifests
|
|
53
|
-
const cssChunks = matchedRouteManifests
|
|
51
|
+
if (asyncEntry) matchedRouteManifests.push(asyncEntry);
|
|
52
|
+
const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
54
53
|
const { referenceCssAssets = [] } = routeManifest;
|
|
55
54
|
const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
|
|
56
55
|
return [
|
|
57
56
|
...chunks,
|
|
58
57
|
..._cssChunks
|
|
59
58
|
];
|
|
60
|
-
}, [])
|
|
59
|
+
}, []);
|
|
61
60
|
const { inlineStyles } = config;
|
|
62
61
|
const styles = await Promise.all(cssChunks.map(async (chunk)=>{
|
|
63
62
|
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
@@ -0,0 +1,61 @@
|
|
|
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 if (routerContext && routes) {
|
|
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.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 };
|
|
@@ -9,7 +9,7 @@ import { getTemplates } from "./template.mjs";
|
|
|
9
9
|
const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
10
10
|
let shellChunkStatus = ShellChunkStatus.START;
|
|
11
11
|
const chunkVec = [];
|
|
12
|
-
const { htmlTemplate, runtimeContext, config, ssrConfig, entryName, rscRoot } = options;
|
|
12
|
+
const { htmlTemplate, runtimeContext, config, ssrConfig, entryName, rscManifest, rscRoot } = options;
|
|
13
13
|
const { shellBefore, shellAfter } = await getTemplates(htmlTemplate, {
|
|
14
14
|
renderLevel: RenderLevel.SERVER_RENDER,
|
|
15
15
|
runtimeContext,
|
|
@@ -22,6 +22,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
22
22
|
const readableOriginal = await renderSSRStream(rootElement, {
|
|
23
23
|
request,
|
|
24
24
|
nonce: config.nonce,
|
|
25
|
+
rscManifest,
|
|
25
26
|
rscRoot: rscRoot,
|
|
26
27
|
routes: runtimeContext.routes,
|
|
27
28
|
onError (error) {
|
|
@@ -87,6 +87,7 @@ function createRenderStreaming(createReadableStreamPromise) {
|
|
|
87
87
|
rscClientManifest: options.rscClientManifest,
|
|
88
88
|
rscSSRManifest: options.rscSSRManifest,
|
|
89
89
|
rscServerManifest: options.rscServerManifest,
|
|
90
|
+
rscManifest: options.rscManifest,
|
|
90
91
|
rscRoot: options.rscRoot,
|
|
91
92
|
onShellReady () {
|
|
92
93
|
const cost = end();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { ChunkExtractor } from "@loadable/server";
|
|
3
|
+
import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
3
4
|
import { attributesToString, checkIsNode } from "../utils.mjs";
|
|
4
5
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
5
6
|
import { dirname as __rspack_dirname } from "node:path";
|
|
@@ -25,6 +26,20 @@ class LoadableCollector {
|
|
|
25
26
|
const { routeManifest, entryName } = this.options;
|
|
26
27
|
return routeManifest?.routeAssets?.[entryName]?.assets;
|
|
27
28
|
}
|
|
29
|
+
getMatchedRouteChunks() {
|
|
30
|
+
const { routeManifest, runtimeContext } = this.options;
|
|
31
|
+
const routeAssets = routeManifest?.routeAssets;
|
|
32
|
+
if (!routeAssets) return [];
|
|
33
|
+
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
|
|
34
|
+
return matchedRouteIds.flatMap((routeId)=>{
|
|
35
|
+
const routeAsset = routeAssets[routeId];
|
|
36
|
+
return (routeAsset?.assets ?? []).map((asset)=>({
|
|
37
|
+
filename: asset.replace(/^\//, ''),
|
|
38
|
+
path: asset,
|
|
39
|
+
url: asset
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
28
43
|
collect(comopnent) {
|
|
29
44
|
const { stats, entryName } = this.options;
|
|
30
45
|
if (!stats) return comopnent;
|
|
@@ -46,7 +61,7 @@ class LoadableCollector {
|
|
|
46
61
|
`async-${entryName}`
|
|
47
62
|
]));
|
|
48
63
|
} catch (e) {}
|
|
49
|
-
const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
|
|
64
|
+
const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks)).concat(this.getMatchedRouteChunks());
|
|
50
65
|
const scriptChunks = generateChunks(chunks, 'js');
|
|
51
66
|
const styleChunks = generateChunks(chunks, 'css');
|
|
52
67
|
this.emitLoadableScripts(extractor);
|
|
@@ -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
|
};
|
|
@@ -224,7 +234,11 @@ function createRouteStaticData(opts: {
|
|
|
224
234
|
modernRouteAction?: unknown;
|
|
225
235
|
modernRouteLoader?: unknown;
|
|
226
236
|
}) {
|
|
227
|
-
const staticData:
|
|
237
|
+
const staticData: {
|
|
238
|
+
modernRouteId?: string;
|
|
239
|
+
modernRouteAction?: unknown;
|
|
240
|
+
modernRouteLoader?: unknown;
|
|
241
|
+
} = {};
|
|
228
242
|
|
|
229
243
|
if (opts.modernRouteId) {
|
|
230
244
|
staticData.modernRouteId = opts.modernRouteId;
|
|
@@ -238,7 +252,7 @@ function createRouteStaticData(opts: {
|
|
|
238
252
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
239
253
|
}
|
|
240
254
|
|
|
241
|
-
return
|
|
255
|
+
return staticData;
|
|
242
256
|
}
|
|
243
257
|
|
|
244
258
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|
|
@@ -172,16 +172,9 @@ const fileSystemRoutes = async ({ metaName, routes, ssrMode, nestedRoutesEntry,
|
|
|
172
172
|
webpackChunkName: true
|
|
173
173
|
});
|
|
174
174
|
component = 'string' === ssrMode ? `loadable(${lazyImport})` : `lazy(${lazyImport})`;
|
|
175
|
-
} else
|
|
175
|
+
} else {
|
|
176
176
|
components.push(route._component);
|
|
177
177
|
component = `component_${components.length - 1}`;
|
|
178
|
-
} else {
|
|
179
|
-
lazyImport = createLazyImport({
|
|
180
|
-
componentPath: route._component,
|
|
181
|
-
routeId: route.id,
|
|
182
|
-
eager: true
|
|
183
|
-
});
|
|
184
|
-
component = `lazy(${lazyImport})`;
|
|
185
178
|
}
|
|
186
179
|
} else if (route._component) if (splitRouteChunks) {
|
|
187
180
|
lazyImport = `() => import('${route._component}')`;
|