@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.12 → 3.2.0-ultramodern.121

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.
Files changed (136) hide show
  1. package/dist/cjs/cli/index.js +89 -31
  2. package/dist/cjs/cli/routeSplitting.js +55 -0
  3. package/dist/cjs/cli/tanstackTypes.js +172 -170
  4. package/dist/cjs/cli.js +12 -8
  5. package/dist/cjs/runtime/basepathRewrite.js +12 -8
  6. package/dist/cjs/runtime/dataMutation.js +9 -5
  7. package/dist/cjs/runtime/hooks.js +20 -19
  8. package/dist/cjs/runtime/hydrationBoundary.js +48 -0
  9. package/dist/cjs/runtime/index.js +79 -35
  10. package/dist/cjs/runtime/lifecycle.js +21 -91
  11. package/dist/cjs/runtime/loaderBridge.js +173 -0
  12. package/dist/cjs/runtime/outlet.js +58 -0
  13. package/dist/cjs/runtime/plugin.js +195 -114
  14. package/dist/cjs/runtime/plugin.node.js +45 -45
  15. package/dist/cjs/runtime/plugin.worker.js +53 -0
  16. package/dist/cjs/runtime/pluginCore.js +55 -0
  17. package/dist/cjs/runtime/prefetchLink.js +10 -6
  18. package/dist/cjs/runtime/register.js +56 -0
  19. package/dist/cjs/runtime/routeTree.js +74 -207
  20. package/dist/cjs/runtime/router.js +41 -0
  21. package/dist/cjs/runtime/rsc/ClientSlot.js +9 -5
  22. package/dist/cjs/runtime/rsc/CompositeComponent.js +9 -5
  23. package/dist/cjs/runtime/rsc/ReplayableStream.js +14 -9
  24. package/dist/cjs/runtime/rsc/RscNodeRenderer.js +9 -5
  25. package/dist/cjs/runtime/rsc/SlotContext.js +9 -5
  26. package/dist/cjs/runtime/rsc/client.js +9 -5
  27. package/dist/cjs/runtime/rsc/createRscProxy.js +9 -5
  28. package/dist/cjs/runtime/rsc/index.js +9 -5
  29. package/dist/cjs/runtime/rsc/payloadRouter.js +44 -6
  30. package/dist/cjs/runtime/rsc/server.js +9 -5
  31. package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +9 -5
  32. package/dist/cjs/runtime/rsc/symbols.js +20 -15
  33. package/dist/cjs/runtime/state.js +45 -0
  34. package/dist/cjs/runtime/types.js +31 -1
  35. package/dist/cjs/runtime/utils.js +9 -10
  36. package/dist/cjs/runtime.js +9 -5
  37. package/dist/esm/cli/index.mjs +75 -27
  38. package/dist/esm/cli/routeSplitting.mjs +14 -0
  39. package/dist/esm/cli/tanstackTypes.mjs +158 -160
  40. package/dist/esm/runtime/hooks.mjs +1 -8
  41. package/dist/esm/runtime/hydrationBoundary.mjs +10 -0
  42. package/dist/esm/runtime/index.mjs +5 -2
  43. package/dist/esm/runtime/lifecycle.mjs +1 -82
  44. package/dist/esm/runtime/loaderBridge.mjs +114 -0
  45. package/dist/esm/runtime/outlet.mjs +17 -0
  46. package/dist/esm/runtime/plugin.mjs +191 -114
  47. package/dist/esm/runtime/plugin.node.mjs +40 -44
  48. package/dist/esm/runtime/plugin.worker.mjs +1 -0
  49. package/dist/esm/runtime/pluginCore.mjs +14 -0
  50. package/dist/esm/runtime/prefetchLink.mjs +1 -1
  51. package/dist/esm/runtime/register.mjs +18 -0
  52. package/dist/esm/runtime/routeTree.mjs +59 -193
  53. package/dist/esm/runtime/router.mjs +2 -0
  54. package/dist/esm/runtime/rsc/payloadRouter.mjs +35 -1
  55. package/dist/esm/runtime/state.mjs +7 -0
  56. package/dist/esm/runtime/types.mjs +7 -0
  57. package/dist/esm/runtime/utils.mjs +0 -5
  58. package/dist/esm-node/cli/index.mjs +75 -27
  59. package/dist/esm-node/cli/routeSplitting.mjs +15 -0
  60. package/dist/esm-node/cli/tanstackTypes.mjs +158 -160
  61. package/dist/esm-node/runtime/hooks.mjs +1 -8
  62. package/dist/esm-node/runtime/hydrationBoundary.mjs +11 -0
  63. package/dist/esm-node/runtime/index.mjs +5 -2
  64. package/dist/esm-node/runtime/lifecycle.mjs +1 -82
  65. package/dist/esm-node/runtime/loaderBridge.mjs +115 -0
  66. package/dist/esm-node/runtime/outlet.mjs +18 -0
  67. package/dist/esm-node/runtime/plugin.mjs +191 -114
  68. package/dist/esm-node/runtime/plugin.node.mjs +40 -44
  69. package/dist/esm-node/runtime/plugin.worker.mjs +2 -0
  70. package/dist/esm-node/runtime/pluginCore.mjs +15 -0
  71. package/dist/esm-node/runtime/prefetchLink.mjs +1 -1
  72. package/dist/esm-node/runtime/register.mjs +19 -0
  73. package/dist/esm-node/runtime/routeTree.mjs +59 -193
  74. package/dist/esm-node/runtime/router.mjs +3 -0
  75. package/dist/esm-node/runtime/rsc/payloadRouter.mjs +35 -1
  76. package/dist/esm-node/runtime/state.mjs +8 -0
  77. package/dist/esm-node/runtime/types.mjs +7 -0
  78. package/dist/esm-node/runtime/utils.mjs +0 -5
  79. package/dist/types/cli/index.d.ts +14 -1
  80. package/dist/types/cli/routeSplitting.d.ts +20 -0
  81. package/dist/types/cli/tanstackTypes.d.ts +21 -1
  82. package/dist/types/runtime/hooks.d.ts +8 -33
  83. package/dist/types/runtime/hydrationBoundary.d.ts +2 -0
  84. package/dist/types/runtime/index.d.ts +8 -3
  85. package/dist/types/runtime/lifecycle.d.ts +7 -22
  86. package/dist/types/runtime/loaderBridge.d.ts +48 -0
  87. package/dist/types/runtime/outlet.d.ts +2 -0
  88. package/dist/types/runtime/plugin.d.ts +2 -15
  89. package/dist/types/runtime/plugin.node.d.ts +2 -15
  90. package/dist/types/runtime/plugin.worker.d.ts +1 -0
  91. package/dist/types/runtime/pluginCore.d.ts +21 -0
  92. package/dist/types/runtime/register.d.ts +9 -0
  93. package/dist/types/runtime/routeTree.d.ts +0 -2
  94. package/dist/types/runtime/router.d.ts +14 -0
  95. package/dist/types/runtime/state.d.ts +16 -0
  96. package/dist/types/runtime/types.d.ts +14 -53
  97. package/package.json +42 -40
  98. package/rstest.config.mts +6 -0
  99. package/src/cli/index.ts +162 -23
  100. package/src/cli/routeSplitting.ts +43 -0
  101. package/src/cli/tanstackTypes.ts +331 -187
  102. package/src/runtime/hooks.ts +10 -27
  103. package/src/runtime/hydrationBoundary.tsx +12 -0
  104. package/src/runtime/index.tsx +17 -7
  105. package/src/runtime/lifecycle.ts +16 -151
  106. package/src/runtime/loaderBridge.ts +257 -0
  107. package/src/runtime/outlet.tsx +48 -0
  108. package/src/runtime/plugin.node.tsx +72 -85
  109. package/src/runtime/plugin.tsx +361 -206
  110. package/src/runtime/plugin.worker.tsx +4 -0
  111. package/src/runtime/pluginCore.ts +48 -0
  112. package/src/runtime/prefetchLink.tsx +1 -1
  113. package/src/runtime/register.ts +58 -0
  114. package/src/runtime/routeTree.ts +163 -354
  115. package/src/runtime/router.ts +15 -0
  116. package/src/runtime/rsc/payloadRouter.ts +45 -2
  117. package/src/runtime/ssr-shim.d.ts +1 -3
  118. package/src/runtime/state.ts +29 -0
  119. package/src/runtime/types.ts +32 -66
  120. package/src/runtime/utils.tsx +3 -6
  121. package/tests/router/cli.test.ts +586 -5
  122. package/tests/router/fastDefaults.test.ts +25 -0
  123. package/tests/router/hooks.test.ts +26 -0
  124. package/tests/router/hydrationBoundary.test.tsx +23 -0
  125. package/tests/router/loaderBridge.test.ts +211 -0
  126. package/tests/router/packageSurface.test.ts +24 -0
  127. package/tests/router/prefetchLink.test.tsx +43 -7
  128. package/tests/router/register.test.ts +46 -0
  129. package/tests/router/routeTree.test.ts +381 -81
  130. package/tests/router/rsc.test.tsx +70 -0
  131. package/tests/router/tanstackTypes.test.ts +573 -1
  132. package/dist/cjs/runtime/DefaultNotFound.js +0 -47
  133. package/dist/esm/runtime/DefaultNotFound.mjs +0 -13
  134. package/dist/esm-node/runtime/DefaultNotFound.mjs +0 -14
  135. package/dist/types/runtime/DefaultNotFound.d.ts +0 -2
  136. package/src/runtime/DefaultNotFound.tsx +0 -15
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
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
- });
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
  (()=>{
@@ -29,16 +33,20 @@ __webpack_require__.d(__webpack_exports__, {
29
33
  });
30
34
  const jsx_runtime_namespaceObject = require("react/jsx-runtime");
31
35
  const context_namespaceObject = require("@modern-js/runtime/context");
32
- const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
33
36
  const url_namespaceObject = require("@modern-js/runtime-utils/url");
34
37
  const react_router_namespaceObject = require("@tanstack/react-router");
35
38
  const client_namespaceObject = require("@tanstack/react-router/ssr/client");
36
39
  const external_react_namespaceObject = require("react");
37
40
  const external_basepathRewrite_js_namespaceObject = require("./basepathRewrite.js");
38
41
  const external_hooks_js_namespaceObject = require("./hooks.js");
42
+ const external_hydrationBoundary_js_namespaceObject = require("./hydrationBoundary.js");
39
43
  const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
44
+ const external_outlet_js_namespaceObject = require("./outlet.js");
45
+ const external_pluginCore_js_namespaceObject = require("./pluginCore.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,133 +75,207 @@ function wrapRouterSubscribeWithBlockState(router, getBlockNavState) {
67
75
  };
68
76
  target[BLOCKING_SUBSCRIBE_SYMBOL] = true;
69
77
  }
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
- };
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
77
152
  });
