@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.12 → 3.2.0-ultramodern.120
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/cli/index.js +47 -9
- package/dist/cjs/cli/routeSplitting.js +87 -0
- package/dist/cjs/cli/tanstackTypes.js +230 -63
- package/dist/cjs/cli.js +12 -8
- package/dist/cjs/runtime/DefaultNotFound.js +9 -5
- package/dist/cjs/runtime/basepathRewrite.js +12 -8
- package/dist/cjs/runtime/dataMutation.js +9 -5
- package/dist/cjs/runtime/hooks.js +9 -5
- package/dist/cjs/runtime/hydrationBoundary.js +48 -0
- package/dist/cjs/runtime/index.js +330 -74
- package/dist/cjs/runtime/lifecycle.js +15 -11
- package/dist/cjs/runtime/outlet.js +58 -0
- package/dist/cjs/runtime/plugin.js +203 -98
- package/dist/cjs/runtime/plugin.node.js +38 -16
- package/dist/cjs/runtime/plugin.worker.js +53 -0
- package/dist/cjs/runtime/prefetchLink.js +10 -6
- package/dist/cjs/runtime/routeTree.js +81 -17
- package/dist/cjs/runtime/rsc/ClientSlot.js +9 -5
- package/dist/cjs/runtime/rsc/CompositeComponent.js +9 -5
- package/dist/cjs/runtime/rsc/ReplayableStream.js +14 -9
- package/dist/cjs/runtime/rsc/RscNodeRenderer.js +9 -5
- package/dist/cjs/runtime/rsc/SlotContext.js +9 -5
- package/dist/cjs/runtime/rsc/client.js +9 -5
- package/dist/cjs/runtime/rsc/createRscProxy.js +9 -5
- package/dist/cjs/runtime/rsc/index.js +9 -5
- package/dist/cjs/runtime/rsc/payloadRouter.js +9 -5
- package/dist/cjs/runtime/rsc/server.js +9 -5
- package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +9 -5
- package/dist/cjs/runtime/rsc/symbols.js +20 -15
- package/dist/cjs/runtime/types.js +31 -1
- package/dist/cjs/runtime/utils.js +9 -5
- package/dist/cjs/runtime.js +9 -5
- package/dist/esm/cli/index.mjs +28 -6
- package/dist/esm/cli/routeSplitting.mjs +43 -0
- package/dist/esm/cli/tanstackTypes.mjs +219 -59
- package/dist/esm/runtime/hydrationBoundary.mjs +10 -0
- package/dist/esm/runtime/index.mjs +3 -2
- package/dist/esm/runtime/outlet.mjs +17 -0
- package/dist/esm/runtime/plugin.mjs +197 -96
- package/dist/esm/runtime/plugin.node.mjs +30 -12
- package/dist/esm/runtime/plugin.worker.mjs +1 -0
- package/dist/esm/runtime/prefetchLink.mjs +1 -1
- package/dist/esm/runtime/routeTree.mjs +73 -13
- package/dist/esm/runtime/types.mjs +7 -0
- package/dist/esm-node/cli/index.mjs +28 -6
- package/dist/esm-node/cli/routeSplitting.mjs +44 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +219 -59
- package/dist/esm-node/runtime/hydrationBoundary.mjs +11 -0
- package/dist/esm-node/runtime/index.mjs +3 -2
- package/dist/esm-node/runtime/outlet.mjs +18 -0
- package/dist/esm-node/runtime/plugin.mjs +197 -96
- package/dist/esm-node/runtime/plugin.node.mjs +30 -12
- package/dist/esm-node/runtime/plugin.worker.mjs +2 -0
- package/dist/esm-node/runtime/prefetchLink.mjs +1 -1
- package/dist/esm-node/runtime/routeTree.mjs +73 -13
- package/dist/esm-node/runtime/types.mjs +7 -0
- package/dist/types/cli/index.d.ts +7 -1
- package/dist/types/cli/routeSplitting.d.ts +29 -0
- package/dist/types/cli/tanstackTypes.d.ts +9 -0
- package/dist/types/runtime/hooks.d.ts +9 -24
- package/dist/types/runtime/hydrationBoundary.d.ts +2 -0
- package/dist/types/runtime/index.d.ts +5 -2
- package/dist/types/runtime/outlet.d.ts +2 -0
- package/dist/types/runtime/plugin.d.ts +1 -1
- package/dist/types/runtime/plugin.node.d.ts +1 -1
- package/dist/types/runtime/plugin.worker.d.ts +1 -0
- package/dist/types/runtime/types.d.ts +7 -0
- package/package.json +20 -20
- package/src/cli/index.ts +59 -2
- package/src/cli/routeSplitting.ts +81 -0
- package/src/cli/tanstackTypes.ts +347 -67
- package/src/runtime/hydrationBoundary.tsx +12 -0
- package/src/runtime/index.tsx +107 -2
- package/src/runtime/outlet.tsx +48 -0
- package/src/runtime/plugin.node.tsx +58 -8
- package/src/runtime/plugin.tsx +372 -157
- package/src/runtime/plugin.worker.tsx +4 -0
- package/src/runtime/prefetchLink.tsx +1 -1
- package/src/runtime/routeTree.ts +194 -23
- package/src/runtime/ssr-shim.d.ts +1 -3
- package/src/runtime/types.ts +13 -0
- package/tests/router/cli.test.ts +315 -0
- package/tests/router/fastDefaults.test.ts +25 -0
- package/tests/router/hydrationBoundary.test.tsx +23 -0
- package/tests/router/prefetchLink.test.tsx +43 -7
- package/tests/router/routeTree.test.ts +416 -1
- package/tests/router/tanstackTypes.test.ts +415 -1
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -23,12 +27,6 @@ var __webpack_require__ = {};
|
|
|
23
27
|
})();
|
|
24
28
|
var __webpack_exports__ = {};
|
|
25
29
|
__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
30
|
function toHydrationScripts(state) {
|
|
33
31
|
if (state.hydrationScripts?.length) return state.hydrationScripts;
|
|
34
32
|
return state.hydrationScript ? [
|
|
@@ -110,6 +108,12 @@ function applyRouterServerPrepareResult(runtimeContext, result) {
|
|
|
110
108
|
applyRouterRuntimeState(runtimeContext, state);
|
|
111
109
|
return runtimeContext;
|
|
112
110
|
}
|
|
111
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
112
|
+
applyRouterRuntimeState: ()=>applyRouterRuntimeState,
|
|
113
|
+
applyRouterServerPrepareResult: ()=>applyRouterServerPrepareResult,
|
|
114
|
+
createRouterRuntimeState: ()=>createRouterRuntimeState,
|
|
115
|
+
createRouterServerSnapshot: ()=>createRouterServerSnapshot
|
|
116
|
+
});
|
|
113
117
|
exports.applyRouterRuntimeState = __webpack_exports__.applyRouterRuntimeState;
|
|
114
118
|
exports.applyRouterServerPrepareResult = __webpack_exports__.applyRouterServerPrepareResult;
|
|
115
119
|
exports.createRouterRuntimeState = __webpack_exports__.createRouterRuntimeState;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
Outlet: ()=>Outlet,
|
|
32
|
+
withModernRouteMatchContext: ()=>withModernRouteMatchContext
|
|
33
|
+
});
|
|
34
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
35
|
+
const react_router_namespaceObject = require("@tanstack/react-router");
|
|
36
|
+
const external_react_namespaceObject = require("react");
|
|
37
|
+
const Outlet = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(function() {
|
|
38
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.Outlet, {});
|
|
39
|
+
});
|
|
40
|
+
function withModernRouteMatchContext(component, _routeId) {
|
|
41
|
+
if (null == component) return component;
|
|
42
|
+
const Component = component;
|
|
43
|
+
const WrappedRouteComponent = (props)=>/*#__PURE__*/ (0, external_react_namespaceObject.createElement)(Component, props);
|
|
44
|
+
const preloadable = component;
|
|
45
|
+
if ('function' == typeof preloadable.load) WrappedRouteComponent.load = preloadable.load.bind(preloadable);
|
|
46
|
+
if ('function' == typeof preloadable.preload) WrappedRouteComponent.preload = preloadable.preload.bind(preloadable);
|
|
47
|
+
else if ('function' == typeof preloadable.load) WrappedRouteComponent.preload = WrappedRouteComponent.load;
|
|
48
|
+
return WrappedRouteComponent;
|
|
49
|
+
}
|
|
50
|
+
exports.Outlet = __webpack_exports__.Outlet;
|
|
51
|
+
exports.withModernRouteMatchContext = __webpack_exports__.withModernRouteMatchContext;
|
|
52
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
53
|
+
"Outlet",
|
|
54
|
+
"withModernRouteMatchContext"
|
|
55
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
56
|
+
Object.defineProperty(exports, '__esModule', {
|
|
57
|
+
value: true
|
|
58
|
+
});
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -36,9 +40,13 @@ const client_namespaceObject = require("@tanstack/react-router/ssr/client");
|
|
|
36
40
|
const external_react_namespaceObject = require("react");
|
|
37
41
|
const external_basepathRewrite_js_namespaceObject = require("./basepathRewrite.js");
|
|
38
42
|
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
43
|
+
const external_hydrationBoundary_js_namespaceObject = require("./hydrationBoundary.js");
|
|
39
44
|
const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
|
|
45
|
+
const external_outlet_js_namespaceObject = require("./outlet.js");
|
|
46
|
+
const external_prefetchLink_js_namespaceObject = require("./prefetchLink.js");
|
|
40
47
|
const external_routeTree_js_namespaceObject = require("./routeTree.js");
|
|
41
48
|
const client_js_namespaceObject = require("./rsc/client.js");
|
|
49
|
+
const external_types_js_namespaceObject = require("./types.js");
|
|
42
50
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
43
51
|
const BLOCKING_SUBSCRIBE_SYMBOL = Symbol.for('@modern-js/plugin-tanstack:blocking-subscribe');
|
|
44
52
|
const BLOCKING_STATE_SYMBOL = Symbol.for('@modern-js/plugin-tanstack:blocking-state');
|
|
@@ -67,6 +75,82 @@ function wrapRouterSubscribeWithBlockState(router, getBlockNavState) {
|
|
|
67
75
|
};
|
|
68
76
|
target[BLOCKING_SUBSCRIBE_SYMBOL] = true;
|
|
69
77
|
}
|
|
78
|
+
const routerHydrationRecords = new WeakMap();
|
|
79
|
+
const routeModulesKey = '_routeModules';
|
|
80
|
+
function pickRouteModuleComponent(routeModule, seen = new Set()) {
|
|
81
|
+
if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
|
|
82
|
+
if (!routeModule || 'object' != typeof routeModule) return;
|
|
83
|
+
if (seen.has(routeModule)) return;
|
|
84
|
+
seen.add(routeModule);
|
|
85
|
+
const module = routeModule;
|
|
86
|
+
for (const candidate of [
|
|
87
|
+
module.default,
|
|
88
|
+
module.Component
|
|
89
|
+
]){
|
|
90
|
+
const component = pickRouteModuleComponent(candidate, seen);
|
|
91
|
+
if (component) return component;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function getCachedRouteModule(routeId) {
|
|
95
|
+
if ("u" < typeof window) return;
|
|
96
|
+
return window[routeModulesKey]?.[routeId];
|
|
97
|
+
}
|
|
98
|
+
function preloadHydratedRouteComponents(router) {
|
|
99
|
+
const preloadableRouter = router;
|
|
100
|
+
const routesById = preloadableRouter.routesById || {};
|
|
101
|
+
const matches = preloadableRouter.stores.matches.get();
|
|
102
|
+
return Promise.all(matches.map((match)=>{
|
|
103
|
+
if (void 0 === match.routeId || '' === match.routeId) return;
|
|
104
|
+
const route = routesById[match.routeId];
|
|
105
|
+
const component = route?.options?.component;
|
|
106
|
+
const preload = component?.load || component?.preload;
|
|
107
|
+
if ('function' != typeof preload) return;
|
|
108
|
+
return Promise.resolve(preload.call(component)).then((routeModule)=>{
|
|
109
|
+
const modernRouteId = route?.options?.staticData?.modernRouteId;
|
|
110
|
+
const cachedRouteModule = 'string' == typeof modernRouteId && '' !== modernRouteId ? getCachedRouteModule(modernRouteId) : void 0;
|
|
111
|
+
const resolvedComponent = pickRouteModuleComponent(cachedRouteModule ?? routeModule);
|
|
112
|
+
if (void 0 !== resolvedComponent && 'string' == typeof modernRouteId && '' !== modernRouteId) route.options.component = (0, external_outlet_js_namespaceObject.withModernRouteMatchContext)(resolvedComponent, modernRouteId);
|
|
113
|
+
});
|
|
114
|
+
})).then(()=>void 0);
|
|
115
|
+
}
|
|
116
|
+
function getTanstackSsrHydrationRecord(router) {
|
|
117
|
+
const existingHydrationRecord = routerHydrationRecords.get(router);
|
|
118
|
+
if (void 0 !== existingHydrationRecord) return existingHydrationRecord;
|
|
119
|
+
const hydrationRecord = {
|
|
120
|
+
promise: Promise.resolve(),
|
|
121
|
+
status: 'pending'
|
|
122
|
+
};
|
|
123
|
+
routerHydrationRecords.set(router, hydrationRecord);
|
|
124
|
+
try {
|
|
125
|
+
hydrationRecord.promise = (0, client_namespaceObject.hydrate)(router).then((value)=>preloadHydratedRouteComponents(router).then(()=>value)).then((value)=>{
|
|
126
|
+
hydrationRecord.status = 'fulfilled';
|
|
127
|
+
return value;
|
|
128
|
+
}, (error)=>{
|
|
129
|
+
hydrationRecord.status = 'rejected';
|
|
130
|
+
hydrationRecord.error = error;
|
|
131
|
+
throw error;
|
|
132
|
+
});
|
|
133
|
+
} catch (error) {
|
|
134
|
+
hydrationRecord.status = 'rejected';
|
|
135
|
+
hydrationRecord.error = error;
|
|
136
|
+
hydrationRecord.promise = Promise.reject(error);
|
|
137
|
+
hydrationRecord.promise.catch(()=>{});
|
|
138
|
+
}
|
|
139
|
+
return hydrationRecord;
|
|
140
|
+
}
|
|
141
|
+
function getTanstackSsrHydrationPromise(router) {
|
|
142
|
+
return getTanstackSsrHydrationRecord(router).promise;
|
|
143
|
+
}
|
|
144
|
+
function hasTanstackSsrHydrationRecord(router) {
|
|
145
|
+
return routerHydrationRecords.has(router);
|
|
146
|
+
}
|
|
147
|
+
function ModernRouterClient({ router }) {
|
|
148
|
+
const hydrationRecord = getTanstackSsrHydrationRecord(router);
|
|
149
|
+
if ('rejected' === hydrationRecord.status) throw hydrationRecord.error;
|
|
150
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.RouterProvider, {
|
|
151
|
+
router: router
|
|
152
|
+
});
|
|
153
|
+
}
|
|
70
154
|
function stripSyntheticNotFoundRoute(routes) {
|
|
71
155
|
return routes.filter((route)=>!('*' === route.path && !route.id && !route.loader)).map((route)=>{
|
|
72
156
|
if (!route.children?.length) return route;
|
|
@@ -88,112 +172,134 @@ const tanstackRouterPlugin = (userConfig = {})=>{
|
|
|
88
172
|
onBeforeHydrateRouter: external_hooks_js_namespaceObject.onBeforeHydrateRouter
|
|
89
173
|
},
|
|
90
174
|
setup: (api)=>{
|
|
91
|
-
api.
|
|
175
|
+
const hooks = api.getHooks();
|
|
176
|
+
let cachedRouteObjects;
|
|
177
|
+
let cachedRouteTree = null;
|
|
178
|
+
let cachedRouter = null;
|
|
179
|
+
let cachedRouterBasepath = null;
|
|
180
|
+
const getMergedConfig = ()=>{
|
|
92
181
|
const pluginConfig = api.getRuntimeConfig();
|
|
93
|
-
|
|
94
|
-
|
|
182
|
+
return (0, merge_namespaceObject.merge)(pluginConfig.router || {}, userConfig);
|
|
183
|
+
};
|
|
184
|
+
const getRouteObjects = ()=>{
|
|
185
|
+
if (void 0 !== cachedRouteObjects) return cachedRouteObjects;
|
|
186
|
+
const mergedConfig = getMergedConfig();
|
|
187
|
+
const { routesConfig, createRoutes } = mergedConfig;
|
|
188
|
+
const finalRouteConfig = {
|
|
189
|
+
routes: (0, context_namespaceObject.getGlobalRoutes)(),
|
|
190
|
+
globalApp: (0, context_namespaceObject.getGlobalLayoutApp)(),
|
|
191
|
+
...routesConfig
|
|
192
|
+
};
|
|
193
|
+
const routeObjects = createRoutes ? createRoutes() : (0, external_utils_js_namespaceObject.createRouteObjectsFromConfig)({
|
|
194
|
+
routesConfig: finalRouteConfig
|
|
195
|
+
}) || [];
|
|
196
|
+
const normalizedRouteObjects = createRoutes ? routeObjects : stripSyntheticNotFoundRoute(routeObjects);
|
|
197
|
+
cachedRouteObjects = hooks.modifyRoutes.call(normalizedRouteObjects);
|
|
198
|
+
return cachedRouteObjects;
|
|
199
|
+
};
|
|
200
|
+
const getRouteTree = ()=>{
|
|
201
|
+
if (cachedRouteTree) return cachedRouteTree;
|
|
202
|
+
const routeObjects = getRouteObjects();
|
|
203
|
+
if (!routeObjects.length) return null;
|
|
204
|
+
cachedRouteTree = (0, external_routeTree_js_namespaceObject.createRouteTreeFromRouteObjects)(routeObjects, {
|
|
205
|
+
rscPayloadRouter: (0, context_namespaceObject.getGlobalEnableRsc)()
|
|
206
|
+
});
|
|
207
|
+
return cachedRouteTree;
|
|
208
|
+
};
|
|
209
|
+
const selectBasePath = (pathname)=>{
|
|
210
|
+
const { serverBase = [] } = getMergedConfig();
|
|
211
|
+
const match = serverBase.find((baseUrl)=>isSegmentPrefix(pathname, baseUrl));
|
|
212
|
+
return match || '/';
|
|
213
|
+
};
|
|
214
|
+
const getClientBasename = (runtimeContext)=>{
|
|
215
|
+
const { basename = '' } = getMergedConfig();
|
|
216
|
+
const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
|
|
217
|
+
return '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
|
|
218
|
+
};
|
|
219
|
+
const getRouter = (runtimeContext, _basename)=>{
|
|
220
|
+
const routeTree = getRouteTree();
|
|
221
|
+
if (!routeTree) return null;
|
|
222
|
+
const lifecycleContext = {
|
|
223
|
+
framework: 'tanstack',
|
|
224
|
+
phase: 'client-create',
|
|
225
|
+
routes: getRouteObjects(),
|
|
226
|
+
runtimeContext,
|
|
227
|
+
basename: _basename
|
|
228
|
+
};
|
|
229
|
+
hooks.onBeforeCreateRouter.call(lifecycleContext);
|
|
230
|
+
if (cachedRouter && cachedRouterBasepath === _basename) {
|
|
231
|
+
wrapRouterSubscribeWithBlockState(cachedRouter, runtimeContext.unstable_getBlockNavState);
|
|
232
|
+
hooks.onAfterCreateRouter.call({
|
|
233
|
+
...lifecycleContext,
|
|
234
|
+
router: cachedRouter,
|
|
235
|
+
runtimeContext
|
|
236
|
+
});
|
|
237
|
+
return cachedRouter;
|
|
238
|
+
}
|
|
239
|
+
const mergedConfig = getMergedConfig();
|
|
240
|
+
const { supportHtml5History = true } = mergedConfig;
|
|
241
|
+
const history = supportHtml5History ? (0, react_router_namespaceObject.createBrowserHistory)() : (0, react_router_namespaceObject.createHashHistory)();
|
|
242
|
+
const rewrite = (0, external_basepathRewrite_js_namespaceObject.createModernBasepathRewrite)(_basename);
|
|
243
|
+
const serializationAdapters = (0, context_namespaceObject.getGlobalEnableRsc)() ? (0, client_js_namespaceObject.getTanstackRscSerializationAdapters)() : void 0;
|
|
244
|
+
cachedRouter = (0, react_router_namespaceObject.createRouter)({
|
|
245
|
+
...(0, external_types_js_namespaceObject.getModernTanstackRouterFastDefaults)(mergedConfig),
|
|
246
|
+
routeTree,
|
|
247
|
+
basepath: '/',
|
|
248
|
+
rewrite,
|
|
249
|
+
history,
|
|
250
|
+
context: {},
|
|
251
|
+
...serializationAdapters ? {
|
|
252
|
+
serializationAdapters
|
|
253
|
+
} : {}
|
|
254
|
+
});
|
|
255
|
+
cachedRouterBasepath = _basename;
|
|
256
|
+
wrapRouterSubscribeWithBlockState(cachedRouter, runtimeContext.unstable_getBlockNavState);
|
|
257
|
+
hooks.onAfterCreateRouter.call({
|
|
258
|
+
...lifecycleContext,
|
|
259
|
+
router: cachedRouter,
|
|
260
|
+
runtimeContext
|
|
261
|
+
});
|
|
262
|
+
return cachedRouter;
|
|
263
|
+
};
|
|
264
|
+
api.onBeforeRender((context)=>{
|
|
265
|
+
const mergedConfig = getMergedConfig();
|
|
266
|
+
if ("u" > typeof window && void 0 !== window._SSR_DATA && mergedConfig.unstable_reloadOnURLMismatch) {
|
|
95
267
|
const { ssrContext } = context;
|
|
96
268
|
const currentPathname = (0, url_namespaceObject.normalizePathname)(window.location.pathname);
|
|
97
|
-
const initialPathname = ssrContext?.request?.pathname
|
|
98
|
-
if (initialPathname && initialPathname !== currentPathname) {
|
|
269
|
+
const initialPathname = 'string' == typeof ssrContext?.request?.pathname ? (0, url_namespaceObject.normalizePathname)(ssrContext.request.pathname) : void 0;
|
|
270
|
+
if (void 0 !== initialPathname && '' !== initialPathname && initialPathname !== currentPathname) {
|
|
99
271
|
const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
|
|
100
272
|
console.error(errorMsg);
|
|
101
273
|
window.location.reload();
|
|
102
274
|
}
|
|
103
275
|
}
|
|
104
276
|
context.router = {
|
|
277
|
+
Link: external_prefetchLink_js_namespaceObject.Link,
|
|
105
278
|
useMatches: react_router_namespaceObject.useMatches,
|
|
106
279
|
useLocation: react_router_namespaceObject.useLocation,
|
|
107
280
|
useNavigate: react_router_namespaceObject.useNavigate,
|
|
108
281
|
useRouter: react_router_namespaceObject.useRouter
|
|
109
282
|
};
|
|
283
|
+
const hasSSRBootstrap = "u" > typeof window && Boolean(window.$_TSR);
|
|
284
|
+
if (hasSSRBootstrap && getRouteObjects().length > 0) {
|
|
285
|
+
const runtimeContext = context;
|
|
286
|
+
const router = getRouter(runtimeContext, getClientBasename(runtimeContext));
|
|
287
|
+
if (null != router) return getTanstackSsrHydrationPromise(router).then(()=>void 0);
|
|
288
|
+
}
|
|
110
289
|
});
|
|
111
290
|
api.wrapRoot((App)=>{
|
|
112
|
-
|
|
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;
|
|
291
|
+
if (0 === getRouteObjects().length) return App;
|
|
138
292
|
const RouterWrapper = ()=>{
|
|
139
293
|
const runtimeContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
140
|
-
const
|
|
141
|
-
const
|
|
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
|
-
}, []);
|
|
294
|
+
const _basename = getClientBasename(runtimeContext);
|
|
295
|
+
const routeTree = (0, external_react_namespaceObject.useMemo)(()=>getRouteTree(), []);
|
|
151
296
|
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
|
-
}, [
|
|
297
|
+
const router = (0, external_react_namespaceObject.useMemo)(()=>getRouter(runtimeContext, _basename), [
|
|
192
298
|
_basename,
|
|
193
299
|
routeTree,
|
|
194
|
-
supportHtml5History,
|
|
195
300
|
runtimeContext
|
|
196
301
|
]);
|
|
302
|
+
if (!router) return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {}) : null;
|
|
197
303
|
const runtimeState = (0, external_lifecycle_js_namespaceObject.applyRouterRuntimeState)(runtimeContext, {
|
|
198
304
|
framework: 'tanstack',
|
|
199
305
|
basename: _basename,
|
|
@@ -207,30 +313,29 @@ const tanstackRouterPlugin = (userConfig = {})=>{
|
|
|
207
313
|
basename: _basename,
|
|
208
314
|
router
|
|
209
315
|
};
|
|
210
|
-
const hasSSRBootstrap = "u" > typeof window && Boolean(window.$_TSR);
|
|
211
|
-
|
|
316
|
+
const hasSSRBootstrap = "u" > typeof window && (Boolean(window.$_TSR) || hasTanstackSsrHydrationRecord(router));
|
|
317
|
+
const needsRouterClient = hasSSRBootstrap;
|
|
318
|
+
if (needsRouterClient) hooks.onBeforeHydrateRouter.call({
|
|
212
319
|
...lifecycleContext,
|
|
213
320
|
phase: 'hydrate',
|
|
214
321
|
router,
|
|
215
322
|
runtimeContext: runtimeState
|
|
216
323
|
});
|
|
217
|
-
const RouterContent =
|
|
218
|
-
|
|
219
|
-
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(client_namespaceObject.RouterClient, {
|
|
220
|
-
router: router
|
|
221
|
-
})
|
|
324
|
+
const RouterContent = needsRouterClient ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ModernRouterClient, {
|
|
325
|
+
router: router
|
|
222
326
|
}) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.RouterProvider, {
|
|
223
327
|
router: router
|
|
224
328
|
});
|
|
225
|
-
|
|
329
|
+
const HydratableRouterContent = (0, external_hydrationBoundary_js_namespaceObject.wrapTanstackSsrHydrationBoundary)(RouterContent, hasSSRBootstrap);
|
|
330
|
+
if (needsRouterClient) hooks.onAfterHydrateRouter.call({
|
|
226
331
|
...lifecycleContext,
|
|
227
332
|
phase: 'hydrate',
|
|
228
333
|
router,
|
|
229
334
|
runtimeContext: runtimeState
|
|
230
335
|
});
|
|
231
336
|
return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
232
|
-
children:
|
|
233
|
-
}) :
|
|
337
|
+
children: HydratableRouterContent
|
|
338
|
+
}) : HydratableRouterContent;
|
|
234
339
|
};
|
|
235
340
|
return RouterWrapper;
|
|
236
341
|
});
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -34,24 +38,42 @@ const node_namespaceObject = require("@modern-js/runtime-utils/node");
|
|
|
34
38
|
const time_namespaceObject = require("@modern-js/runtime-utils/time");
|
|
35
39
|
const constants_namespaceObject = require("@modern-js/utils/universal/constants");
|
|
36
40
|
const react_router_namespaceObject = require("@tanstack/react-router");
|
|
37
|
-
const server_namespaceObject = require("@tanstack/
|
|
41
|
+
const server_namespaceObject = require("@tanstack/router-core/ssr/server");
|
|
38
42
|
const external_react_namespaceObject = require("react");
|
|
39
43
|
const external_basepathRewrite_js_namespaceObject = require("./basepathRewrite.js");
|
|
40
44
|
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
45
|
+
const external_hydrationBoundary_js_namespaceObject = require("./hydrationBoundary.js");
|
|
41
46
|
const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
|
|
42
47
|
const external_routeTree_js_namespaceObject = require("./routeTree.js");
|
|
43
48
|
const payloadRouter_js_namespaceObject = require("./rsc/payloadRouter.js");
|
|
49
|
+
const external_types_js_namespaceObject = require("./types.js");
|
|
44
50
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
45
51
|
const setTanstackRscServerPayload = (payload)=>{
|
|
46
52
|
const storageContext = node_namespaceObject.storage.useContext?.();
|
|
47
53
|
if (storageContext) storageContext.serverPayload = payload;
|
|
48
54
|
};
|
|
55
|
+
function isPromiseLike(value) {
|
|
56
|
+
return Boolean(value && 'function' == typeof value.then);
|
|
57
|
+
}
|
|
49
58
|
function isPreloadableRouteComponent(component) {
|
|
50
59
|
if (!component || 'function' != typeof component) return false;
|
|
51
60
|
const preloadable = component;
|
|
52
61
|
return 'function' == typeof preloadable.load || 'function' == typeof preloadable.preload;
|
|
53
62
|
}
|
|
63
|
+
function isReactLazyRouteComponent(component) {
|
|
64
|
+
return null != component && 'object' == typeof component && 'function' == typeof component._init && '_payload' in component;
|
|
65
|
+
}
|
|
66
|
+
async function preloadReactLazyRouteComponent(component) {
|
|
67
|
+
try {
|
|
68
|
+
component._init?.(component._payload);
|
|
69
|
+
} catch (thrown) {
|
|
70
|
+
if (!isPromiseLike(thrown)) throw thrown;
|
|
71
|
+
await thrown;
|
|
72
|
+
component._init?.(component._payload);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
54
75
|
async function preloadRouteComponent(component) {
|
|
76
|
+
if (isReactLazyRouteComponent(component)) return void await preloadReactLazyRouteComponent(component);
|
|
55
77
|
if (!isPreloadableRouteComponent(component)) return;
|
|
56
78
|
if ('function' == typeof component.load) return void await component.load({});
|
|
57
79
|
await component.preload?.({});
|
|
@@ -190,6 +212,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
|
|
|
190
212
|
};
|
|
191
213
|
hooks.onBeforeCreateRouter.call(routerLifecycleContext);
|
|
192
214
|
const tanstackRouter = (0, react_router_namespaceObject.createRouter)({
|
|
215
|
+
...(0, external_types_js_namespaceObject.getModernTanstackRouterFastDefaults)(mergedConfig),
|
|
193
216
|
routeTree,
|
|
194
217
|
history,
|
|
195
218
|
basepath: '/',
|
|
@@ -235,10 +258,12 @@ const tanstackRouterPlugin = (userConfig = {})=>{
|
|
|
235
258
|
await preloadMatchedRouteComponents(serverRouter);
|
|
236
259
|
context.ssrContext?.response.status(tanstackRouter.state.statusCode);
|
|
237
260
|
await serverRouter.serverSsr?.dehydrate?.();
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
261
|
+
if (isRSCNavigation) {
|
|
262
|
+
await waitForRouterSerialization(serverRouter);
|
|
263
|
+
setTanstackRscServerPayload((0, payloadRouter_js_namespaceObject.createTanstackRscServerPayload)(serverRouter, {
|
|
264
|
+
omitClientLoaderData: true
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
242
267
|
const ssrScriptTags = serverRouter.serverSsr?.takeBufferedScripts?.();
|
|
243
268
|
const hydrationScripts = routerManagedTagsToHtml(ssrScriptTags);
|
|
244
269
|
const matchedRouteIds = (0, external_routeTree_js_namespaceObject.getModernRouteIdsFromMatches)(serverRouter);
|
|
@@ -276,12 +301,9 @@ const tanstackRouterPlugin = (userConfig = {})=>{
|
|
|
276
301
|
if (!router) return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
277
302
|
...props
|
|
278
303
|
}) : null;
|
|
279
|
-
const routerWrapper = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
router: router
|
|
283
|
-
})
|
|
284
|
-
});
|
|
304
|
+
const routerWrapper = (0, external_hydrationBoundary_js_namespaceObject.wrapTanstackSsrHydrationBoundary)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.RouterProvider, {
|
|
305
|
+
router: router
|
|
306
|
+
}), true);
|
|
285
307
|
return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
286
308
|
children: routerWrapper
|
|
287
309
|
}) : routerWrapper;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.r = (exports1)=>{
|
|
29
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
+
value: 'Module'
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
+
value: true
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
var __webpack_exports__ = {};
|
|
38
|
+
__webpack_require__.r(__webpack_exports__);
|
|
39
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
default: ()=>external_plugin_node_js_default(),
|
|
41
|
+
tanstackRouterPlugin: ()=>external_plugin_node_js_namespaceObject.tanstackRouterPlugin
|
|
42
|
+
});
|
|
43
|
+
const external_plugin_node_js_namespaceObject = require("./plugin.node.js");
|
|
44
|
+
var external_plugin_node_js_default = /*#__PURE__*/ __webpack_require__.n(external_plugin_node_js_namespaceObject);
|
|
45
|
+
exports["default"] = __webpack_exports__["default"];
|
|
46
|
+
exports.tanstackRouterPlugin = __webpack_exports__.tanstackRouterPlugin;
|
|
47
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
48
|
+
"default",
|
|
49
|
+
"tanstackRouterPlugin"
|
|
50
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
51
|
+
Object.defineProperty(exports, '__esModule', {
|
|
52
|
+
value: true
|
|
53
|
+
});
|