@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.103 → 3.2.0-ultramodern.104

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.
@@ -38,7 +38,7 @@ const Outlet = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(function()
38
38
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_router_namespaceObject.Outlet, {});
39
39
  });
40
40
  function withModernRouteMatchContext(component, _routeId) {
41
- if (!component) return component;
41
+ if (null == component) return component;
42
42
  const Component = component;
43
43
  const WrappedRouteComponent = (props)=>/*#__PURE__*/ (0, external_react_namespaceObject.createElement)(Component, props);
44
44
  const preloadable = component;
@@ -95,49 +95,46 @@ function getCachedRouteModule(routeId) {
95
95
  if ("u" < typeof window) return;
96
96
  return window[routeModulesKey]?.[routeId];
97
97
  }
98
- async function preloadHydratedRouteComponents(router) {
98
+ function preloadHydratedRouteComponents(router) {
99
99
  const preloadableRouter = router;
100
100
  const routesById = preloadableRouter.routesById || {};
101
101
  const matches = preloadableRouter.stores.matches.get();
102
- await Promise.all(matches.map((match)=>{
103
- if (!match.routeId) return;
102
+ return Promise.all(matches.map((match)=>{
103
+ if (void 0 === match.routeId || '' === match.routeId) return;
104
104
  const route = routesById[match.routeId];
105
105
  const component = route?.options?.component;
106
106
  const preload = component?.load || component?.preload;
107
107
  if ('function' != typeof preload) return;
108
108
  return Promise.resolve(preload.call(component)).then((routeModule)=>{
109
109
  const modernRouteId = route?.options?.staticData?.modernRouteId;
110
- const resolvedComponent = pickRouteModuleComponent(modernRouteId && getCachedRouteModule(modernRouteId) || routeModule);
111
- if (resolvedComponent && modernRouteId) route.options.component = (0, external_outlet_js_namespaceObject.withModernRouteMatchContext)(resolvedComponent, 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);
112
113
  });
113
- }));
114
+ })).then(()=>void 0);
114
115
  }
115
116
  function getTanstackSsrHydrationRecord(router) {
116
- let hydrationRecord = routerHydrationRecords.get(router);
117
- if (!hydrationRecord) {
118
- hydrationRecord = {
119
- promise: Promise.resolve(),
120
- status: 'pending'
121
- };
122
- routerHydrationRecords.set(router, hydrationRecord);
123
- try {
124
- hydrationRecord.promise = (0, client_namespaceObject.hydrate)(router).then(async (value)=>{
125
- await preloadHydratedRouteComponents(router);
126
- return value;
127
- }).then((value)=>{
128
- hydrationRecord.status = 'fulfilled';
129
- return value;
130
- }, (error)=>{
131
- hydrationRecord.status = 'rejected';
132
- hydrationRecord.error = error;
133
- throw error;
134
- });
135
- } catch (error) {
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)=>{
136
129
  hydrationRecord.status = 'rejected';
137
130
  hydrationRecord.error = error;
138
- hydrationRecord.promise = Promise.reject(error);
139
- hydrationRecord.promise.catch(()=>{});
140
- }
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(()=>{});
141
138
  }
142
139
  return hydrationRecord;
143
140
  }
@@ -264,13 +261,13 @@ const tanstackRouterPlugin = (userConfig = {})=>{
264
261
  });
265
262
  return cachedRouter;
266
263
  };
