@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.0
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/LICENSE +21 -0
- package/dist/cjs/cli/index.js +268 -0
- package/dist/cjs/cli/tanstackTypes.js +388 -0
- package/dist/cjs/cli.js +65 -0
- package/dist/cjs/runtime/DefaultNotFound.js +47 -0
- package/dist/cjs/runtime/basepathRewrite.js +62 -0
- package/dist/cjs/runtime/dataMutation.js +345 -0
- package/dist/cjs/runtime/hooks.js +57 -0
- package/dist/cjs/runtime/index.js +114 -0
- package/dist/cjs/runtime/lifecycle.js +125 -0
- package/dist/cjs/runtime/plugin.js +250 -0
- package/dist/cjs/runtime/plugin.node.js +304 -0
- package/dist/cjs/runtime/prefetchLink.js +55 -0
- package/dist/cjs/runtime/routeTree.js +492 -0
- package/dist/cjs/runtime/rsc/ClientSlot.js +53 -0
- package/dist/cjs/runtime/rsc/CompositeComponent.js +75 -0
- package/dist/cjs/runtime/rsc/ReplayableStream.js +141 -0
- package/dist/cjs/runtime/rsc/RscNodeRenderer.js +65 -0
- package/dist/cjs/runtime/rsc/SlotContext.js +54 -0
- package/dist/cjs/runtime/rsc/client.js +93 -0
- package/dist/cjs/runtime/rsc/createRscProxy.js +141 -0
- package/dist/cjs/runtime/rsc/index.js +42 -0
- package/dist/cjs/runtime/rsc/payloadRouter.js +211 -0
- package/dist/cjs/runtime/rsc/server.js +246 -0
- package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +65 -0
- package/dist/cjs/runtime/rsc/symbols.js +72 -0
- package/dist/cjs/runtime/types.js +18 -0
- package/dist/cjs/runtime/utils.js +142 -0
- package/dist/cjs/runtime.js +58 -0
- package/dist/esm/cli/index.mjs +201 -0
- package/dist/esm/cli/tanstackTypes.mjs +341 -0
- package/dist/esm/cli.mjs +2 -0
- package/dist/esm/rslib-runtime.mjs +18 -0
- package/dist/esm/runtime/DefaultNotFound.mjs +13 -0
- package/dist/esm/runtime/basepathRewrite.mjs +28 -0
- package/dist/esm/runtime/dataMutation.mjs +305 -0
- package/dist/esm/runtime/hooks.mjs +8 -0
- package/dist/esm/runtime/index.mjs +6 -0
- package/dist/esm/runtime/lifecycle.mjs +82 -0
- package/dist/esm/runtime/plugin.mjs +214 -0
- package/dist/esm/runtime/plugin.node.mjs +268 -0
- package/dist/esm/runtime/prefetchLink.mjs +18 -0
- package/dist/esm/runtime/routeTree.mjs +452 -0
- package/dist/esm/runtime/rsc/ClientSlot.mjs +19 -0
- package/dist/esm/runtime/rsc/CompositeComponent.mjs +41 -0
- package/dist/esm/runtime/rsc/ReplayableStream.mjs +104 -0
- package/dist/esm/runtime/rsc/RscNodeRenderer.mjs +31 -0
- package/dist/esm/runtime/rsc/SlotContext.mjs +17 -0
- package/dist/esm/runtime/rsc/client.mjs +53 -0
- package/dist/esm/runtime/rsc/createRscProxy.mjs +107 -0
- package/dist/esm/runtime/rsc/index.mjs +1 -0
- package/dist/esm/runtime/rsc/payloadRouter.mjs +162 -0
- package/dist/esm/runtime/rsc/server.mjs +200 -0
- package/dist/esm/runtime/rsc/slotUsageSanitizer.mjs +31 -0
- package/dist/esm/runtime/rsc/symbols.mjs +17 -0
- package/dist/esm/runtime/types.mjs +0 -0
- package/dist/esm/runtime/utils.mjs +89 -0
- package/dist/esm/runtime.mjs +1 -0
- package/dist/esm-node/cli/index.mjs +205 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +342 -0
- package/dist/esm-node/cli.mjs +3 -0
- package/dist/esm-node/rslib-runtime.mjs +19 -0
- package/dist/esm-node/runtime/DefaultNotFound.mjs +14 -0
- package/dist/esm-node/runtime/basepathRewrite.mjs +29 -0
- package/dist/esm-node/runtime/dataMutation.mjs +306 -0
- package/dist/esm-node/runtime/hooks.mjs +9 -0
- package/dist/esm-node/runtime/index.mjs +7 -0
- package/dist/esm-node/runtime/lifecycle.mjs +83 -0
- package/dist/esm-node/runtime/plugin.mjs +215 -0
- package/dist/esm-node/runtime/plugin.node.mjs +269 -0
- package/dist/esm-node/runtime/prefetchLink.mjs +19 -0
- package/dist/esm-node/runtime/routeTree.mjs +453 -0
- package/dist/esm-node/runtime/rsc/ClientSlot.mjs +20 -0
- package/dist/esm-node/runtime/rsc/CompositeComponent.mjs +42 -0
- package/dist/esm-node/runtime/rsc/ReplayableStream.mjs +105 -0
- package/dist/esm-node/runtime/rsc/RscNodeRenderer.mjs +32 -0
- package/dist/esm-node/runtime/rsc/SlotContext.mjs +18 -0
- package/dist/esm-node/runtime/rsc/client.mjs +54 -0
- package/dist/esm-node/runtime/rsc/createRscProxy.mjs +108 -0
- package/dist/esm-node/runtime/rsc/index.mjs +2 -0
- package/dist/esm-node/runtime/rsc/payloadRouter.mjs +163 -0
- package/dist/esm-node/runtime/rsc/server.mjs +201 -0
- package/dist/esm-node/runtime/rsc/slotUsageSanitizer.mjs +32 -0
- package/dist/esm-node/runtime/rsc/symbols.mjs +18 -0
- package/dist/esm-node/runtime/types.mjs +1 -0
- package/dist/esm-node/runtime/utils.mjs +90 -0
- package/dist/esm-node/runtime.mjs +2 -0
- package/dist/types/cli/index.d.ts +20 -0
- package/dist/types/cli/tanstackTypes.d.ts +11 -0
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types/runtime/basepathRewrite.d.ts +8 -0
- package/dist/types/runtime/dataMutation.d.ts +29 -0
- package/dist/types/runtime/hooks.d.ts +18 -0
- package/dist/types/runtime/index.d.ts +9 -0
- package/dist/types/runtime/lifecycle.d.ts +22 -0
- package/dist/types/runtime/plugin.d.ts +17 -0
- package/dist/types/runtime/plugin.node.d.ts +17 -0
- package/dist/types/runtime/prefetchLink.d.ts +11 -0
- package/dist/types/runtime/routeTree.d.ts +11 -0
- package/dist/types/runtime/rsc/ClientSlot.d.ts +5 -0
- package/dist/types/runtime/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types/runtime/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types/runtime/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types/runtime/rsc/SlotContext.d.ts +11 -0
- package/dist/types/runtime/rsc/client.d.ts +11 -0
- package/dist/types/runtime/rsc/createRscProxy.d.ts +7 -0
- package/dist/types/runtime/rsc/index.d.ts +2 -0
- package/dist/types/runtime/rsc/payloadRouter.d.ts +24 -0
- package/dist/types/runtime/rsc/server.d.ts +14 -0
- package/dist/types/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types/runtime/rsc/symbols.d.ts +46 -0
- package/dist/types/runtime/types.d.ts +68 -0
- package/dist/types/runtime/utils.d.ts +36 -0
- package/dist/types/runtime.d.ts +1 -0
- package/dist/types-direct/cli/index.d.ts +20 -0
- package/dist/types-direct/cli/tanstackTypes.d.ts +11 -0
- package/dist/types-direct/cli.d.ts +2 -0
- package/dist/types-direct/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types-direct/runtime/basepathRewrite.d.ts +8 -0
- package/dist/types-direct/runtime/dataMutation.d.ts +29 -0
- package/dist/types-direct/runtime/hooks.d.ts +18 -0
- package/dist/types-direct/runtime/index.d.ts +9 -0
- package/dist/types-direct/runtime/lifecycle.d.ts +22 -0
- package/dist/types-direct/runtime/plugin.d.ts +17 -0
- package/dist/types-direct/runtime/plugin.node.d.ts +17 -0
- package/dist/types-direct/runtime/prefetchLink.d.ts +11 -0
- package/dist/types-direct/runtime/routeTree.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/ClientSlot.d.ts +5 -0
- package/dist/types-direct/runtime/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types-direct/runtime/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types-direct/runtime/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types-direct/runtime/rsc/SlotContext.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/client.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/createRscProxy.d.ts +7 -0
- package/dist/types-direct/runtime/rsc/index.d.ts +2 -0
- package/dist/types-direct/runtime/rsc/payloadRouter.d.ts +24 -0
- package/dist/types-direct/runtime/rsc/server.d.ts +14 -0
- package/dist/types-direct/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types-direct/runtime/rsc/symbols.d.ts +46 -0
- package/dist/types-direct/runtime/types.d.ts +68 -0
- package/dist/types-direct/runtime/utils.d.ts +36 -0
- package/dist/types-direct/runtime.d.ts +1 -0
- package/package.json +126 -0
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +43 -0
- package/src/cli/index.ts +388 -0
- package/src/cli/tanstackTypes.ts +503 -0
- package/src/cli.ts +2 -0
- package/src/runtime/DefaultNotFound.tsx +15 -0
- package/src/runtime/basepathRewrite.ts +59 -0
- package/src/runtime/dataMutation.tsx +517 -0
- package/src/runtime/hooks.ts +34 -0
- package/src/runtime/index.tsx +30 -0
- package/src/runtime/lifecycle.ts +150 -0
- package/src/runtime/plugin.node.tsx +534 -0
- package/src/runtime/plugin.tsx +395 -0
- package/src/runtime/prefetchLink.tsx +87 -0
- package/src/runtime/routeTree.ts +942 -0
- package/src/runtime/rsc/ClientSlot.tsx +25 -0
- package/src/runtime/rsc/CompositeComponent.tsx +65 -0
- package/src/runtime/rsc/ReplayableStream.ts +155 -0
- package/src/runtime/rsc/RscNodeRenderer.tsx +45 -0
- package/src/runtime/rsc/SlotContext.tsx +31 -0
- package/src/runtime/rsc/client.tsx +90 -0
- package/src/runtime/rsc/createRscProxy.tsx +189 -0
- package/src/runtime/rsc/index.ts +10 -0
- package/src/runtime/rsc/payloadRouter.ts +318 -0
- package/src/runtime/rsc/server.tsx +303 -0
- package/src/runtime/rsc/slotUsageSanitizer.ts +76 -0
- package/src/runtime/rsc/symbols.ts +106 -0
- package/src/runtime/ssr-shim.d.ts +12 -0
- package/src/runtime/types.ts +83 -0
- package/src/runtime/utils.tsx +161 -0
- package/src/runtime.ts +1 -0
- package/tests/router/cli.test.ts +386 -0
- package/tests/router/dataMutation.test.tsx +396 -0
- package/tests/router/prefetchLink.test.tsx +43 -0
- package/tests/router/routeTree.test.ts +502 -0
- package/tests/router/rsc.test.tsx +256 -0
- package/tests/router/tanstackTypes.test.ts +62 -0
- package/tsconfig.json +12 -0
- package/tsconfig.tsgo.json +6 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
applyRouterRuntimeState: ()=>applyRouterRuntimeState,
|
|
28
|
+
applyRouterServerPrepareResult: ()=>applyRouterServerPrepareResult,
|
|
29
|
+
createRouterRuntimeState: ()=>createRouterRuntimeState,
|
|
30
|
+
createRouterServerSnapshot: ()=>createRouterServerSnapshot
|
|
31
|
+
});
|
|
32
|
+
function toHydrationScripts(state) {
|
|
33
|
+
if (state.hydrationScripts?.length) return state.hydrationScripts;
|
|
34
|
+
return state.hydrationScript ? [
|
|
35
|
+
state.hydrationScript
|
|
36
|
+
] : void 0;
|
|
37
|
+
}
|
|
38
|
+
function getMatchedRouteIdsFromMatches(matches) {
|
|
39
|
+
const routeIds = matches?.map((match)=>match.assetRouteId ?? match.routeId).filter((routeId)=>'string' == typeof routeId);
|
|
40
|
+
return routeIds?.length ? routeIds : void 0;
|
|
41
|
+
}
|
|
42
|
+
function createRouterServerSnapshot(state) {
|
|
43
|
+
const hydrationScripts = toHydrationScripts(state);
|
|
44
|
+
const matchedRouteIds = state.matchedRouteIds ?? getMatchedRouteIdsFromMatches(state.matches);
|
|
45
|
+
return {
|
|
46
|
+
...state,
|
|
47
|
+
...hydrationScripts?.length ? {
|
|
48
|
+
hydrationScript: state.hydrationScript ?? hydrationScripts[0],
|
|
49
|
+
hydrationScripts
|
|
50
|
+
} : {},
|
|
51
|
+
...matchedRouteIds ? {
|
|
52
|
+
matchedRouteIds
|
|
53
|
+
} : {}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function createRouterRuntimeState(state) {
|
|
57
|
+
const hasSnapshotState = Boolean(state.serverSnapshot) || Boolean(state.hydrationScript) || Boolean(state.hydrationScripts?.length) || Boolean(state.matchedRouteIds?.length) || Boolean(state.matches?.length);
|
|
58
|
+
const serverSnapshot = state.serverSnapshot ? createRouterServerSnapshot({
|
|
59
|
+
...state.serverSnapshot,
|
|
60
|
+
framework: state.serverSnapshot.framework ?? state.framework,
|
|
61
|
+
basename: state.serverSnapshot.basename ?? state.basename,
|
|
62
|
+
hydrationScript: state.serverSnapshot.hydrationScript ?? state.hydrationScript,
|
|
63
|
+
hydrationScripts: state.serverSnapshot.hydrationScripts ?? state.hydrationScripts,
|
|
64
|
+
matchedRouteIds: state.serverSnapshot.matchedRouteIds ?? state.matchedRouteIds,
|
|
65
|
+
matches: state.serverSnapshot.matches ?? state.matches
|
|
66
|
+
}) : hasSnapshotState ? createRouterServerSnapshot({
|
|
67
|
+
framework: state.framework,
|
|
68
|
+
basename: state.basename,
|
|
69
|
+
hydrationScript: state.hydrationScript,
|
|
70
|
+
hydrationScripts: state.hydrationScripts,
|
|
71
|
+
matchedRouteIds: state.matchedRouteIds,
|
|
72
|
+
matches: state.matches
|
|
73
|
+
}) : void 0;
|
|
74
|
+
const hydrationScripts = toHydrationScripts({
|
|
75
|
+
hydrationScript: state.hydrationScript ?? serverSnapshot?.hydrationScript,
|
|
76
|
+
hydrationScripts: state.hydrationScripts ?? serverSnapshot?.hydrationScripts
|
|
77
|
+
});
|
|
78
|
+
const matchedRouteIds = state.matchedRouteIds ?? serverSnapshot?.matchedRouteIds ?? getMatchedRouteIdsFromMatches(state.matches);
|
|
79
|
+
return {
|
|
80
|
+
...state,
|
|
81
|
+
...hydrationScripts?.length ? {
|
|
82
|
+
hydrationScript: state.hydrationScript ?? hydrationScripts[0],
|
|
83
|
+
hydrationScripts
|
|
84
|
+
} : {},
|
|
85
|
+
...matchedRouteIds ? {
|
|
86
|
+
matchedRouteIds
|
|
87
|
+
} : {},
|
|
88
|
+
...serverSnapshot ? {
|
|
89
|
+
serverSnapshot
|
|
90
|
+
} : {}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function applyRouterRuntimeState(runtimeContext, state) {
|
|
94
|
+
const normalized = createRouterRuntimeState(state);
|
|
95
|
+
const mutableRuntimeContext = runtimeContext;
|
|
96
|
+
mutableRuntimeContext.routerFramework = normalized.framework;
|
|
97
|
+
mutableRuntimeContext.routerInstance = normalized.instance;
|
|
98
|
+
mutableRuntimeContext.routerHydrationScript = normalized.hydrationScript;
|
|
99
|
+
mutableRuntimeContext.routerMatchedRouteIds = normalized.matchedRouteIds;
|
|
100
|
+
mutableRuntimeContext.routerRuntime = normalized;
|
|
101
|
+
if (normalized.serverSnapshot) mutableRuntimeContext.routerServerSnapshot = normalized.serverSnapshot;
|
|
102
|
+
return runtimeContext;
|
|
103
|
+
}
|
|
104
|
+
function applyRouterServerPrepareResult(runtimeContext, result) {
|
|
105
|
+
const state = createRouterRuntimeState({
|
|
106
|
+
...result.state,
|
|
107
|
+
cleanup: result.cleanup ?? result.state.cleanup,
|
|
108
|
+
serverSnapshot: result.snapshot ?? result.state.serverSnapshot
|
|
109
|
+
});
|
|
110
|
+
applyRouterRuntimeState(runtimeContext, state);
|
|
111
|
+
return runtimeContext;
|
|
112
|
+
}
|
|
113
|
+
exports.applyRouterRuntimeState = __webpack_exports__.applyRouterRuntimeState;
|
|
114
|
+
exports.applyRouterServerPrepareResult = __webpack_exports__.applyRouterServerPrepareResult;
|
|
115
|
+
exports.createRouterRuntimeState = __webpack_exports__.createRouterRuntimeState;
|
|
116
|
+
exports.createRouterServerSnapshot = __webpack_exports__.createRouterServerSnapshot;
|
|
117
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
118
|
+
"applyRouterRuntimeState",
|
|
119
|
+
"applyRouterServerPrepareResult",
|
|
120
|
+
"createRouterRuntimeState",
|
|
121
|
+
"createRouterServerSnapshot"
|
|
122
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
123
|
+
Object.defineProperty(exports, '__esModule', {
|
|
124
|
+
value: true
|
|
125
|
+
});
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
default: ()=>runtime_plugin,
|
|
28
|
+
tanstackRouterPlugin: ()=>tanstackRouterPlugin
|
|
29
|
+
});
|
|
30
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
31
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
32
|
+
const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
|
|
33
|
+
const url_namespaceObject = require("@modern-js/runtime-utils/url");
|
|
34
|
+
const react_router_namespaceObject = require("@tanstack/react-router");
|
|
35
|
+
const client_namespaceObject = require("@tanstack/react-router/ssr/client");
|
|
36
|
+
const external_react_namespaceObject = require("react");
|
|
37
|
+
const external_basepathRewrite_js_namespaceObject = require("./basepathRewrite.js");
|
|
38
|
+
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
39
|
+
const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
|
|
40
|
+
const external_routeTree_js_namespaceObject = require("./routeTree.js");
|
|
41
|
+
const client_js_namespaceObject = require("./rsc/client.js");
|
|
42
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
43
|
+
const BLOCKING_SUBSCRIBE_SYMBOL = Symbol.for('@modern-js/plugin-tanstack:blocking-subscribe');
|
|
44
|
+
const BLOCKING_STATE_SYMBOL = Symbol.for('@modern-js/plugin-tanstack:blocking-state');
|
|
45
|
+
function normalizeBase(b) {
|
|
46
|
+
if (b.length > 1 && b.endsWith('/')) return b.slice(0, -1);
|
|
47
|
+
return b || '/';
|
|
48
|
+
}
|
|
49
|
+
function isSegmentPrefix(pathname, base) {
|
|
50
|
+
const b = normalizeBase(base);
|
|
51
|
+
const p = pathname || '/';
|
|
52
|
+
return p === b || p.startsWith(`${b}/`);
|
|
53
|
+
}
|
|
54
|
+
function wrapRouterSubscribeWithBlockState(router, getBlockNavState) {
|
|
55
|
+
if (!router || 'object' != typeof router) return;
|
|
56
|
+
const target = router;
|
|
57
|
+
target[BLOCKING_STATE_SYMBOL] = getBlockNavState;
|
|
58
|
+
if (target[BLOCKING_SUBSCRIBE_SYMBOL] || 'function' != typeof target.subscribe) return;
|
|
59
|
+
const originSubscribe = target.subscribe.bind(target);
|
|
60
|
+
target.subscribe = (eventType, listener)=>{
|
|
61
|
+
const wrappedListener = (...args)=>{
|
|
62
|
+
const blockRoute = target[BLOCKING_STATE_SYMBOL]?.() || false;
|
|
63
|
+
if (blockRoute) return;
|
|
64
|
+
return listener(...args);
|
|
65
|
+
};
|
|
66
|
+
return originSubscribe(eventType, wrappedListener);
|
|
67
|
+
};
|
|
68
|
+
target[BLOCKING_SUBSCRIBE_SYMBOL] = true;
|
|
69
|
+
}
|
|
70
|
+
function stripSyntheticNotFoundRoute(routes) {
|
|
71
|
+
return routes.filter((route)=>!('*' === route.path && !route.id && !route.loader)).map((route)=>{
|
|
72
|
+
if (!route.children?.length) return route;
|
|
73
|
+
return {
|
|
74
|
+
...route,
|
|
75
|
+
children: stripSyntheticNotFoundRoute(route.children)
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const tanstackRouterPlugin = (userConfig = {})=>{
|
|
80
|
+
const plugin = {
|
|
81
|
+
name: '@modern-js/plugin-router-tanstack',
|
|
82
|
+
registryHooks: {
|
|
83
|
+
modifyRoutes: external_hooks_js_namespaceObject.modifyRoutes,
|
|
84
|
+
onAfterCreateRouter: external_hooks_js_namespaceObject.onAfterCreateRouter,
|
|
85
|
+
onAfterHydrateRouter: external_hooks_js_namespaceObject.onAfterHydrateRouter,
|
|
86
|
+
onBeforeCreateRouter: external_hooks_js_namespaceObject.onBeforeCreateRouter,
|
|
87
|
+
onBeforeCreateRoutes: external_hooks_js_namespaceObject.onBeforeCreateRoutes,
|
|
88
|
+
onBeforeHydrateRouter: external_hooks_js_namespaceObject.onBeforeHydrateRouter
|
|
89
|
+
},
|
|
90
|
+
setup: (api)=>{
|
|
91
|
+
api.onBeforeRender((context)=>{
|
|
92
|
+
const pluginConfig = api.getRuntimeConfig();
|
|
93
|
+
const mergedConfig = (0, merge_namespaceObject.merge)(pluginConfig.router || {}, userConfig);
|
|
94
|
+
if ("u" > typeof window && window._SSR_DATA && mergedConfig.unstable_reloadOnURLMismatch) {
|
|
95
|
+
const { ssrContext } = context;
|
|
96
|
+
const currentPathname = (0, url_namespaceObject.normalizePathname)(window.location.pathname);
|
|
97
|
+
const initialPathname = ssrContext?.request?.pathname && (0, url_namespaceObject.normalizePathname)(ssrContext.request.pathname);
|
|
98
|
+
if (initialPathname && initialPathname !== currentPathname) {
|
|
99
|
+
const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
|
|
100
|
+
console.error(errorMsg);
|
|
101
|
+
window.location.reload();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
context.router = {
|
|
105
|
+
useMatches: react_router_namespaceObject.useMatches,
|
|
106
|
+
useLocation: react_router_namespaceObject.useLocation,
|
|
107
|
+
useNavigate: react_router_namespaceObject.useNavigate,
|
|
108
|
+
useRouter: react_router_namespaceObject.useRouter
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
api.wrapRoot((App)=>{
|
|
112
|
+
const mergedConfig = (0, merge_namespaceObject.merge)(api.getRuntimeConfig().router || {}, userConfig);
|
|
113
|
+
const { serverBase = [], supportHtml5History = true, basename = '', routesConfig, createRoutes } = mergedConfig;
|
|
114
|
+
const finalRouteConfig = {
|
|
115
|
+
routes: (0, context_namespaceObject.getGlobalRoutes)(),
|
|
116
|
+
globalApp: (0, context_namespaceObject.getGlobalLayoutApp)(),
|
|
117
|
+
...routesConfig
|
|
118
|
+
};
|
|
119
|
+
if (!finalRouteConfig.routes && !createRoutes) return App;
|
|
120
|
+
const hooks = api.getHooks();
|
|
121
|
+
let cachedRouteObjects;
|
|
122
|
+
const getRouteObjects = ()=>{
|
|
123
|
+
if (void 0 !== cachedRouteObjects) return cachedRouteObjects;
|
|
124
|
+
const routeObjects = createRoutes ? createRoutes() : (0, external_utils_js_namespaceObject.createRouteObjectsFromConfig)({
|
|
125
|
+
routesConfig: finalRouteConfig
|
|
126
|
+
}) || [];
|
|
127
|
+
const normalizedRouteObjects = createRoutes ? routeObjects : stripSyntheticNotFoundRoute(routeObjects);
|
|
128
|
+
cachedRouteObjects = hooks.modifyRoutes.call(normalizedRouteObjects);
|
|
129
|
+
return cachedRouteObjects;
|
|
130
|
+
};
|
|
131
|
+
const selectBasePath = (pathname)=>{
|
|
132
|
+
const match = serverBase.find((baseUrl)=>isSegmentPrefix(pathname, baseUrl));
|
|
133
|
+
return match || '/';
|
|
134
|
+
};
|
|
135
|
+
let cachedRouteTree = null;
|
|
136
|
+
let cachedRouter = null;
|
|
137
|
+
let cachedRouterBasepath = null;
|
|
138
|
+
const RouterWrapper = ()=>{
|
|
139
|
+
const runtimeContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
140
|
+
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
141
|
+
const _basename = '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
142
|
+
const routeTree = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
143
|
+
if (cachedRouteTree) return cachedRouteTree;
|
|
144
|
+
const routeObjects = getRouteObjects();
|
|
145
|
+
if (!routeObjects.length) return null;
|
|
146
|
+
cachedRouteTree = (0, external_routeTree_js_namespaceObject.createRouteTreeFromRouteObjects)(routeObjects, {
|
|
147
|
+
rscPayloadRouter: (0, context_namespaceObject.getGlobalEnableRsc)()
|
|
148
|
+
});
|
|
149
|
+
return cachedRouteTree;
|
|
150
|
+
}, []);
|
|
151
|
+
if (!routeTree) return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {}) : null;
|
|
152
|
+
const router = (0, external_react_namespaceObject.useMemo)(()=>{
|
|
153
|
+
const lifecycleContext = {
|
|
154
|
+
framework: 'tanstack',
|
|
155
|
+
phase: 'client-create',
|
|
156
|
+
routes: getRouteObjects(),
|
|
157
|
+
runtimeContext,
|
|
158
|
+
basename: _basename
|
|
159
|
+
};
|
|
160
|
+
hooks.onBeforeCreateRouter.call(lifecycleContext);
|
|
161
|
+
if (cachedRouter && cachedRouterBasepath === _basename) {
|
|
162
|
+
wrapRouterSubscribeWithBlockState(cachedRouter, runtimeContext.unstable_getBlockNavState);
|
|
163
|
+
hooks.onAfterCreateRouter.call({
|
|
164
|
+
...lifecycleContext,
|
|
165
|
+
router: cachedRouter,
|
|
166
|
+
runtimeContext
|
|
167
|
+
});
|
|
168
|
+
return cachedRouter;
|
|
169
|
+
}
|
|
170
|
+
const history = supportHtml5History ? (0, react_router_namespaceObject.createBrowserHistory)() : (0, react_router_namespaceObject.createHashHistory)();
|
|
171
|
+
const rewrite = (0, external_basepathRewrite_js_namespaceObject.createModernBasepathRewrite)(_basename);
|
|
172
|
+
const serializationAdapters = (0, context_namespaceObject.getGlobalEnableRsc)() ? (0, client_js_namespaceObject.getTanstackRscSerializationAdapters)() : void 0;
|
|
173
|
+
cachedRouter = (0, react_router_namespaceObject.createRouter)({
|
|
174
|
+
routeTree,
|
|
175
|
+
basepath: '/',
|
|
176
|
+
rewrite,
|
|
177
|
+
history,
|
|
178
|
+
context: {},
|
|
179
|
+
...serializationAdapters ? {
|
|
180
|
+
serializationAdapters
|
|
181
|
+
} : {}
|
|
182
|
+
});
|
|
183
|
+
cachedRouterBasepath = _basename;
|
|
184
|
+
wrapRouterSubscribeWithBlockState(cachedRouter, runtimeContext.unstable_getBlockNavState);
|
|
185
|
+
hooks.onAfterCreateRouter.call({
|
|
186
|
+
...lifecycleContext,
|
|
187
|
+
router: cachedRouter,
|
|
188
|
+
runtimeContext
|
|
189
|
+
});
|
|
190
|
+
return cachedRouter;
|
|
191
|
+
}, [
|
|
192
|
+
_basename,
|
|
193
|
+
routeTree,
|
|
194
|
+
supportHtml5History,
|
|
195
|
+
runtimeContext
|
|
196
|
+
]);
|
|
197
|
+
const runtimeState = (0, external_lifecycle_js_namespaceObject.applyRouterRuntimeState)(runtimeContext, {
|
|
198
|
+
framework: 'tanstack',
|
|
199
|
+
basename: _basename,
|
|
200
|
+
instance: router
|
|
201
|
+
});
|
|
202
|
+
const lifecycleContext = {
|
|
203
|
+
framework: 'tanstack',
|
|
204
|
+
phase: 'client-create',
|
|
205
|
+
routes: getRouteObjects(),
|
|
206
|
+
runtimeContext: runtimeState,
|
|
207
|
+
basename: _basename,
|
|
208
|
+
router
|
|
209
|
+
};
|
|
210
|
+
const hasSSRBootstrap = "u" > typeof window && Boolean(window.$_TSR);
|
|
211
|
+
if (hasSSRBootstrap) hooks.onBeforeHydrateRouter.call({
|
|
212
|
+
...lifecycleContext,
|
|
213
|
+
phase: 'hydrate',
|
|
214
|
+
router,
|
|
215
|
+
runtimeContext: runtimeState
|
|
216
|
+
});
|
|
217
|
+
const RouterContent = hasSSRBootstrap ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_namespaceObject.Suspense, {
|
|
218
|
+
fallback: null,
|
|
219
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.RouterClient, {
|
|
220
|
+
router: router
|
|
221
|
+
})
|
|
222
|
+
}) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.RouterProvider, {
|
|
223
|
+
router: router
|
|
224
|
+
});
|
|
225
|
+
if (hasSSRBootstrap) hooks.onAfterHydrateRouter.call({
|
|
226
|
+
...lifecycleContext,
|
|
227
|
+
phase: 'hydrate',
|
|
228
|
+
router,
|
|
229
|
+
runtimeContext: runtimeState
|
|
230
|
+
});
|
|
231
|
+
return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
232
|
+
children: RouterContent
|
|
233
|
+
}) : RouterContent;
|
|
234
|
+
};
|
|
235
|
+
return RouterWrapper;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
return plugin;
|
|
240
|
+
};
|
|
241
|
+
const runtime_plugin = tanstackRouterPlugin;
|
|
242
|
+
exports["default"] = __webpack_exports__["default"];
|
|
243
|
+
exports.tanstackRouterPlugin = __webpack_exports__.tanstackRouterPlugin;
|
|
244
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
245
|
+
"default",
|
|
246
|
+
"tanstackRouterPlugin"
|
|
247
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
248
|
+
Object.defineProperty(exports, '__esModule', {
|
|
249
|
+
value: true
|
|
250
|
+
});
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
default: ()=>plugin_node,
|
|
28
|
+
tanstackRouterPlugin: ()=>tanstackRouterPlugin
|
|
29
|
+
});
|
|
30
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
31
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
32
|
+
const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
|
|
33
|
+
const node_namespaceObject = require("@modern-js/runtime-utils/node");
|
|
34
|
+
const time_namespaceObject = require("@modern-js/runtime-utils/time");
|
|
35
|
+
const constants_namespaceObject = require("@modern-js/utils/universal/constants");
|
|
36
|
+
const react_router_namespaceObject = require("@tanstack/react-router");
|
|
37
|
+
const server_namespaceObject = require("@tanstack/react-router/ssr/server");
|
|
38
|
+
const external_react_namespaceObject = require("react");
|
|
39
|
+
const external_basepathRewrite_js_namespaceObject = require("./basepathRewrite.js");
|
|
40
|
+
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
41
|
+
const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
|
|
42
|
+
const external_routeTree_js_namespaceObject = require("./routeTree.js");
|
|
43
|
+
const payloadRouter_js_namespaceObject = require("./rsc/payloadRouter.js");
|
|
44
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
45
|
+
const setTanstackRscServerPayload = (payload)=>{
|
|
46
|
+
const storageContext = node_namespaceObject.storage.useContext?.();
|
|
47
|
+
if (storageContext) storageContext.serverPayload = payload;
|
|
48
|
+
};
|
|
49
|
+
function isPreloadableRouteComponent(component) {
|
|
50
|
+
if (!component || 'function' != typeof component) return false;
|
|
51
|
+
const preloadable = component;
|
|
52
|
+
return 'function' == typeof preloadable.load || 'function' == typeof preloadable.preload;
|
|
53
|
+
}
|
|
54
|
+
async function preloadRouteComponent(component) {
|
|
55
|
+
if (!isPreloadableRouteComponent(component)) return;
|
|
56
|
+
if ('function' == typeof component.load) return void await component.load({});
|
|
57
|
+
await component.preload?.({});
|
|
58
|
+
}
|
|
59
|
+
async function preloadMatchedRouteComponents(tanstackRouter) {
|
|
60
|
+
const matches = Array.isArray(tanstackRouter.state.matches) ? tanstackRouter.state.matches : [];
|
|
61
|
+
const routesById = tanstackRouter.routesById || {};
|
|
62
|
+
await Promise.all(matches.map(async (match)=>{
|
|
63
|
+
const routeId = 'string' == typeof match.routeId ? match.routeId : 'string' == typeof match.route?.id ? match.route.id : void 0;
|
|
64
|
+
const route = routeId ? routesById[routeId] : match.route;
|
|
65
|
+
const options = route?.options;
|
|
66
|
+
if (!options) return;
|
|
67
|
+
await Promise.all([
|
|
68
|
+
preloadRouteComponent(options.component),
|
|
69
|
+
preloadRouteComponent(options.pendingComponent),
|
|
70
|
+
preloadRouteComponent(options.errorComponent),
|
|
71
|
+
preloadRouteComponent(options.notFoundComponent)
|
|
72
|
+
]);
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
async function waitForRouterSerialization(tanstackRouter) {
|
|
76
|
+
const serverSsr = tanstackRouter.serverSsr;
|
|
77
|
+
if (!serverSsr || 'function' != typeof serverSsr.onSerializationFinished || serverSsr.isSerializationFinished?.()) return;
|
|
78
|
+
await new Promise((resolve)=>{
|
|
79
|
+
serverSsr.onSerializationFinished?.(resolve);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function htmlEscapeAttr(value) {
|
|
83
|
+
return value.replace(/&/g, '&').replace(/"/g, '"');
|
|
84
|
+
}
|
|
85
|
+
function routerManagedTagToHtml(tag) {
|
|
86
|
+
if (!tag || 'object' != typeof tag) return '';
|
|
87
|
+
const managedTag = tag;
|
|
88
|
+
if (!managedTag || "script" !== managedTag.tag) return '';
|
|
89
|
+
const attrs = managedTag.attrs || {};
|
|
90
|
+
const attrsStr = Object.entries(attrs).filter(([, v])=>null != v && false !== v).map(([k, v])=>{
|
|
91
|
+
const name = 'className' === k ? 'class' : k;
|
|
92
|
+
if (true === v) return name;
|
|
93
|
+
return `${name}="${htmlEscapeAttr(String(v))}"`;
|
|
94
|
+
}).join(' ');
|
|
95
|
+
const open = attrsStr.length ? `<script ${attrsStr}>` : "<script>";
|
|
96
|
+
const children = 'string' == typeof managedTag.children ? managedTag.children : '';
|
|
97
|
+
return `${open}${children}</script>`;
|
|
98
|
+
}
|
|
99
|
+
function routerManagedTagsToHtml(tags) {
|
|
100
|
+
const normalizedTags = Array.isArray(tags) ? tags : [
|
|
101
|
+
tags
|
|
102
|
+
];
|
|
103
|
+
return normalizedTags.map(routerManagedTagToHtml).filter(Boolean);
|
|
104
|
+
}
|
|
105
|
+
function createGetSsrHref(request) {
|
|
106
|
+
const url = new URL(request.url);
|
|
107
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
108
|
+
}
|
|
109
|
+
function stripSyntheticNotFoundRoute(routes) {
|
|
110
|
+
return routes.filter((route)=>!('*' === route.path && !route.id && !route.loader)).map((route)=>{
|
|
111
|
+
if (!route.children?.length) return route;
|
|
112
|
+
return {
|
|
113
|
+
...route,
|
|
114
|
+
children: stripSyntheticNotFoundRoute(route.children)
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function collectRouterErrors(tanstackRouter) {
|
|
119
|
+
const state = tanstackRouter.state;
|
|
120
|
+
const matches = Array.isArray(state.matches) ? state.matches : [];
|
|
121
|
+
const errors = matches.reduce((acc, match)=>{
|
|
122
|
+
if (!match.error) return acc;
|
|
123
|
+
const routeId = 'string' == typeof match.routeId ? match.routeId : 'string' == typeof match.route?.id ? match.route.id : `match-${Object.keys(acc).length}`;
|
|
124
|
+
acc[routeId] = match.error;
|
|
125
|
+
return acc;
|
|
126
|
+
}, {});
|
|
127
|
+
return Object.keys(errors).length > 0 ? errors : void 0;
|
|
128
|
+
}
|
|
129
|
+
const tanstackRouterPlugin = (userConfig = {})=>{
|
|
130
|
+
const plugin = {
|
|
131
|
+
name: '@modern-js/plugin-router-tanstack',
|
|
132
|
+
registryHooks: {
|
|
133
|
+
modifyRoutes: external_hooks_js_namespaceObject.modifyRoutes,
|
|
134
|
+
onAfterCreateRouter: external_hooks_js_namespaceObject.onAfterCreateRouter,
|
|
135
|
+
onAfterHydrateRouter: external_hooks_js_namespaceObject.onAfterHydrateRouter,
|
|
136
|
+
onBeforeCreateRouter: external_hooks_js_namespaceObject.onBeforeCreateRouter,
|
|
137
|
+
onBeforeCreateRoutes: external_hooks_js_namespaceObject.onBeforeCreateRoutes,
|
|
138
|
+
onBeforeHydrateRouter: external_hooks_js_namespaceObject.onBeforeHydrateRouter
|
|
139
|
+
},
|
|
140
|
+
setup: (api)=>{
|
|
141
|
+
api.onBeforeRender(async (context, interrupt)=>{
|
|
142
|
+
const pluginConfig = api.getRuntimeConfig();
|
|
143
|
+
const mergedConfig = (0, merge_namespaceObject.merge)(pluginConfig.router || {}, userConfig);
|
|
144
|
+
const serializationAdapters = (0, context_namespaceObject.getGlobalEnableRsc)() ? (await import("./rsc/server.js")).getTanstackRscSerializationAdapters() : void 0;
|
|
145
|
+
const enableRsc = (0, context_namespaceObject.getGlobalEnableRsc)();
|
|
146
|
+
const { basename = '', routesConfig, createRoutes } = mergedConfig;
|
|
147
|
+
const finalRouteConfig = {
|
|
148
|
+
routes: (0, context_namespaceObject.getGlobalRoutes)(),
|
|
149
|
+
globalApp: (0, context_namespaceObject.getGlobalLayoutApp)(),
|
|
150
|
+
...routesConfig
|
|
151
|
+
};
|
|
152
|
+
if (!finalRouteConfig.routes && !createRoutes) return;
|
|
153
|
+
const hooks = api.getHooks();
|
|
154
|
+
await hooks.onBeforeCreateRoutes.call(context);
|
|
155
|
+
const routeObjects = createRoutes ? createRoutes() : (0, external_utils_js_namespaceObject.createRouteObjectsFromConfig)({
|
|
156
|
+
routesConfig: finalRouteConfig,
|
|
157
|
+
ssrMode: context.ssrContext?.mode
|
|
158
|
+
}) || [];
|
|
159
|
+
const normalizedRouteObjects = createRoutes ? routeObjects : stripSyntheticNotFoundRoute(routeObjects);
|
|
160
|
+
const modifiedRouteObjects = hooks.modifyRoutes.call(normalizedRouteObjects);
|
|
161
|
+
if (!modifiedRouteObjects.length) return;
|
|
162
|
+
const { request, nonce, baseUrl, loaderFailureMode = 'errorBoundary' } = context.ssrContext;
|
|
163
|
+
const _basename = '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, basename || '') : baseUrl;
|
|
164
|
+
const initialHref = createGetSsrHref(request.raw);
|
|
165
|
+
const isRSCNavigation = enableRsc && 'true' === request.raw.headers.get('x-rsc-tree');
|
|
166
|
+
const requestContext = (0, node_namespaceObject.createRequestContext)(context.ssrContext?.loaderContext);
|
|
167
|
+
const controller = new AbortController();
|
|
168
|
+
const ssrRequest = new Request(request.raw.url, {
|
|
169
|
+
method: 'GET',
|
|
170
|
+
headers: request.raw.headers,
|
|
171
|
+
signal: controller.signal
|
|
172
|
+
});
|
|
173
|
+
const routerContext = {
|
|
174
|
+
request: ssrRequest,
|
|
175
|
+
requestContext
|
|
176
|
+
};
|
|
177
|
+
const routeTree = (0, external_routeTree_js_namespaceObject.createRouteTreeFromRouteObjects)(modifiedRouteObjects);
|
|
178
|
+
const history = (0, react_router_namespaceObject.createMemoryHistory)({
|
|
179
|
+
initialEntries: [
|
|
180
|
+
initialHref
|
|
181
|
+
]
|
|
182
|
+
});
|
|
183
|
+
const rewrite = (0, external_basepathRewrite_js_namespaceObject.createModernBasepathRewrite)(_basename);
|
|
184
|
+
const routerLifecycleContext = {
|
|
185
|
+
framework: 'tanstack',
|
|
186
|
+
phase: 'ssr-prepare',
|
|
187
|
+
routes: modifiedRouteObjects,
|
|
188
|
+
runtimeContext: context,
|
|
189
|
+
basename: _basename
|
|
190
|
+
};
|
|
191
|
+
hooks.onBeforeCreateRouter.call(routerLifecycleContext);
|
|
192
|
+
const tanstackRouter = (0, react_router_namespaceObject.createRouter)({
|
|
193
|
+
routeTree,
|
|
194
|
+
history,
|
|
195
|
+
basepath: '/',
|
|
196
|
+
rewrite,
|
|
197
|
+
origin: new URL(request.raw.url).origin,
|
|
198
|
+
ssr: {
|
|
199
|
+
nonce
|
|
200
|
+
},
|
|
201
|
+
context: routerContext,
|
|
202
|
+
...serializationAdapters ? {
|
|
203
|
+
serializationAdapters
|
|
204
|
+
} : {}
|
|
205
|
+
});
|
|
206
|
+
const serverRouter = tanstackRouter;
|
|
207
|
+
(0, server_namespaceObject.attachRouterServerSsrUtils)({
|
|
208
|
+
router: serverRouter,
|
|
209
|
+
manifest: void 0
|
|
210
|
+
});
|
|
211
|
+
const end = (0, time_namespaceObject.time)();
|
|
212
|
+
try {
|
|
213
|
+
await tanstackRouter.load({
|
|
214
|
+
sync: true
|
|
215
|
+
});
|
|
216
|
+
} finally{
|
|
217
|
+
const cost = end();
|
|
218
|
+
context.ssrContext?.onTiming?.(constants_namespaceObject.LOADER_REPORTER_NAME, cost);
|
|
219
|
+
}
|
|
220
|
+
if (serverRouter.state.redirect) {
|
|
221
|
+
const resolved = serverRouter.resolveRedirect ? serverRouter.resolveRedirect(serverRouter.state.redirect) : serverRouter.state.redirect;
|
|
222
|
+
try {
|
|
223
|
+
serverRouter.serverSsr?.cleanup?.();
|
|
224
|
+
} catch {}
|
|
225
|
+
return interrupt(isRSCNavigation ? (0, payloadRouter_js_namespaceObject.handleTanstackRscRedirect)(resolved.headers, _basename, resolved.status) : resolved);
|
|
226
|
+
}
|
|
227
|
+
const routerErrors = collectRouterErrors(tanstackRouter);
|
|
228
|
+
if (routerErrors && 'clientRender' === loaderFailureMode) {
|
|
229
|
+
context.ssrContext?.response.status(200);
|
|
230
|
+
try {
|
|
231
|
+
serverRouter.serverSsr?.cleanup?.();
|
|
232
|
+
} catch {}
|
|
233
|
+
throw Object.values(routerErrors)[0];
|
|
234
|
+
}
|
|
235
|
+
await preloadMatchedRouteComponents(serverRouter);
|
|
236
|
+
context.ssrContext?.response.status(tanstackRouter.state.statusCode);
|
|
237
|
+
await serverRouter.serverSsr?.dehydrate?.();
|
|
238
|
+
await waitForRouterSerialization(serverRouter);
|
|
239
|
+
if (isRSCNavigation) setTanstackRscServerPayload((0, payloadRouter_js_namespaceObject.createTanstackRscServerPayload)(serverRouter, {
|
|
240
|
+
omitClientLoaderData: true
|
|
241
|
+
}));
|
|
242
|
+
const ssrScriptTags = serverRouter.serverSsr?.takeBufferedScripts?.();
|
|
243
|
+
const hydrationScripts = routerManagedTagsToHtml(ssrScriptTags);
|
|
244
|
+
const matchedRouteIds = (0, external_routeTree_js_namespaceObject.getModernRouteIdsFromMatches)(serverRouter);
|
|
245
|
+
const routerServerSnapshot = (0, external_lifecycle_js_namespaceObject.createRouterServerSnapshot)({
|
|
246
|
+
framework: 'tanstack',
|
|
247
|
+
basename: _basename,
|
|
248
|
+
statusCode: tanstackRouter.state.statusCode,
|
|
249
|
+
errors: routerErrors,
|
|
250
|
+
matchedRouteIds,
|
|
251
|
+
hydrationScripts
|
|
252
|
+
});
|
|
253
|
+
const runtimeContext = (0, external_lifecycle_js_namespaceObject.applyRouterServerPrepareResult)(context, {
|
|
254
|
+
snapshot: routerServerSnapshot,
|
|
255
|
+
cleanup: ()=>serverRouter.serverSsr?.cleanup?.(),
|
|
256
|
+
state: {
|
|
257
|
+
framework: 'tanstack',
|
|
258
|
+
basename: _basename,
|
|
259
|
+
instance: serverRouter,
|
|
260
|
+
hydrationScripts,
|
|
261
|
+
matchedRouteIds,
|
|
262
|
+
serverSnapshot: routerServerSnapshot
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
hooks.onAfterCreateRouter.call({
|
|
266
|
+
...routerLifecycleContext,
|
|
267
|
+
router: serverRouter,
|
|
268
|
+
serverSnapshot: routerServerSnapshot,
|
|
269
|
+
runtimeContext
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
api.wrapRoot((App)=>{
|
|
273
|
+
const getRouteApp = ()=>(props)=>{
|
|
274
|
+
const context = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
275
|
+
const router = context.routerInstance ?? context.routerRuntime?.instance;
|
|
276
|
+
if (!router) return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
277
|
+
...props
|
|
278
|
+
}) : null;
|
|
279
|
+
const routerWrapper = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_react_namespaceObject.Suspense, {
|
|
280
|
+
fallback: null,
|
|
281
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.RouterProvider, {
|
|
282
|
+
router: router
|
|
283
|
+
})
|
|
284
|
+
});
|
|
285
|
+
return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
286
|
+
children: routerWrapper
|
|
287
|
+
}) : routerWrapper;
|
|
288
|
+
};
|
|
289
|
+
return getRouteApp();
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
return plugin;
|
|
294
|
+
};
|
|
295
|
+
const plugin_node = tanstackRouterPlugin;
|
|
296
|
+
exports["default"] = __webpack_exports__["default"];
|
|
297
|
+
exports.tanstackRouterPlugin = __webpack_exports__.tanstackRouterPlugin;
|
|
298
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
299
|
+
"default",
|
|
300
|
+
"tanstackRouterPlugin"
|
|
301
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
302
|
+
Object.defineProperty(exports, '__esModule', {
|
|
303
|
+
value: true
|
|
304
|
+
});
|