78
153
  }
79
154
  const tanstackRouterPlugin = (userConfig = {})=>{
80
155
  const plugin = {
81
156
  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
- },
157
+ registryHooks: external_hooks_js_namespaceObject.routerProviderRegistryHooks,
90
158
  setup: (api)=>{
159
+ const hooks = api.getHooks();
160
+ let cachedRouteObjects;
161
+ let cachedRouteTree = null;
162
+ let cachedRouter = null;
163
+ let cachedRouterBasepath = null;
164
+ const getMergedConfig = ()=>(0, external_pluginCore_js_namespaceObject.getMergedRouterConfig)(api, userConfig);
165
+ const getRouteObjects = ()=>{
166
+ if (void 0 !== cachedRouteObjects) return cachedRouteObjects;
167
+ const mergedConfig = getMergedConfig();
168
+ const { createRoutes } = mergedConfig;
169
+ const finalRouteConfig = (0, external_pluginCore_js_namespaceObject.getFinalRouteConfig)(mergedConfig);
170
+ const routeObjects = createRoutes ? createRoutes() : (0, external_utils_js_namespaceObject.createRouteObjectsFromConfig)({
171
+ routesConfig: finalRouteConfig
172
+ }) || [];
173
+ cachedRouteObjects = hooks.modifyRoutes.call(routeObjects);
174
+ return cachedRouteObjects;
175
+ };
176
+ const getRouteTree = ()=>{
177
+ if (cachedRouteTree) return cachedRouteTree;
178
+ const routeObjects = getRouteObjects();
179
+ if (!routeObjects.length) return null;
180
+ cachedRouteTree = (0, external_routeTree_js_namespaceObject.createRouteTreeFromRouteObjects)(routeObjects, {
181
+ rscPayloadRouter: (0, context_namespaceObject.getGlobalEnableRsc)()
182
+ });
183
+ return cachedRouteTree;
184
+ };
185
+ const selectBasePath = (pathname)=>{
186
+ const { serverBase = [] } = getMergedConfig();
187
+ const match = serverBase.find((baseUrl)=>isSegmentPrefix(pathname, baseUrl));
188
+ return match || '/';
189
+ };
190
+ const getClientBasename = (runtimeContext)=>{
191
+ const { basename = '' } = getMergedConfig();
192
+ const baseUrl = selectBasePath(location.pathname).replace(/^\/*/, '/');
193
+ return '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, runtimeContext._internalRouterBaseName || basename || '') : baseUrl;
194
+ };
195
+ const getRouter = (runtimeContext, _basename)=>{
196
+ const routeTree = getRouteTree();
197
+ if (!routeTree) return null;
198
+ const lifecycleContext = {
199
+ framework: 'tanstack',
200
+ phase: 'client-create',
201
+ routes: getRouteObjects(),
202
+ runtimeContext,
203
+ basename: _basename
204
+ };
205
+ hooks.onBeforeCreateRouter.call(lifecycleContext);
206
+ if (cachedRouter && cachedRouterBasepath === _basename) {
207
+ wrapRouterSubscribeWithBlockState(cachedRouter, runtimeContext.unstable_getBlockNavState);
208
+ hooks.onAfterCreateRouter.call({
209
+ ...lifecycleContext,
210
+ router: cachedRouter,
211
+ runtimeContext
212
+ });
213
+ return cachedRouter;
214
+ }
215
+ const mergedConfig = getMergedConfig();
216
+ const { supportHtml5History = true } = mergedConfig;
217
+ const history = supportHtml5History ? (0, react_router_namespaceObject.createBrowserHistory)() : (0, react_router_namespaceObject.createHashHistory)();
218
+ const rewrite = (0, external_basepathRewrite_js_namespaceObject.createModernBasepathRewrite)(_basename);
219
+ const serializationAdapters = (0, context_namespaceObject.getGlobalEnableRsc)() ? (0, client_js_namespaceObject.getTanstackRscSerializationAdapters)() : void 0;
220
+ cachedRouter = (0, react_router_namespaceObject.createRouter)({
221
+ ...(0, external_types_js_namespaceObject.getModernTanstackRouterFastDefaults)(mergedConfig),
222
+ routeTree,
223
+ basepath: '/',
224
+ rewrite,
225
+ history,
226
+ context: {},
227
+ ...serializationAdapters ? {
228
+ serializationAdapters
229
+ } : {}
230
+ });
231
+ cachedRouterBasepath = _basename;
232
+ wrapRouterSubscribeWithBlockState(cachedRouter, runtimeContext.unstable_getBlockNavState);
233
+ hooks.onAfterCreateRouter.call({
234
+ ...lifecycleContext,
235
+ router: cachedRouter,
236
+ runtimeContext
237
+ });
238
+ return cachedRouter;
239
+ };
91
240
  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) {
241
+ const mergedConfig = getMergedConfig();
242
+ if ("u" > typeof window && void 0 !== window._SSR_DATA && mergedConfig.unstable_reloadOnURLMismatch) {
95
243
  const { ssrContext } = context;
96
244
  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) {
245
+ const initialPathname = 'string' == typeof ssrContext?.request?.pathname ? (0, url_namespaceObject.normalizePathname)(ssrContext.request.pathname) : void 0;
246
+ if (void 0 !== initialPathname && '' !== initialPathname && initialPathname !== currentPathname) {
99
247
  const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
100
248
  console.error(errorMsg);
101
249
  window.location.reload();
102
250
  }
103
251
  }
104
252
  context.router = {
253
+ Link: external_prefetchLink_js_namespaceObject.Link,
105
254
  useMatches: react_router_namespaceObject.useMatches,
106
255
  useLocation: react_router_namespaceObject.useLocation,
107
256
  useNavigate: react_router_namespaceObject.useNavigate,
108
257
  useRouter: react_router_namespaceObject.useRouter
109
258
  };
259
+ const hasSSRBootstrap = "u" > typeof window && Boolean(window.$_TSR);
260
+ if (hasSSRBootstrap && getRouteObjects().length > 0) {
261
+ const runtimeContext = context;
262
+ const router = getRouter(runtimeContext, getClientBasename(runtimeContext));
263
+ if (null != router) return getTanstackSsrHydrationPromise(router).then(()=>void 0);
264
+ }
110
265
  });
111
266
  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;
267
+ if (0 === getRouteObjects().length) return App;
138
268
  const RouterWrapper = ()=>{
139
269
  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
- }, []);
270
+ const _basename = getClientBasename(runtimeContext);
271
+ const routeTree = (0, external_react_namespaceObject.useMemo)(()=>getRouteTree(), []);
151
272
  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
- }, [
273
+ const router = (0, external_react_namespaceObject.useMemo)(()=>getRouter(runtimeContext, _basename), [
192
274
  _basename,
193
275
  routeTree,
194
- supportHtml5History,
195
276
  runtimeContext
196
277
  ]);
278
+ if (!router) return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {}) : null;
197
279
  const runtimeState = (0, external_lifecycle_js_namespaceObject.applyRouterRuntimeState)(runtimeContext, {
198
280
  framework: 'tanstack',
199
281
  basename: _basename,
@@ -207,30 +289,29 @@ const tanstackRouterPlugin = (userConfig = {})=>{
207
289
  basename: _basename,
208
290
  router
209
291
  };
210
- const hasSSRBootstrap = "u" > typeof window && Boolean(window.$_TSR);
211
- if (hasSSRBootstrap) hooks.onBeforeHydrateRouter.call({
292
+ const hasSSRBootstrap = "u" > typeof window && (Boolean(window.$_TSR) || hasTanstackSsrHydrationRecord(router));
293
+ const needsRouterClient = hasSSRBootstrap;
294
+ if (needsRouterClient) hooks.onBeforeHydrateRouter.call({
212
295
  ...lifecycleContext,
213
296
  phase: 'hydrate',
214
297
  router,
215
298
  runtimeContext: runtimeState
216
299
  });
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
- })
300
+ const RouterContent = needsRouterClient ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ModernRouterClient, {
301
+ router: router
222
302
  }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.RouterProvider, {
223
303
  router: router
224
304
  });
225
- if (hasSSRBootstrap) hooks.onAfterHydrateRouter.call({
305
+ const HydratableRouterContent = (0, external_hydrationBoundary_js_namespaceObject.wrapTanstackSsrHydrationBoundary)(RouterContent, hasSSRBootstrap);
306
+ if (needsRouterClient) hooks.onAfterHydrateRouter.call({
226
307
  ...lifecycleContext,
227
308
  phase: 'hydrate',
228
309
  router,
229
310
  runtimeContext: runtimeState
230
311
  });
231
312
  return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
232
- children: RouterContent
233
- }) : RouterContent;
313
+ children: HydratableRouterContent
314
+ }) : HydratableRouterContent;
234
315
  };
235
316
  return RouterWrapper;
236
317
  });
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
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
- });
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
  (()=>{
@@ -29,29 +33,47 @@ __webpack_require__.d(__webpack_exports__, {
29
33
  });
30
34
  const jsx_runtime_namespaceObject = require("react/jsx-runtime");
31
35
  const context_namespaceObject = require("@modern-js/runtime/context");
32
- const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
33
36
  const node_namespaceObject = require("@modern-js/runtime-utils/node");
34
37
  const time_namespaceObject = require("@modern-js/runtime-utils/time");
35
38
  const constants_namespaceObject = require("@modern-js/utils/universal/constants");
36
39
  const react_router_namespaceObject = require("@tanstack/react-router");
37
- const server_namespaceObject = require("@tanstack/react-router/ssr/server");
40
+ const server_namespaceObject = require("@tanstack/router-core/ssr/server");
38
41
  const external_react_namespaceObject = require("react");
39
42
  const external_basepathRewrite_js_namespaceObject = require("./basepathRewrite.js");
40
43
  const external_hooks_js_namespaceObject = require("./hooks.js");
44
+ const external_hydrationBoundary_js_namespaceObject = require("./hydrationBoundary.js");
41
45
  const external_lifecycle_js_namespaceObject = require("./lifecycle.js");
46
+ const external_pluginCore_js_namespaceObject = require("./pluginCore.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?.({});
@@ -106,15 +128,6 @@ function createGetSsrHref(request) {
106
128
  const url = new URL(request.url);
107
129
  return `${url.pathname}${url.search}${url.hash}`;
108
130
  }
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
131
  function collectRouterErrors(tanstackRouter) {
119
132
  const state = tanstackRouter.state;
120
133
  const matches = Array.isArray(state.matches) ? state.matches : [];
@@ -129,26 +142,14 @@ function collectRouterErrors(tanstackRouter) {
129
142
  const tanstackRouterPlugin = (userConfig = {})=>{
130
143
  const plugin = {
131
144
  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
- },
145
+ registryHooks: external_hooks_js_namespaceObject.routerProviderRegistryHooks,
140
146
  setup: (api)=>{
141
147
  api.onBeforeRender(async (context, interrupt)=>{
142
- const pluginConfig = api.getRuntimeConfig();
143
- const mergedConfig = (0, merge_namespaceObject.merge)(pluginConfig.router || {}, userConfig);
148
+ const mergedConfig = (0, external_pluginCore_js_namespaceObject.getMergedRouterConfig)(api, userConfig);
144
149
  const serializationAdapters = (0, context_namespaceObject.getGlobalEnableRsc)() ? (await import("./rsc/server.js")).getTanstackRscSerializationAdapters() : void 0;
145
150
  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
- };
151
+ const { basename = '', createRoutes } = mergedConfig;
152
+ const finalRouteConfig = (0, external_pluginCore_js_namespaceObject.getFinalRouteConfig)(mergedConfig);
152
153
  if (!finalRouteConfig.routes && !createRoutes) return;
153
154
  const hooks = api.getHooks();
154
155
  await hooks.onBeforeCreateRoutes.call(context);
@@ -156,8 +157,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
156
157
  routesConfig: finalRouteConfig,
157
158
  ssrMode: context.ssrContext?.mode
158
159
  }) || [];
159
- const normalizedRouteObjects = createRoutes ? routeObjects : stripSyntheticNotFoundRoute(routeObjects);
160
- const modifiedRouteObjects = hooks.modifyRoutes.call(normalizedRouteObjects);
160
+ const modifiedRouteObjects = hooks.modifyRoutes.call(routeObjects);
161
161
  if (!modifiedRouteObjects.length) return;
162
162
  const { request, nonce, baseUrl, loaderFailureMode = 'errorBoundary' } = context.ssrContext;
163
163
  const _basename = '/' === baseUrl ? (0, external_utils_js_namespaceObject.urlJoin)(baseUrl, basename || '') : baseUrl;
@@ -190,6 +190,7 @@ const tanstackRouterPlugin = (userConfig = {})=>{
190
190
  };
191
191
  hooks.onBeforeCreateRouter.call(routerLifecycleContext);
192
192
  const tanstackRouter = (0, react_router_namespaceObject.createRouter)({
193
+ ...(0, external_types_js_namespaceObject.getModernTanstackRouterFastDefaults)(mergedConfig),
193
194
  routeTree,
194
195
  history,
195
196
  basepath: '/',
@@ -235,10 +236,12 @@ const tanstackRouterPlugin = (userConfig = {})=>{
235
236
  await preloadMatchedRouteComponents(serverRouter);
236
237
  context.ssrContext?.response.status(tanstackRouter.state.statusCode);
237
238
  await serverRouter.serverSsr?.dehydrate?.();
238
- await waitForRouterSerialization(serverRouter);
239
- if (isRSCNavigation) setTanstackRscServerPayload((0, payloadRouter_js_namespaceObject.createTanstackRscServerPayload)(serverRouter, {
240
- omitClientLoaderData: true
241
- }));
239
+ if (isRSCNavigation) {
240
+ await waitForRouterSerialization(serverRouter);
241
+ setTanstackRscServerPayload((0, payloadRouter_js_namespaceObject.createTanstackRscServerPayload)(serverRouter, {
242
+ omitClientLoaderData: true
243
+ }));
244
+ }
242
245
  const ssrScriptTags = serverRouter.serverSsr?.takeBufferedScripts?.();
243
246
  const hydrationScripts = routerManagedTagsToHtml(ssrScriptTags);
244
247
  const matchedRouteIds = (0, external_routeTree_js_namespaceObject.getModernRouteIdsFromMatches)(serverRouter);
@@ -272,16 +275,13 @@ const tanstackRouterPlugin = (userConfig = {})=>{
272
275
  api.wrapRoot((App)=>{
273
276
  const getRouteApp = ()=>(props)=>{
274
277
  const context = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
275
- const router = context.routerInstance ?? context.routerRuntime?.instance;
278
+ const router = (0, external_lifecycle_js_namespaceObject.getRouterRuntimeState)(context)?.instance;
276
279
  if (!router) return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
277
280
  ...props
278
281
  }) : 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
- });
282
+ const routerWrapper = (0, external_hydrationBoundary_js_namespaceObject.wrapTanstackSsrHydrationBoundary)(/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.RouterProvider, {
283
+ router: router
284
+ }), true);
285
285
  return App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
286
286
  children: routerWrapper
287
287
  }) : 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
+ });