267
- api.onBeforeRender(async (context)=>{
264
+ api.onBeforeRender((context)=>{
268
265
  const mergedConfig = getMergedConfig();
269
- if ("u" > typeof window && window._SSR_DATA && mergedConfig.unstable_reloadOnURLMismatch) {
266
+ if ("u" > typeof window && void 0 !== window._SSR_DATA && mergedConfig.unstable_reloadOnURLMismatch) {
270
267
  const { ssrContext } = context;
271
268
  const currentPathname = (0, url_namespaceObject.normalizePathname)(window.location.pathname);
272
- const initialPathname = ssrContext?.request?.pathname && (0, url_namespaceObject.normalizePathname)(ssrContext.request.pathname);
273
- 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) {
274
271
  const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
275
272
  console.error(errorMsg);
276
273
  window.location.reload();
@@ -284,14 +281,14 @@ const tanstackRouterPlugin = (userConfig = {})=>{
284
281
  useRouter: react_router_namespaceObject.useRouter
285
282
  };
286
283
  const hasSSRBootstrap = "u" > typeof window && Boolean(window.$_TSR);
287
- if (hasSSRBootstrap && getRouteObjects().length) {
284
+ if (hasSSRBootstrap && getRouteObjects().length > 0) {
288
285
  const runtimeContext = context;
289
286
  const router = getRouter(runtimeContext, getClientBasename(runtimeContext));
290
- if (router) await getTanstackSsrHydrationPromise(router);
287
+ if (null != router) return getTanstackSsrHydrationPromise(router).then(()=>void 0);
291
288
  }
292
289
  });
293
290
  api.wrapRoot((App)=>{
294
- if (!getRouteObjects().length) return App;
291
+ if (0 === getRouteObjects().length) return App;
295
292
  const RouterWrapper = ()=>{
296
293
  const runtimeContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
297
294
  const _basename = getClientBasename(runtimeContext);
@@ -61,7 +61,7 @@ function isPreloadableRouteComponent(component) {
61
61
  return 'function' == typeof preloadable.load || 'function' == typeof preloadable.preload;
62
62
  }
63
63
  function isReactLazyRouteComponent(component) {
64
- return Boolean(component) && 'object' == typeof component && 'function' == typeof component._init && '_payload' in component;
64
+ return null != component && 'object' == typeof component && 'function' == typeof component._init && '_payload' in component;
65
65
  }
66
66
  async function preloadReactLazyRouteComponent(component) {
67
67
  try {
@@ -5,7 +5,7 @@ const outlet_Outlet = /*#__PURE__*/ memo(function() {
5
5
  return /*#__PURE__*/ jsx(Outlet, {});
6
6
  });
7
7
  function withModernRouteMatchContext(component, _routeId) {
8
- if (!component) return component;
8
+ if (null == component) return component;
9
9
  const Component = component;
10
10
  const WrappedRouteComponent = (props)=>/*#__PURE__*/ createElement(Component, props);
11
11
  const preloadable = component;
@@ -62,49 +62,46 @@ function getCachedRouteModule(routeId) {
62
62
  if ("u" < typeof window) return;
63
63
  return window[routeModulesKey]?.[routeId];
64
64
  }
65
- async function preloadHydratedRouteComponents(router) {
65
+ function preloadHydratedRouteComponents(router) {
66
66
  const preloadableRouter = router;
67
67
  const routesById = preloadableRouter.routesById || {};
68
68
  const matches = preloadableRouter.stores.matches.get();
69
- await Promise.all(matches.map((match)=>{
70
- if (!match.routeId) return;
69
+ return Promise.all(matches.map((match)=>{
70
+ if (void 0 === match.routeId || '' === match.routeId) return;
71
71
  const route = routesById[match.routeId];
72
72
  const component = route?.options?.component;
73
73
  const preload = component?.load || component?.preload;
74
74
  if ('function' != typeof preload) return;
75
75
  return Promise.resolve(preload.call(component)).then((routeModule)=>{
76
76
  const modernRouteId = route?.options?.staticData?.modernRouteId;
77
- const resolvedComponent = pickRouteModuleComponent(modernRouteId && getCachedRouteModule(modernRouteId) || routeModule);
78
- if (resolvedComponent && modernRouteId) route.options.component = withModernRouteMatchContext(resolvedComponent, modernRouteId);
77
+ const cachedRouteModule = 'string' == typeof modernRouteId && '' !== modernRouteId ? getCachedRouteModule(modernRouteId) : void 0;
78
+ const resolvedComponent = pickRouteModuleComponent(cachedRouteModule ?? routeModule);
79
+ if (void 0 !== resolvedComponent && 'string' == typeof modernRouteId && '' !== modernRouteId) route.options.component = withModernRouteMatchContext(resolvedComponent, modernRouteId);
79
80
  });
80
- }));
81
+ })).then(()=>void 0);
81
82
  }
82
83
  function getTanstackSsrHydrationRecord(router) {
83
- let hydrationRecord = routerHydrationRecords.get(router);
84
- if (!hydrationRecord) {
85
- hydrationRecord = {
86
- promise: Promise.resolve(),
87
- status: 'pending'
88
- };
89
- routerHydrationRecords.set(router, hydrationRecord);
90
- try {
91
- hydrationRecord.promise = hydrate(router).then(async (value)=>{
92
- await preloadHydratedRouteComponents(router);
93
- return value;
94
- }).then((value)=>{
95
- hydrationRecord.status = 'fulfilled';
96
- return value;
97
- }, (error)=>{
98
- hydrationRecord.status = 'rejected';
99
- hydrationRecord.error = error;
100
- throw error;
101
- });
102
- } catch (error) {
84
+ const existingHydrationRecord = routerHydrationRecords.get(router);
85
+ if (void 0 !== existingHydrationRecord) return existingHydrationRecord;
86
+ const hydrationRecord = {
87
+ promise: Promise.resolve(),
88
+ status: 'pending'
89
+ };
90
+ routerHydrationRecords.set(router, hydrationRecord);
91
+ try {
92
+ hydrationRecord.promise = hydrate(router).then((value)=>preloadHydratedRouteComponents(router).then(()=>value)).then((value)=>{
93
+ hydrationRecord.status = 'fulfilled';
94
+ return value;
95
+ }, (error)=>{
103
96
  hydrationRecord.status = 'rejected';
104
97
  hydrationRecord.error = error;
105
- hydrationRecord.promise = Promise.reject(error);
106
- hydrationRecord.promise.catch(()=>{});
107
- }
98
+ throw error;
99
+ });
100
+ } catch (error) {
101
+ hydrationRecord.status = 'rejected';
102
+ hydrationRecord.error = error;
103
+ hydrationRecord.promise = Promise.reject(error);
104
+ hydrationRecord.promise.catch(()=>{});
108
105
  }
109
106
  return hydrationRecord;
110
107
  }
@@ -231,13 +228,13 @@ const tanstackRouterPlugin = (userConfig = {})=>{
231
228
  });
232
229
  return cachedRouter;
233
230
  };
234
- api.onBeforeRender(async (context)=>{
231
+ api.onBeforeRender((context)=>{
235
232
  const mergedConfig = getMergedConfig();
236
- if ("u" > typeof window && window._SSR_DATA && mergedConfig.unstable_reloadOnURLMismatch) {
233
+ if ("u" > typeof window && void 0 !== window._SSR_DATA && mergedConfig.unstable_reloadOnURLMismatch) {
237
234
  const { ssrContext } = context;
238
235
  const currentPathname = normalizePathname(window.location.pathname);
239
- const initialPathname = ssrContext?.request?.pathname && normalizePathname(ssrContext.request.pathname);
240
- if (initialPathname && initialPathname !== currentPathname) {
236
+ const initialPathname = 'string' == typeof ssrContext?.request?.pathname ? normalizePathname(ssrContext.request.pathname) : void 0;
237
+ if (void 0 !== initialPathname && '' !== initialPathname && initialPathname !== currentPathname) {
241
238
  const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
242
239
  console.error(errorMsg);
243
240
  window.location.reload();
@@ -251,14 +248,14 @@ const tanstackRouterPlugin = (userConfig = {})=>{
251
248
  useRouter: useRouter
252
249
  };
253
250
  const hasSSRBootstrap = "u" > typeof window && Boolean(window.$_TSR);
254
- if (hasSSRBootstrap && getRouteObjects().length) {
251
+ if (hasSSRBootstrap && getRouteObjects().length > 0) {
255
252
  const runtimeContext = context;
256
253
  const router = getRouter(runtimeContext, getClientBasename(runtimeContext));
257
- if (router) await getTanstackSsrHydrationPromise(router);
254
+ if (null != router) return getTanstackSsrHydrationPromise(router).then(()=>void 0);
258
255
  }
259
256
  });
260
257
  api.wrapRoot((App)=>{
261
- if (!getRouteObjects().length) return App;
258
+ if (0 === getRouteObjects().length) return App;
262
259
  const RouterWrapper = ()=>{
263
260
  const runtimeContext = useContext(InternalRuntimeContext);
264
261
  const _basename = getClientBasename(runtimeContext);
@@ -28,7 +28,7 @@ function isPreloadableRouteComponent(component) {
28
28
  return 'function' == typeof preloadable.load || 'function' == typeof preloadable.preload;
29
29
  }
30
30
  function isReactLazyRouteComponent(component) {
31
- return Boolean(component) && 'object' == typeof component && 'function' == typeof component._init && '_payload' in component;
31
+ return null != component && 'object' == typeof component && 'function' == typeof component._init && '_payload' in component;
32
32
  }
33
33
  async function preloadReactLazyRouteComponent(component) {
34
34
  try {
@@ -6,7 +6,7 @@ const outlet_Outlet = /*#__PURE__*/ memo(function() {
6
6
  return /*#__PURE__*/ jsx(Outlet, {});
7
7
  });
8
8
  function withModernRouteMatchContext(component, _routeId) {
9
- if (!component) return component;
9
+ if (null == component) return component;
10
10
  const Component = component;
11
11
  const WrappedRouteComponent = (props)=>/*#__PURE__*/ createElement(Component, props);
12
12
  const preloadable = component;
@@ -63,49 +63,46 @@ function getCachedRouteModule(routeId) {
63
63
  if ("u" < typeof window) return;
64
64
  return window[routeModulesKey]?.[routeId];
65
65
  }
66
- async function preloadHydratedRouteComponents(router) {
66
+ function preloadHydratedRouteComponents(router) {
67
67
  const preloadableRouter = router;
68
68
  const routesById = preloadableRouter.routesById || {};
69
69
  const matches = preloadableRouter.stores.matches.get();
70
- await Promise.all(matches.map((match)=>{
71
- if (!match.routeId) return;
70
+ return Promise.all(matches.map((match)=>{
71
+ if (void 0 === match.routeId || '' === match.routeId) return;
72
72
  const route = routesById[match.routeId];
73
73
  const component = route?.options?.component;
74
74
  const preload = component?.load || component?.preload;
75
75
  if ('function' != typeof preload) return;
76
76
  return Promise.resolve(preload.call(component)).then((routeModule)=>{
77
77
  const modernRouteId = route?.options?.staticData?.modernRouteId;
78
- const resolvedComponent = pickRouteModuleComponent(modernRouteId && getCachedRouteModule(modernRouteId) || routeModule);
79
- if (resolvedComponent && modernRouteId) route.options.component = withModernRouteMatchContext(resolvedComponent, modernRouteId);
78
+ const cachedRouteModule = 'string' == typeof modernRouteId && '' !== modernRouteId ? getCachedRouteModule(modernRouteId) : void 0;
79
+ const resolvedComponent = pickRouteModuleComponent(cachedRouteModule ?? routeModule);
80
+ if (void 0 !== resolvedComponent && 'string' == typeof modernRouteId && '' !== modernRouteId) route.options.component = withModernRouteMatchContext(resolvedComponent, modernRouteId);
80
81
  });
81
- }));
82
+ })).then(()=>void 0);
82
83
  }
83
84
  function getTanstackSsrHydrationRecord(router) {
84
- let hydrationRecord = routerHydrationRecords.get(router);
85
- if (!hydrationRecord) {
86
- hydrationRecord = {
87
- promise: Promise.resolve(),
88
- status: 'pending'
89
- };
90
- routerHydrationRecords.set(router, hydrationRecord);
91
- try {
92
- hydrationRecord.promise = hydrate(router).then(async (value)=>{
93
- await preloadHydratedRouteComponents(router);
94
- return value;
95
- }).then((value)=>{
96
- hydrationRecord.status = 'fulfilled';
97
- return value;
98
- }, (error)=>{
99
- hydrationRecord.status = 'rejected';
100
- hydrationRecord.error = error;
101
- throw error;
102
- });
103
- } catch (error) {
85
+ const existingHydrationRecord = routerHydrationRecords.get(router);
86
+ if (void 0 !== existingHydrationRecord) return existingHydrationRecord;
87
+ const hydrationRecord = {
88
+ promise: Promise.resolve(),
89
+ status: 'pending'
90
+ };
91
+ routerHydrationRecords.set(router, hydrationRecord);
92
+ try {
93
+ hydrationRecord.promise = hydrate(router).then((value)=>preloadHydratedRouteComponents(router).then(()=>value)).then((value)=>{
94
+ hydrationRecord.status = 'fulfilled';
95
+ return value;
96
+ }, (error)=>{
104
97
  hydrationRecord.status = 'rejected';
105
98
  hydrationRecord.error = error;
106
- hydrationRecord.promise = Promise.reject(error);
107
- hydrationRecord.promise.catch(()=>{});
108
- }
99
+ throw error;
100
+ });
101
+ } catch (error) {
102
+ hydrationRecord.status = 'rejected';
103
+ hydrationRecord.error = error;
104
+ hydrationRecord.promise = Promise.reject(error);
105
+ hydrationRecord.promise.catch(()=>{});
109
106
  }
110
107
  return hydrationRecord;
111
108
  }
@@ -232,13 +229,13 @@ const tanstackRouterPlugin = (userConfig = {})=>{
232
229
  });
233
230
  return cachedRouter;
234
231
  };
235
- api.onBeforeRender(async (context)=>{
232
+ api.onBeforeRender((context)=>{
236
233
  const mergedConfig = getMergedConfig();
237
- if ("u" > typeof window && window._SSR_DATA && mergedConfig.unstable_reloadOnURLMismatch) {
234
+ if ("u" > typeof window && void 0 !== window._SSR_DATA && mergedConfig.unstable_reloadOnURLMismatch) {
238
235
  const { ssrContext } = context;
239
236
  const currentPathname = normalizePathname(window.location.pathname);
240
- const initialPathname = ssrContext?.request?.pathname && normalizePathname(ssrContext.request.pathname);
241
- if (initialPathname && initialPathname !== currentPathname) {
237
+ const initialPathname = 'string' == typeof ssrContext?.request?.pathname ? normalizePathname(ssrContext.request.pathname) : void 0;
238
+ if (void 0 !== initialPathname && '' !== initialPathname && initialPathname !== currentPathname) {
242
239
  const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
243
240
  console.error(errorMsg);
244
241
  window.location.reload();
@@ -252,14 +249,14 @@ const tanstackRouterPlugin = (userConfig = {})=>{
252
249
  useRouter: useRouter
253
250
  };
254
251
  const hasSSRBootstrap = "u" > typeof window && Boolean(window.$_TSR);
255
- if (hasSSRBootstrap && getRouteObjects().length) {
252
+ if (hasSSRBootstrap && getRouteObjects().length > 0) {
256
253
  const runtimeContext = context;
257
254
  const router = getRouter(runtimeContext, getClientBasename(runtimeContext));
258
- if (router) await getTanstackSsrHydrationPromise(router);
255
+ if (null != router) return getTanstackSsrHydrationPromise(router).then(()=>void 0);
259
256
  }
260
257
  });
261
258
  api.wrapRoot((App)=>{
262
- if (!getRouteObjects().length) return App;
259
+ if (0 === getRouteObjects().length) return App;
263
260
  const RouterWrapper = ()=>{
264
261
  const runtimeContext = useContext(InternalRuntimeContext);
265
262
  const _basename = getClientBasename(runtimeContext);
@@ -29,7 +29,7 @@ function isPreloadableRouteComponent(component) {
29
29
  return 'function' == typeof preloadable.load || 'function' == typeof preloadable.preload;
30
30
  }
31
31
  function isReactLazyRouteComponent(component) {
32
- return Boolean(component) && 'object' == typeof component && 'function' == typeof component._init && '_payload' in component;
32
+ return null != component && 'object' == typeof component && 'function' == typeof component._init && '_payload' in component;
33
33
  }
34
34
  async function preloadReactLazyRouteComponent(component) {
35
35
  try {
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "modern.js",
19
19
  "tanstack-router"
20
20
  ],
21
- "version": "3.2.0-ultramodern.103",
21
+ "version": "3.2.0-ultramodern.104",
22
22
  "engines": {
23
23
  "node": ">=20"
24
24
  },
@@ -88,13 +88,13 @@
88
88
  "@swc/helpers": "^0.5.23",
89
89
  "@tanstack/react-router": "1.170.11",
90
90
  "@tanstack/router-core": "1.171.9",
91
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.103",
92
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.103",
93
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.103",
94
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.103"
91
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.104",
92
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.104",
93
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.104",
94
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.104"
95
95
  },
96
96
  "peerDependencies": {
97
- "@modern-js/runtime": "3.2.0-ultramodern.103",
97
+ "@modern-js/runtime": "3.2.0-ultramodern.104",
98
98
  "react": "^19.2.6",
99
99
  "react-dom": "^19.2.6"
100
100
  },
@@ -109,9 +109,9 @@
109
109
  "@typescript/native-preview": "7.0.0-dev.20260527.2",
110
110
  "react": "^19.2.6",
111
111
  "react-dom": "^19.2.6",
112
- "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.103",
113
- "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.2.0-ultramodern.103",
114
- "@scripts/rstest-config": "2.66.0"
112
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.104",
113
+ "@scripts/rstest-config": "2.66.0",
114
+ "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.2.0-ultramodern.104"
115
115
  },
116
116
  "sideEffects": false,
117
117
  "publishConfig": {
@@ -1,12 +1,19 @@
1
1
  import { Outlet as TanstackOutlet } from '@tanstack/react-router';
2
2
  import {
3
- type ComponentProps,
4
3
  createElement,
5
4
  type ElementType,
6
5
  memo,
6
+ type ReactElement,
7
7
  } from 'react';
8
8
 
9
- type PreloadableComponent = ElementType<Record<string, unknown>> & {
9
+ type RouteComponentProps = Record<string, unknown>;
10
+ type PreloadableComponent = ElementType<RouteComponentProps> & {
11
+ load?: () => Promise<unknown>;
12
+ preload?: () => Promise<unknown>;
13
+ };
14
+ type WrappedPreloadableComponent = ((
15
+ props: RouteComponentProps,
16
+ ) => ReactElement | null) & {
10
17
  load?: () => Promise<unknown>;
11
18
  preload?: () => Promise<unknown>;
12
19
  };
@@ -19,14 +26,13 @@ export function withModernRouteMatchContext(
19
26
  component: unknown,
20
27
  _routeId: string,
21
28
  ): unknown {
22
- if (!component) {
29
+ if (component === null || component === undefined) {
23
30
  return component;
24
31
  }
25
32
 
26
- const Component = component as ElementType<Record<string, unknown>>;
27
- const WrappedRouteComponent = (
28
- props: ComponentProps<ElementType<Record<string, unknown>>>,
29
- ) => createElement(Component, props);
33
+ const Component = component as ElementType<RouteComponentProps>;
34
+ const WrappedRouteComponent: WrappedPreloadableComponent = props =>
35
+ createElement(Component, props);
30
36
 
31
37
  const preloadable = component as PreloadableComponent;
32
38
  if (typeof preloadable.load === 'function') {
@@ -169,7 +169,8 @@ function isReactLazyRouteComponent(
169
169
  component: unknown,
170
170
  ): component is ReactLazyRouteComponent {
171
171
  return (
172
- Boolean(component) &&
172
+ component !== null &&
173
+ component !== undefined &&
173
174
  typeof component === 'object' &&
174
175
  typeof (component as ReactLazyRouteComponent)._init === 'function' &&
175
176
  '_payload' in component
@@ -208,16 +208,16 @@ function getCachedRouteModule(routeId: string) {
208
208
  ]?.[routeId];
209
209
  }
210
210
 
211
- async function preloadHydratedRouteComponents(router: AnyRouter) {
211
+ function preloadHydratedRouteComponents(router: AnyRouter): Promise<void> {
212
212
  const preloadableRouter = router as RouterWithPreloadableRoutes;
213
213
  const routesById = preloadableRouter.routesById || {};
214
214
  const matches = preloadableRouter.stores.matches.get() as Array<{
215
215
  routeId?: string;
216
216
  }>;
217
217
 
218
- await Promise.all(
218
+ return Promise.all(
219
219
  matches.map(match => {
220
- if (!match.routeId) {
220
+ if (match.routeId === undefined || match.routeId === '') {
221
221
  return undefined;
222
222
  }
223
223
 
@@ -230,10 +230,18 @@ async function preloadHydratedRouteComponents(router: AnyRouter) {
230
230
 
231
231
  return Promise.resolve(preload.call(component)).then(routeModule => {
232
232
  const modernRouteId = route?.options?.staticData?.modernRouteId;
233
+ const cachedRouteModule =
234
+ typeof modernRouteId === 'string' && modernRouteId !== ''
235
+ ? getCachedRouteModule(modernRouteId)
236
+ : undefined;
233
237
  const resolvedComponent = pickRouteModuleComponent(
234
- (modernRouteId && getCachedRouteModule(modernRouteId)) || routeModule,
238
+ cachedRouteModule ?? routeModule,
235
239
  );
236
- if (resolvedComponent && modernRouteId) {
240
+ if (
241
+ resolvedComponent !== undefined &&
242
+ typeof modernRouteId === 'string' &&
243
+ modernRouteId !== ''
244
+ ) {
237
245
  route.options.component = withModernRouteMatchContext(
238
246
  resolvedComponent,
239
247
  modernRouteId,
@@ -241,40 +249,39 @@ async function preloadHydratedRouteComponents(router: AnyRouter) {
241
249
  }
242
250
  });
243
251
  }),
244
- );
252
+ ).then(() => undefined);
245
253
  }
246
254
 
247
255
  function getTanstackSsrHydrationRecord(router: AnyRouter) {
248
- let hydrationRecord = routerHydrationRecords.get(router);
249
- if (!hydrationRecord) {
250
- hydrationRecord = {
251
- promise: Promise.resolve(),
252
- status: 'pending',
253
- };
254
- routerHydrationRecords.set(router, hydrationRecord);
255
- try {
256
- hydrationRecord.promise = hydrateTanstackRouter(router)
257
- .then(async value => {
258
- await preloadHydratedRouteComponents(router);
256
+ const existingHydrationRecord = routerHydrationRecords.get(router);
257
+ if (existingHydrationRecord !== undefined) {
258
+ return existingHydrationRecord;
259
+ }
260
+
261
+ const hydrationRecord: RouterHydrationRecord = {
262
+ promise: Promise.resolve(),
263
+ status: 'pending',
264
+ };
265
+ routerHydrationRecords.set(router, hydrationRecord);
266
+ try {
267
+ hydrationRecord.promise = hydrateTanstackRouter(router)
268
+ .then(value => preloadHydratedRouteComponents(router).then(() => value))
269
+ .then(
270
+ value => {
271
+ hydrationRecord.status = 'fulfilled';
259
272
  return value;
260
- })
261
- .then(
262
- value => {
263
- hydrationRecord.status = 'fulfilled';
264
- return value;
265
- },
266
- error => {
267
- hydrationRecord.status = 'rejected';
268
- hydrationRecord.error = error;
269
- throw error;
270
- },
271
- );
272
- } catch (error) {
273
- hydrationRecord.status = 'rejected';
274
- hydrationRecord.error = error;
275
- hydrationRecord.promise = Promise.reject(error);
276
- hydrationRecord.promise.catch(() => {});
277
- }
273
+ },
274
+ error => {
275
+ hydrationRecord.status = 'rejected';
276
+ hydrationRecord.error = error;
277
+ throw error;
278
+ },
279
+ );
280
+ } catch (error) {
281
+ hydrationRecord.status = 'rejected';
282
+ hydrationRecord.error = error;
283
+ hydrationRecord.promise = Promise.reject(error);
284
+ hydrationRecord.promise.catch(() => {});
278
285
  }
279
286
  return hydrationRecord;
280
287
  }
@@ -466,20 +473,25 @@ export const tanstackRouterPlugin = (
466
473
  return cachedRouter;
467
474
  };
468
475
 
469
- api.onBeforeRender(async context => {
476
+ api.onBeforeRender(context => {
470
477
  const mergedConfig = getMergedConfig();
471
478
  if (
472
479
  typeof window !== 'undefined' &&
473
- (window as { _SSR_DATA?: unknown })._SSR_DATA &&
480
+ (window as { _SSR_DATA?: unknown })._SSR_DATA !== undefined &&
474
481
  mergedConfig.unstable_reloadOnURLMismatch
475
482
  ) {
476
483
  const { ssrContext } = context;
477
484
  const currentPathname = normalizePathname(window.location.pathname);
478
485
  const initialPathname =
479
- ssrContext?.request?.pathname &&
480
- normalizePathname(ssrContext.request.pathname);
481
-
482
- if (initialPathname && initialPathname !== currentPathname) {
486
+ typeof ssrContext?.request?.pathname === 'string'
487
+ ? normalizePathname(ssrContext.request.pathname)
488
+ : undefined;
489
+
490
+ if (
491
+ initialPathname !== undefined &&
492
+ initialPathname !== '' &&
493
+ initialPathname !== currentPathname
494
+ ) {
483
495
  const errorMsg = `The initial URL ${initialPathname} and the URL ${currentPathname} to be hydrated do not match, reload.`;
484
496
  console.error(errorMsg);
485
497
  window.location.reload();
@@ -497,14 +509,14 @@ export const tanstackRouterPlugin = (
497
509
  const hasSSRBootstrap =
498
510
  typeof window !== 'undefined' &&
499
511
  Boolean((window as WindowWithTanstackSsr).$_TSR);
500
- if (hasSSRBootstrap && getRouteObjects().length) {
512
+ if (hasSSRBootstrap && getRouteObjects().length > 0) {
501
513
  const runtimeContext = context as TInternalRuntimeContext;
502
514
  const router = getRouter(
503
515
  runtimeContext,
504
516
  getClientBasename(runtimeContext),
505
517
  );
506
- if (router) {
507
- await getTanstackSsrHydrationPromise(router);
518
+ if (router !== undefined && router !== null) {
519
+ return getTanstackSsrHydrationPromise(router).then(() => undefined);
508
520
  }
509
521
  }
510
522
 
@@ -512,7 +524,7 @@ export const tanstackRouterPlugin = (
512
524
  });
513
525
 
514
526
  api.wrapRoot(App => {
515
- if (!getRouteObjects().length) {
527
+ if (getRouteObjects().length === 0) {
516
528
  return App;
517
529
  }
518
530
 
@@ -523,17 +535,16 @@ export const tanstackRouterPlugin = (
523
535
 
524
536
  const _basename = getClientBasename(runtimeContext);
525
537
 
526
- const routeTree = useMemo(() => {
527
- return getRouteTree();
528
- }, []);
538
+ const routeTree = useMemo(() => getRouteTree(), []);
529
539
 
530
540
  if (!routeTree) {
531
541
  return App ? <App /> : null;
532
542
  }
533
543
 
534
- const router = useMemo(() => {
535
- return getRouter(runtimeContext, _basename);
536
- }, [_basename, routeTree, runtimeContext]);
544
+ const router = useMemo(
545
+ () => getRouter(runtimeContext, _basename),
546
+ [_basename, routeTree, runtimeContext],
547
+ );
537
548
  if (!router) {
538
549
  return App ? <App /> : null;
539
550
  }
@@ -164,7 +164,7 @@ function wrapRouteComponentWithModernContext(
164
164
  route.options.component = withModernRouteMatchContext(
165
165
  component,
166
166
  routeMatchId,
167
- );
167
+ ) as typeof route.options.component;
168
168
  }
169
169
  }
170
170
 
@@ -974,7 +974,7 @@ export function createRouteTreeFromModernRoutes(
974
974
  rootRoute.options.component = withModernRouteMatchContext(
975
975
  rootComponent,
976
976
  rootRouteId,
977
- );
977
+ ) as typeof rootRoute.options.component;
978
978
  }
979
979
 
980
980
  const topLevel = rootModern
@@ -1056,7 +1056,7 @@ export function createRouteTreeFromRouteObjects(
1056
1056
  rootRoute.options.component = withModernRouteMatchContext(
1057
1057
  rootComponent,
1058
1058
  rootRouteId,
1059
- );
1059
+ ) as typeof rootRoute.options.component;
1060
1060
  }
1061
1061
 
1062
1062
  const topLevel = rootLikeRoute