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