@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
|
@@ -29,6 +29,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
29
29
|
getModernRouteIdsFromMatches: ()=>getModernRouteIdsFromMatches
|
|
30
30
|
});
|
|
31
31
|
const react_router_namespaceObject = require("@tanstack/react-router");
|
|
32
|
+
const external_react_namespaceObject = require("react");
|
|
32
33
|
const external_DefaultNotFound_js_namespaceObject = require("../DefaultNotFound.js");
|
|
33
34
|
function createTanstackRoute(options) {
|
|
34
35
|
return (0, react_router_namespaceObject.createRoute)(options);
|
|
@@ -73,6 +74,33 @@ function isModernDeferredData(value) {
|
|
|
73
74
|
function normalizeModernLoaderResult(result) {
|
|
74
75
|
return isModernDeferredData(result) ? result.data : result;
|
|
75
76
|
}
|
|
77
|
+
function pickRouteModuleComponent(routeModule) {
|
|
78
|
+
if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
|
|
79
|
+
if (!routeModule || 'object' != typeof routeModule) return;
|
|
80
|
+
const module = routeModule;
|
|
81
|
+
const component = module.default || module.Component;
|
|
82
|
+
if ('function' == typeof component || component && 'object' == typeof component && '$$typeof' in component) return component;
|
|
83
|
+
}
|
|
84
|
+
function createServerLazyImportComponent(lazyImport, fallbackComponent) {
|
|
85
|
+
if ("u" > typeof document) return fallbackComponent;
|
|
86
|
+
let resolvedComponent;
|
|
87
|
+
let pendingLoad;
|
|
88
|
+
const load = async ()=>{
|
|
89
|
+
if (resolvedComponent) return resolvedComponent;
|
|
90
|
+
const routeModule = await lazyImport();
|
|
91
|
+
const component = pickRouteModuleComponent(routeModule);
|
|
92
|
+
if (component) resolvedComponent = component;
|
|
93
|
+
return resolvedComponent;
|
|
94
|
+
};
|
|
95
|
+
const Component = (props)=>{
|
|
96
|
+
if (resolvedComponent) return (0, external_react_namespaceObject.createElement)(resolvedComponent, props);
|
|
97
|
+
pendingLoad ||= load();
|
|
98
|
+
throw pendingLoad;
|
|
99
|
+
};
|
|
100
|
+
Component.load = load;
|
|
101
|
+
Component.preload = load;
|
|
102
|
+
return Component;
|
|
103
|
+
}
|
|
76
104
|
function throwTanstackRedirect(location) {
|
|
77
105
|
const target = location || '/';
|
|
78
106
|
try {
|
|
@@ -239,10 +267,18 @@ function wrapRouteObjectLoader(route, revalidationState) {
|
|
|
239
267
|
}
|
|
240
268
|
function toRouteComponent(routeObject) {
|
|
241
269
|
const route = routeObject;
|
|
270
|
+
const lazyImport = 'function' == typeof route.lazyImport ? route.lazyImport : void 0;
|
|
271
|
+
const fallbackComponent = route.Component ? route.Component : route.element ? ()=>route.element : void 0;
|
|
272
|
+
if (lazyImport && fallbackComponent) return createServerLazyImportComponent(lazyImport, fallbackComponent);
|
|
242
273
|
if (route.Component) return route.Component;
|
|
243
274
|
const element = route.element;
|
|
244
275
|
if (element) return ()=>element;
|
|
245
276
|
}
|
|
277
|
+
function toModernRouteComponent(route) {
|
|
278
|
+
const component = route.component || void 0;
|
|
279
|
+
if ('function' == typeof route.lazyImport && component) return createServerLazyImportComponent(route.lazyImport, component);
|
|
280
|
+
return component;
|
|
281
|
+
}
|
|
246
282
|
function toErrorComponent(routeObject) {
|
|
247
283
|
const route = routeObject;
|
|
248
284
|
if (route.ErrorBoundary) return route.ErrorBoundary;
|
|
@@ -322,7 +358,7 @@ function createRouteFromModernRoute(opts) {
|
|
|
322
358
|
const stableFallbackId = modernId || route._component || route.filename || route.data || ('function' == typeof route.loader ? route.id : void 0);
|
|
323
359
|
const pendingComponent = route.loading || route.pendingComponent;
|
|
324
360
|
const errorComponent = route.error || route.errorComponent;
|
|
325
|
-
const component = route
|
|
361
|
+
const component = toModernRouteComponent(route);
|
|
326
362
|
const modernLoader = route.loader;
|
|
327
363
|
const modernAction = route.action;
|
|
328
364
|
const modernShouldRevalidate = route.shouldRevalidate;
|
|
@@ -368,7 +404,7 @@ function createRouteFromModernRoute(opts) {
|
|
|
368
404
|
}
|
|
369
405
|
function createRouteTreeFromModernRoutes(routes) {
|
|
370
406
|
const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
|
|
371
|
-
const rootComponent = rootModern
|
|
407
|
+
const rootComponent = rootModern ? toModernRouteComponent(rootModern) : void 0;
|
|
372
408
|
const pendingComponent = rootModern?.loading;
|
|
373
409
|
const errorComponent = rootModern?.error;
|
|
374
410
|
const rootLoader = rootModern?.loader;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"@modern-js/render/rsc-worker" (module) {
|
|
4
|
+
module.exports = require("@modern-js/render/rsc-worker");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.n = (module)=>{
|
|
19
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
20
|
+
__webpack_require__.d(getter, {
|
|
21
|
+
a: getter
|
|
22
|
+
});
|
|
23
|
+
return getter;
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
28
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: definition[key]
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
(()=>{
|
|
35
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
36
|
+
})();
|
|
37
|
+
(()=>{
|
|
38
|
+
__webpack_require__.r = (exports1)=>{
|
|
39
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
40
|
+
value: 'Module'
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
43
|
+
value: true
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __webpack_exports__ = {};
|
|
48
|
+
(()=>{
|
|
49
|
+
__webpack_require__.r(__webpack_exports__);
|
|
50
|
+
var _modern_js_render_rsc_worker__rspack_import_0 = __webpack_require__("@modern-js/render/rsc-worker");
|
|
51
|
+
var __rspack_reexport = {};
|
|
52
|
+
for(const __rspack_import_key in _modern_js_render_rsc_worker__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_modern_js_render_rsc_worker__rspack_import_0[__rspack_import_key];
|
|
53
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
54
|
+
})();
|
|
55
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
56
|
+
Object.defineProperty(exports, '__esModule', {
|
|
57
|
+
value: true
|
|
58
|
+
});
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
|
+
const defaultStorageKey = 'modernjs:boundary-debugger:enabled';
|
|
4
|
+
const defaultLabels = {
|
|
5
|
+
cs: {
|
|
6
|
+
toggle: 'zobrazit hranice verticalů'
|
|
7
|
+
},
|
|
8
|
+
en: {
|
|
9
|
+
toggle: 'show vertical boundaries'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const palette = [
|
|
13
|
+
'#ff5a5f',
|
|
14
|
+
'#30e27a',
|
|
15
|
+
'#f6cf45',
|
|
16
|
+
'#7c8cff',
|
|
17
|
+
'#29b6f6'
|
|
18
|
+
];
|
|
19
|
+
const readEnabled = (storageKey, fallback)=>{
|
|
20
|
+
if ("u" < typeof window) return fallback;
|
|
21
|
+
const stored = window.localStorage.getItem(storageKey);
|
|
22
|
+
return null === stored ? fallback : 'true' === stored;
|
|
23
|
+
};
|
|
24
|
+
const detectLanguage = ()=>{
|
|
25
|
+
if ("u" < typeof document) return 'en';
|
|
26
|
+
const htmlLanguage = document.documentElement.lang;
|
|
27
|
+
if (htmlLanguage) return htmlLanguage.split('-')[0] || 'en';
|
|
28
|
+
return window.location.pathname.split('/').filter(Boolean)[0] || 'en';
|
|
29
|
+
};
|
|
30
|
+
function BoundaryDebugger({ enabledByDefault = false, labels = defaultLabels, metadata, storageKey = defaultStorageKey }) {
|
|
31
|
+
const [mounted, setMounted] = useState(false);
|
|
32
|
+
const [enabled, setEnabled] = useState(false);
|
|
33
|
+
const [boxes, setBoxes] = useState([]);
|
|
34
|
+
const boundaries = useMemo(()=>new Map(metadata.boundaries.map((entry, index)=>[
|
|
35
|
+
entry.mfName,
|
|
36
|
+
{
|
|
37
|
+
...entry,
|
|
38
|
+
color: entry.color ?? palette[index % palette.length],
|
|
39
|
+
label: entry.label ?? entry.appId
|
|
40
|
+
}
|
|
41
|
+
])), [
|
|
42
|
+
metadata
|
|
43
|
+
]);
|
|
44
|
+
const language = mounted ? detectLanguage() : 'en';
|
|
45
|
+
const toggleLabel = labels[language]?.toggle ?? labels.en?.toggle ?? defaultLabels.en?.toggle ?? 'show vertical boundaries';
|
|
46
|
+
useEffect(()=>{
|
|
47
|
+
setMounted(true);
|
|
48
|
+
setEnabled(readEnabled(storageKey, enabledByDefault));
|
|
49
|
+
}, [
|
|
50
|
+
enabledByDefault,
|
|
51
|
+
storageKey
|
|
52
|
+
]);
|
|
53
|
+
useEffect(()=>{
|
|
54
|
+
if (!mounted) return;
|
|
55
|
+
window.localStorage.setItem(storageKey, String(enabled));
|
|
56
|
+
}, [
|
|
57
|
+
enabled,
|
|
58
|
+
mounted,
|
|
59
|
+
storageKey
|
|
60
|
+
]);
|
|
61
|
+
useEffect(()=>{
|
|
62
|
+
if (!enabled) return void setBoxes([]);
|
|
63
|
+
const readBoxes = ()=>{
|
|
64
|
+
const nextBoxes = Array.from(document.querySelectorAll('[data-modern-boundary-id]')).map((element, index)=>{
|
|
65
|
+
const boundaryId = element.dataset.modernBoundaryId;
|
|
66
|
+
if (!boundaryId) return;
|
|
67
|
+
const rect = element.getBoundingClientRect();
|
|
68
|
+
if (rect.width <= 0 || rect.height <= 0) return;
|
|
69
|
+
const boundary = boundaries.get(boundaryId);
|
|
70
|
+
const color = boundary?.color ?? palette[index % palette.length];
|
|
71
|
+
return {
|
|
72
|
+
color,
|
|
73
|
+
height: rect.height,
|
|
74
|
+
id: `${boundaryId}-${index}`,
|
|
75
|
+
label: boundary?.label ?? boundaryId,
|
|
76
|
+
left: rect.left,
|
|
77
|
+
top: rect.top,
|
|
78
|
+
width: rect.width
|
|
79
|
+
};
|
|
80
|
+
}).filter((box)=>void 0 !== box);
|
|
81
|
+
setBoxes(nextBoxes);
|
|
82
|
+
};
|
|
83
|
+
readBoxes();
|
|
84
|
+
const resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(readBoxes);
|
|
85
|
+
for (const element of document.querySelectorAll('[data-modern-boundary-id]'))resizeObserver?.observe(element);
|
|
86
|
+
const mutationObserver = new MutationObserver(readBoxes);
|
|
87
|
+
mutationObserver.observe(document.body, {
|
|
88
|
+
childList: true,
|
|
89
|
+
subtree: true
|
|
90
|
+
});
|
|
91
|
+
window.addEventListener('resize', readBoxes);
|
|
92
|
+
window.addEventListener('scroll', readBoxes, true);
|
|
93
|
+
return ()=>{
|
|
94
|
+
mutationObserver.disconnect();
|
|
95
|
+
resizeObserver?.disconnect();
|
|
96
|
+
window.removeEventListener('resize', readBoxes);
|
|
97
|
+
window.removeEventListener('scroll', readBoxes, true);
|
|
98
|
+
};
|
|
99
|
+
}, [
|
|
100
|
+
boundaries,
|
|
101
|
+
enabled
|
|
102
|
+
]);
|
|
103
|
+
if (!mounted) return null;
|
|
104
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
105
|
+
children: [
|
|
106
|
+
/*#__PURE__*/ jsxs("label", {
|
|
107
|
+
style: {
|
|
108
|
+
alignItems: 'center',
|
|
109
|
+
background: 'rgba(255, 255, 255, 0.96)',
|
|
110
|
+
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
111
|
+
borderRadius: 12,
|
|
112
|
+
bottom: 20,
|
|
113
|
+
boxShadow: '0 16px 40px rgba(0, 0, 0, 0.16)',
|
|
114
|
+
color: '#111827',
|
|
115
|
+
display: 'flex',
|
|
116
|
+
font: '600 14px/1.2 system-ui, sans-serif',
|
|
117
|
+
gap: 8,
|
|
118
|
+
left: 20,
|
|
119
|
+
padding: '12px 14px',
|
|
120
|
+
position: 'fixed',
|
|
121
|
+
zIndex: 2147483000
|
|
122
|
+
},
|
|
123
|
+
children: [
|
|
124
|
+
/*#__PURE__*/ jsx("input", {
|
|
125
|
+
checked: enabled,
|
|
126
|
+
onChange: (event)=>setEnabled(event.currentTarget.checked),
|
|
127
|
+
type: "checkbox"
|
|
128
|
+
}),
|
|
129
|
+
/*#__PURE__*/ jsx("span", {
|
|
130
|
+
children: toggleLabel
|
|
131
|
+
})
|
|
132
|
+
]
|
|
133
|
+
}),
|
|
134
|
+
enabled ? /*#__PURE__*/ jsx("div", {
|
|
135
|
+
"aria-hidden": "true",
|
|
136
|
+
children: boxes.map((box)=>/*#__PURE__*/ jsx("div", {
|
|
137
|
+
style: {
|
|
138
|
+
border: `2px solid ${box.color}`,
|
|
139
|
+
borderRadius: 8,
|
|
140
|
+
boxShadow: `0 0 0 1px rgba(255,255,255,.72), 0 6px 20px color-mix(in srgb, ${box.color} 20%, transparent)`,
|
|
141
|
+
height: box.height,
|
|
142
|
+
left: box.left,
|
|
143
|
+
pointerEvents: 'none',
|
|
144
|
+
position: 'fixed',
|
|
145
|
+
top: box.top,
|
|
146
|
+
width: box.width,
|
|
147
|
+
zIndex: 2147482999
|
|
148
|
+
},
|
|
149
|
+
children: /*#__PURE__*/ jsx("span", {
|
|
150
|
+
style: {
|
|
151
|
+
background: box.color,
|
|
152
|
+
borderRadius: 999,
|
|
153
|
+
color: '#111827',
|
|
154
|
+
font: '800 11px/1 system-ui, sans-serif',
|
|
155
|
+
padding: '5px 8px',
|
|
156
|
+
position: 'absolute',
|
|
157
|
+
right: 4,
|
|
158
|
+
top: 4,
|
|
159
|
+
whiteSpace: 'nowrap'
|
|
160
|
+
},
|
|
161
|
+
children: box.label
|
|
162
|
+
})
|
|
163
|
+
}, box.id))
|
|
164
|
+
}) : null
|
|
165
|
+
]
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const ultramodernBoundaryDebuggerPlugin = (options)=>({
|
|
169
|
+
name: '@modern-js/runtime/boundary-debugger',
|
|
170
|
+
setup: (api)=>{
|
|
171
|
+
api.wrapRoot((App)=>(props)=>/*#__PURE__*/ jsxs(Fragment, {
|
|
172
|
+
children: [
|
|
173
|
+
/*#__PURE__*/ jsx(App, {
|
|
174
|
+
...props
|
|
175
|
+
}),
|
|
176
|
+
/*#__PURE__*/ jsx(BoundaryDebugger, {
|
|
177
|
+
...options
|
|
178
|
+
})
|
|
179
|
+
]
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
const boundary_debugger = ultramodernBoundaryDebuggerPlugin;
|
|
184
|
+
export default boundary_debugger;
|
|
185
|
+
export { ultramodernBoundaryDebuggerPlugin };
|
|
@@ -84,13 +84,14 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
84
84
|
const hasServerRendering = hasServerRenderingConfig(userConfig);
|
|
85
85
|
const hasModuleFederationRuntimeMarker = hasServerRendering && shouldUseModuleFederationNodeOutput(config);
|
|
86
86
|
const hasExplicitMfSsrFlag = isModuleFederationAppSSREnabled(userConfig);
|
|
87
|
+
const isCloudflareWorkerSSR = 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare';
|
|
87
88
|
const requireExplicitMfSsrFlag = 'true' === process.env.MODERN_MF_APP_SSR_REQUIRE_EXPLICIT;
|
|
88
89
|
if (hasServerRendering && hasModuleFederationRuntimeMarker && !hasExplicitMfSsrFlag) {
|
|
89
90
|
const warningMessage = '[modernjs][mf-ssr] Module Federation SSR was auto-detected from runtime markers. Set server.ssr.moduleFederationAppSSR=true explicitly in host and remotes to avoid heuristic drift.';
|
|
90
91
|
if (requireExplicitMfSsrFlag) throw new Error(`${warningMessage} (enforced by MODERN_MF_APP_SSR_REQUIRE_EXPLICIT=true)`);
|
|
91
92
|
console.warn(warningMessage);
|
|
92
93
|
}
|
|
93
|
-
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag;
|
|
94
|
+
const isModuleFederationAppSSR = hasServerRendering && hasExplicitMfSsrFlag && !isCloudflareWorkerSSR;
|
|
94
95
|
const useModuleFederationNodeOutput = hasServerRendering && isModuleFederationAppSSR && isNodeEnvironmentTarget(config.output.target);
|
|
95
96
|
const ssrEnv = userConfig.deploy?.worker?.ssr || userConfig.server?.rsc ? 'edge' : 'node';
|
|
96
97
|
const appContext = modernAPI.getAppContext();
|
|
@@ -107,7 +108,7 @@ const ssrBuilderPlugin = (modernAPI, outputModule, exportLoadablePath)=>({
|
|
|
107
108
|
} : void 0;
|
|
108
109
|
const useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
109
110
|
const outputConfig = {
|
|
110
|
-
module: isServerEnvironment && !useModuleFederationNodeOutput && outputModule
|
|
111
|
+
module: isServerEnvironment && !useModuleFederationNodeOutput && (outputModule || 'workerSSR' === name && userConfig.deploy?.target === 'cloudflare')
|
|
111
112
|
};
|
|
112
113
|
const useLoadableComponents = isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig, appDirectory, entrypoints);
|
|
113
114
|
return mergeEnvironmentConfig(config, {
|
|
@@ -16,8 +16,9 @@ function registerPlugin(internalPlugins, runtimeConfig) {
|
|
|
16
16
|
config: runtimeConfig || {},
|
|
17
17
|
handleSetupResult: handleSetupResult
|
|
18
18
|
});
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const internalRuntimeContext = runtimeContext;
|
|
20
|
+
setGlobalInternalRuntimeContext(internalRuntimeContext);
|
|
21
|
+
return internalRuntimeContext;
|
|
21
22
|
}
|
|
22
23
|
function mergeConfig(config, ...otherConfig) {
|
|
23
24
|
return merge({}, config, ...otherConfig);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serializeJson } from "@modern-js/runtime-utils/node";
|
|
2
|
-
import { getRouterHydrationScripts } from "../../../router/runtime/lifecycle.mjs";
|
|
2
|
+
import { getRouterHydrationScripts, getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
3
3
|
import { SSR_DATA_JSON_ID } from "../../constants.mjs";
|
|
4
4
|
import { SSR_DATA_PLACEHOLDER } from "../constants.mjs";
|
|
5
5
|
import { buildHtml } from "../shared.mjs";
|
|
@@ -22,12 +22,15 @@ function buildShellAfterTemplate(afterAppTemplate, options) {
|
|
|
22
22
|
if (!routeManifest) return template;
|
|
23
23
|
const { routeAssets } = routeManifest;
|
|
24
24
|
if (!routeAssets) return template;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
|
|
26
|
+
const assetEntries = [
|
|
27
|
+
...matchedRouteIds.map((routeId)=>routeAssets[routeId]),
|
|
28
|
+
routeAssets[`async-${entryName}`]
|
|
29
|
+
].filter(Boolean);
|
|
30
|
+
const jsAssets = Array.from(new Set(assetEntries.flatMap((entry)=>(entry.assets ?? []).filter((asset)=>asset.endsWith('.js')))));
|
|
31
|
+
const nonceAttr = nonce ? ` nonce="${nonce}"` : '';
|
|
32
|
+
const jsChunkStr = jsAssets.filter((asset)=>!template.includes(asset)).map((asset)=>`<script src=${asset}${nonceAttr}></script>`).join(' ');
|
|
33
|
+
if (jsChunkStr) return safeReplace(template, '<!--<?- chunksMap.js ?>-->', jsChunkStr);
|
|
31
34
|
return template;
|
|
32
35
|
}
|
|
33
36
|
return buildHtml(afterAppTemplate, callbacks);
|
|
@@ -32,28 +32,27 @@ async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
|
32
32
|
const { routeManifest, routerContext, routes } = runtimeContext;
|
|
33
33
|
if (!routeManifest) return '';
|
|
34
34
|
const { routeAssets } = routeManifest;
|
|
35
|
-
let matchedRouteManifests;
|
|
35
|
+
let matchedRouteManifests = [];
|
|
36
36
|
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
|
|
37
37
|
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
38
|
-
else {
|
|
39
|
-
if (!routerContext || !routes) return '';
|
|
38
|
+
else if (routerContext && routes) {
|
|
40
39
|
const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
|
|
41
40
|
matchedRouteManifests = matches?.map((match, index)=>{
|
|
42
41
|
if (!index) return;
|
|
43
42
|
const routeId = match.route.id;
|
|
44
43
|
if (routeId) return routeAssets[routeId];
|
|
45
|
-
}).filter(Boolean);
|
|
44
|
+
}).filter(Boolean) ?? [];
|
|
46
45
|
}
|
|
47
46
|
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
48
|
-
if (asyncEntry) matchedRouteManifests
|
|
49
|
-
const cssChunks = matchedRouteManifests
|
|
47
|
+
if (asyncEntry) matchedRouteManifests.push(asyncEntry);
|
|
48
|
+
const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
50
49
|
const { referenceCssAssets = [] } = routeManifest;
|
|
51
50
|
const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
|
|
52
51
|
return [
|
|
53
52
|
...chunks,
|
|
54
53
|
..._cssChunks
|
|
55
54
|
];
|
|
56
|
-
}, [])
|
|
55
|
+
}, []);
|
|
57
56
|
const { inlineStyles } = config;
|
|
58
57
|
const styles = await Promise.all(cssChunks.map(async (chunk)=>{
|
|
59
58
|
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { matchRoutes } from "@modern-js/runtime-utils/router";
|
|
2
|
+
import react_helmet from "react-helmet";
|
|
3
|
+
import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
4
|
+
import { CHUNK_CSS_PLACEHOLDER } from "../constants.mjs";
|
|
5
|
+
import { createReplaceHelemt } from "../helmet.mjs";
|
|
6
|
+
import { buildHtml } from "../shared.mjs";
|
|
7
|
+
import { safeReplace } from "../utils.mjs";
|
|
8
|
+
const checkIsInline = (chunk, enableInline)=>{
|
|
9
|
+
if ('production' !== process.env.NODE_ENV) return false;
|
|
10
|
+
if (enableInline instanceof RegExp) return enableInline.test(chunk);
|
|
11
|
+
return Boolean(enableInline);
|
|
12
|
+
};
|
|
13
|
+
async function buildShellBeforeTemplate(beforeAppTemplate, options) {
|
|
14
|
+
const { config, runtimeContext, styledComponentsStyleTags, entryName } = options;
|
|
15
|
+
const helmetData = react_helmet.renderStatic();
|
|
16
|
+
const callbacks = [
|
|
17
|
+
createReplaceHelemt(helmetData),
|
|
18
|
+
(template)=>injectCss(template, entryName, styledComponentsStyleTags)
|
|
19
|
+
];
|
|
20
|
+
return buildHtml(beforeAppTemplate, callbacks);
|
|
21
|
+
async function injectCss(template, entryName, styledComponentsStyleTags) {
|
|
22
|
+
let css = await getCssChunks();
|
|
23
|
+
if (styledComponentsStyleTags) css += styledComponentsStyleTags;
|
|
24
|
+
return safeReplace(template, CHUNK_CSS_PLACEHOLDER, css);
|
|
25
|
+
async function getCssChunks() {
|
|
26
|
+
const { routeManifest, routerContext, routes } = runtimeContext;
|
|
27
|
+
if (!routeManifest) return '';
|
|
28
|
+
const { routeAssets } = routeManifest;
|
|
29
|
+
let matchedRouteManifests = [];
|
|
30
|
+
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext);
|
|
31
|
+
if (matchedRouteIds?.length) matchedRouteManifests = matchedRouteIds.map((routeId)=>routeAssets[routeId]).filter(Boolean);
|
|
32
|
+
else if (routerContext && routes) {
|
|
33
|
+
const matches = matchRoutes(routes, routerContext.location, routerContext.basename);
|
|
34
|
+
matchedRouteManifests = matches?.map((match, index)=>{
|
|
35
|
+
if (!index) return;
|
|
36
|
+
const routeId = match.route.id;
|
|
37
|
+
if (routeId) return routeAssets[routeId];
|
|
38
|
+
}).filter(Boolean) ?? [];
|
|
39
|
+
}
|
|
40
|
+
const asyncEntry = routeAssets[`async-${entryName}`];
|
|
41
|
+
if (asyncEntry) matchedRouteManifests.push(asyncEntry);
|
|
42
|
+
const cssChunks = matchedRouteManifests.reduce((chunks, routeManifest)=>{
|
|
43
|
+
const { referenceCssAssets = [] } = routeManifest;
|
|
44
|
+
const _cssChunks = referenceCssAssets.filter((asset)=>asset?.endsWith('.css') && !template.includes(asset));
|
|
45
|
+
return [
|
|
46
|
+
...chunks,
|
|
47
|
+
..._cssChunks
|
|
48
|
+
];
|
|
49
|
+
}, []);
|
|
50
|
+
const { inlineStyles } = config;
|
|
51
|
+
const styles = cssChunks.map((chunk)=>{
|
|
52
|
+
const link = `<link href="${chunk}" rel="stylesheet" />`;
|
|
53
|
+
checkIsInline(chunk, inlineStyles);
|
|
54
|
+
return link;
|
|
55
|
+
});
|
|
56
|
+
return `${styles.join('')}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export { buildShellBeforeTemplate };
|
|
@@ -8,7 +8,7 @@ import { getTemplates } from "./template.mjs";
|
|
|
8
8
|
const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
9
9
|
let shellChunkStatus = ShellChunkStatus.START;
|
|
10
10
|
const chunkVec = [];
|
|
11
|
-
const { htmlTemplate, runtimeContext, config, ssrConfig, entryName, rscRoot } = options;
|
|
11
|
+
const { htmlTemplate, runtimeContext, config, ssrConfig, entryName, rscManifest, rscRoot } = options;
|
|
12
12
|
const { shellBefore, shellAfter } = await getTemplates(htmlTemplate, {
|
|
13
13
|
renderLevel: RenderLevel.SERVER_RENDER,
|
|
14
14
|
runtimeContext,
|
|
@@ -21,6 +21,7 @@ const createReadableStreamFromElement = async (request, rootElement, options)=>{
|
|
|
21
21
|
const readableOriginal = await renderSSRStream(rootElement, {
|
|
22
22
|
request,
|
|
23
23
|
nonce: config.nonce,
|
|
24
|
+
rscManifest,
|
|
24
25
|
rscRoot: rscRoot,
|
|
25
26
|
routes: runtimeContext.routes,
|
|
26
27
|
onError (error) {
|
|
@@ -86,6 +86,7 @@ function createRenderStreaming(createReadableStreamPromise) {
|
|
|
86
86
|
rscClientManifest: options.rscClientManifest,
|
|
87
87
|
rscSSRManifest: options.rscSSRManifest,
|
|
88
88
|
rscServerManifest: options.rscServerManifest,
|
|
89
|
+
rscManifest: options.rscManifest,
|
|
89
90
|
rscRoot: options.rscRoot,
|
|
90
91
|
onShellReady () {
|
|
91
92
|
const cost = end();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ChunkExtractor } from "@loadable/server";
|
|
2
|
+
import { getRouterMatchedRouteIds } from "../../../router/runtime/lifecycle.mjs";
|
|
2
3
|
import { attributesToString, checkIsNode } from "../utils.mjs";
|
|
3
4
|
const extname = (uri)=>{
|
|
4
5
|
if ('string' != typeof uri || !uri.includes('.')) return '';
|
|
@@ -21,6 +22,20 @@ class LoadableCollector {
|
|
|
21
22
|
const { routeManifest, entryName } = this.options;
|
|
22
23
|
return routeManifest?.routeAssets?.[entryName]?.assets;
|
|
23
24
|
}
|
|
25
|
+
getMatchedRouteChunks() {
|
|
26
|
+
const { routeManifest, runtimeContext } = this.options;
|
|
27
|
+
const routeAssets = routeManifest?.routeAssets;
|
|
28
|
+
if (!routeAssets) return [];
|
|
29
|
+
const matchedRouteIds = getRouterMatchedRouteIds(runtimeContext) ?? [];
|
|
30
|
+
return matchedRouteIds.flatMap((routeId)=>{
|
|
31
|
+
const routeAsset = routeAssets[routeId];
|
|
32
|
+
return (routeAsset?.assets ?? []).map((asset)=>({
|
|
33
|
+
filename: asset.replace(/^\//, ''),
|
|
34
|
+
path: asset,
|
|
35
|
+
url: asset
|
|
36
|
+
}));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
24
39
|
collect(comopnent) {
|
|
25
40
|
const { stats, entryName } = this.options;
|
|
26
41
|
if (!stats) return comopnent;
|
|
@@ -42,7 +57,7 @@ class LoadableCollector {
|
|
|
42
57
|
`async-${entryName}`
|
|
43
58
|
]));
|
|
44
59
|
} catch (e) {}
|
|
45
|
-
const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
|
|
60
|
+
const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks)).concat(this.getMatchedRouteChunks());
|
|
46
61
|
const scriptChunks = generateChunks(chunks, 'js');
|
|
47
62
|
const styleChunks = generateChunks(chunks, 'css');
|
|
48
63
|
this.emitLoadableScripts(extractor);
|
|
@@ -78,6 +78,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
78
78
|
const imports = [];
|
|
79
79
|
const statements = [];
|
|
80
80
|
const loaderImportMap = new Map();
|
|
81
|
+
const usedRouteVarNames = new Set();
|
|
81
82
|
let loaderIndex = 0;
|
|
82
83
|
let routeIndex = 0;
|
|
83
84
|
const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
|
|
@@ -111,10 +112,17 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
111
112
|
actionName
|
|
112
113
|
};
|
|
113
114
|
};
|
|
115
|
+
const reserveRouteVarName = (preferred)=>{
|
|
116
|
+
let candidate = preferred;
|
|
117
|
+
let suffix = 1;
|
|
118
|
+
while(usedRouteVarNames.has(candidate))candidate = `${preferred}_${suffix++}`;
|
|
119
|
+
usedRouteVarNames.add(candidate);
|
|
120
|
+
return candidate;
|
|
121
|
+
};
|
|
114
122
|
const createRouteVarName = (route)=>{
|
|
115
123
|
const id = route.id;
|
|
116
124
|
const base = id ? makeLegalIdentifier(id) : `r_${routeIndex++}`;
|
|
117
|
-
return `route_${base}
|
|
125
|
+
return reserveRouteVarName(`route_${base}`);
|
|
118
126
|
};
|
|
119
127
|
const buildRoute = async (opts)=>{
|
|
120
128
|
const { parentVar, route } = opts;
|
|
@@ -143,14 +151,16 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
|
|
|
143
151
|
actionName
|
|
144
152
|
});
|
|
145
153
|
if (staticDataSnippet) routeOpts.push(staticDataSnippet);
|
|
146
|
-
statements.push(`const ${varName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
147
154
|
const children = route.children;
|
|
155
|
+
const hasChildren = Boolean(children && children.length > 0);
|
|
156
|
+
const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
|
|
157
|
+
statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
|
|
148
158
|
if (children && children.length > 0) {
|
|
149
159
|
const childVars = await Promise.all(children.map((child)=>buildRoute({
|
|
150
|
-
parentVar:
|
|
160
|
+
parentVar: routeCtorVarName,
|
|
151
161
|
route: child
|
|
152
162
|
})));
|
|
153
|
-
statements.push(
|
|
163
|
+
statements.push(`const ${varName} = ${routeCtorVarName}.addChildren([${childVars.join(', ')}]);`);
|
|
154
164
|
}
|
|
155
165
|
return varName;
|
|
156
166
|
};
|
|
@@ -223,7 +233,11 @@ function createRouteStaticData(opts: {
|
|
|
223
233
|
modernRouteAction?: unknown;
|
|
224
234
|
modernRouteLoader?: unknown;
|
|
225
235
|
}) {
|
|
226
|
-
const staticData:
|
|
236
|
+
const staticData: {
|
|
237
|
+
modernRouteId?: string;
|
|
238
|
+
modernRouteAction?: unknown;
|
|
239
|
+
modernRouteLoader?: unknown;
|
|
240
|
+
} = {};
|
|
227
241
|
|
|
228
242
|
if (opts.modernRouteId) {
|
|
229
243
|
staticData.modernRouteId = opts.modernRouteId;
|
|
@@ -237,7 +251,7 @@ function createRouteStaticData(opts: {
|
|
|
237
251
|
staticData.modernRouteAction = opts.modernRouteAction;
|
|
238
252
|
}
|
|
239
253
|
|
|
240
|
-
return
|
|
254
|
+
return staticData;
|
|
241
255
|
}
|
|
242
256
|
|
|
243
257
|
function modernLoaderToTanstack<TLoader extends (args: any) => any>(
|