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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/cjs/cli/index.js +47 -9
  2. package/dist/cjs/cli/routeSplitting.js +87 -0
  3. package/dist/cjs/cli/tanstackTypes.js +230 -63
  4. package/dist/cjs/cli.js +12 -8
  5. package/dist/cjs/runtime/DefaultNotFound.js +9 -5
  6. package/dist/cjs/runtime/basepathRewrite.js +12 -8
  7. package/dist/cjs/runtime/dataMutation.js +9 -5
  8. package/dist/cjs/runtime/hooks.js +9 -5
  9. package/dist/cjs/runtime/hydrationBoundary.js +48 -0
  10. package/dist/cjs/runtime/index.js +330 -74
  11. package/dist/cjs/runtime/lifecycle.js +15 -11
  12. package/dist/cjs/runtime/outlet.js +58 -0
  13. package/dist/cjs/runtime/plugin.js +203 -98
  14. package/dist/cjs/runtime/plugin.node.js +38 -16
  15. package/dist/cjs/runtime/plugin.worker.js +53 -0
  16. package/dist/cjs/runtime/prefetchLink.js +10 -6
  17. package/dist/cjs/runtime/routeTree.js +81 -17
  18. package/dist/cjs/runtime/rsc/ClientSlot.js +9 -5
  19. package/dist/cjs/runtime/rsc/CompositeComponent.js +9 -5
  20. package/dist/cjs/runtime/rsc/ReplayableStream.js +14 -9
  21. package/dist/cjs/runtime/rsc/RscNodeRenderer.js +9 -5
  22. package/dist/cjs/runtime/rsc/SlotContext.js +9 -5
  23. package/dist/cjs/runtime/rsc/client.js +9 -5
  24. package/dist/cjs/runtime/rsc/createRscProxy.js +9 -5
  25. package/dist/cjs/runtime/rsc/index.js +9 -5
  26. package/dist/cjs/runtime/rsc/payloadRouter.js +9 -5
  27. package/dist/cjs/runtime/rsc/server.js +9 -5
  28. package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +9 -5
  29. package/dist/cjs/runtime/rsc/symbols.js +20 -15
  30. package/dist/cjs/runtime/types.js +31 -1
  31. package/dist/cjs/runtime/utils.js +9 -5
  32. package/dist/cjs/runtime.js +9 -5
  33. package/dist/esm/cli/index.mjs +28 -6
  34. package/dist/esm/cli/routeSplitting.mjs +43 -0
  35. package/dist/esm/cli/tanstackTypes.mjs +219 -59
  36. package/dist/esm/runtime/hydrationBoundary.mjs +10 -0
  37. package/dist/esm/runtime/index.mjs +3 -2
  38. package/dist/esm/runtime/outlet.mjs +17 -0
  39. package/dist/esm/runtime/plugin.mjs +197 -96
  40. package/dist/esm/runtime/plugin.node.mjs +30 -12
  41. package/dist/esm/runtime/plugin.worker.mjs +1 -0
  42. package/dist/esm/runtime/prefetchLink.mjs +1 -1
  43. package/dist/esm/runtime/routeTree.mjs +73 -13
  44. package/dist/esm/runtime/types.mjs +7 -0
  45. package/dist/esm-node/cli/index.mjs +28 -6
  46. package/dist/esm-node/cli/routeSplitting.mjs +44 -0
  47. package/dist/esm-node/cli/tanstackTypes.mjs +219 -59
  48. package/dist/esm-node/runtime/hydrationBoundary.mjs +11 -0
  49. package/dist/esm-node/runtime/index.mjs +3 -2
  50. package/dist/esm-node/runtime/outlet.mjs +18 -0
  51. package/dist/esm-node/runtime/plugin.mjs +197 -96
  52. package/dist/esm-node/runtime/plugin.node.mjs +30 -12
  53. package/dist/esm-node/runtime/plugin.worker.mjs +2 -0
  54. package/dist/esm-node/runtime/prefetchLink.mjs +1 -1
  55. package/dist/esm-node/runtime/routeTree.mjs +73 -13
  56. package/dist/esm-node/runtime/types.mjs +7 -0
  57. package/dist/types/cli/index.d.ts +7 -1
  58. package/dist/types/cli/routeSplitting.d.ts +29 -0
  59. package/dist/types/cli/tanstackTypes.d.ts +9 -0
  60. package/dist/types/runtime/hooks.d.ts +9 -24
  61. package/dist/types/runtime/hydrationBoundary.d.ts +2 -0
  62. package/dist/types/runtime/index.d.ts +5 -2
  63. package/dist/types/runtime/outlet.d.ts +2 -0
  64. package/dist/types/runtime/plugin.d.ts +1 -1
  65. package/dist/types/runtime/plugin.node.d.ts +1 -1
  66. package/dist/types/runtime/plugin.worker.d.ts +1 -0
  67. package/dist/types/runtime/types.d.ts +7 -0
  68. package/package.json +20 -20
  69. package/src/cli/index.ts +59 -2
  70. package/src/cli/routeSplitting.ts +81 -0
  71. package/src/cli/tanstackTypes.ts +347 -67
  72. package/src/runtime/hydrationBoundary.tsx +12 -0
  73. package/src/runtime/index.tsx +107 -2
  74. package/src/runtime/outlet.tsx +48 -0
  75. package/src/runtime/plugin.node.tsx +58 -8
  76. package/src/runtime/plugin.tsx +372 -157
  77. package/src/runtime/plugin.worker.tsx +4 -0
  78. package/src/runtime/prefetchLink.tsx +1 -1
  79. package/src/runtime/routeTree.ts +194 -23
  80. package/src/runtime/ssr-shim.d.ts +1 -3
  81. package/src/runtime/types.ts +13 -0
  82. package/tests/router/cli.test.ts +315 -0
  83. package/tests/router/fastDefaults.test.ts +25 -0
  84. package/tests/router/hydrationBoundary.test.tsx +23 -0
  85. package/tests/router/prefetchLink.test.tsx +43 -7
  86. package/tests/router/routeTree.test.ts +416 -1
  87. package/tests/router/tanstackTypes.test.ts +415 -1
@@ -1,5 +1,104 @@
1
- export * from '@tanstack/react-router';
2
- export { useMatch } from '@tanstack/react-router';
1
+ export type * from '@tanstack/react-router';
2
+ export {
3
+ Asset,
4
+ Await,
5
+ Block,
6
+ CatchBoundary,
7
+ CatchNotFound,
8
+ ClientOnly,
9
+ cleanPath,
10
+ composeRewrites,
11
+ createBrowserHistory,
12
+ createControlledPromise,
13
+ createFileRoute,
14
+ createHashHistory,
15
+ createHistory,
16
+ createLazyFileRoute,
17
+ createLazyRoute,
18
+ createLink,
19
+ createMemoryHistory,
20
+ createRootRoute,
21
+ createRootRouteWithContext,
22
+ createRoute,
23
+ createRouteMask,
24
+ createRouter,
25
+ createRouterConfig,
26
+ createSerializationAdapter,
27
+ DEFAULT_PROTOCOL_ALLOWLIST,
28
+ DefaultGlobalNotFound,
29
+ deepEqual,
30
+ defaultParseSearch,
31
+ defaultStringifySearch,
32
+ defer,
33
+ ErrorComponent,
34
+ FileRoute,
35
+ FileRouteLoader,
36
+ functionalUpdate,
37
+ getRouteApi,
38
+ HeadContent,
39
+ interpolatePath,
40
+ isMatch,
41
+ isNotFound,
42
+ isPlainArray,
43
+ isPlainObject,
44
+ isRedirect,
45
+ joinPaths,
46
+ LazyRoute,
47
+ lazyFn,
48
+ lazyRouteComponent,
49
+ linkOptions,
50
+ Match,
51
+ Matches,
52
+ MatchRoute,
53
+ Navigate,
54
+ NotFoundRoute,
55
+ notFound,
56
+ parseSearchWith,
57
+ RootRoute,
58
+ Route,
59
+ RouteApi,
60
+ Router,
61
+ RouterContextProvider,
62
+ RouterProvider,
63
+ reactUse,
64
+ redirect,
65
+ replaceEqualDeep,
66
+ resolvePath,
67
+ retainSearchParams,
68
+ rootRouteId,
69
+ rootRouteWithContext,
70
+ ScriptOnce,
71
+ Scripts,
72
+ ScrollRestoration,
73
+ SearchParamError,
74
+ stringifySearchWith,
75
+ stripSearchParams,
76
+ trimPath,
77
+ trimPathLeft,
78
+ trimPathRight,
79
+ useAwaited,
80
+ useBlocker,
81
+ useCanGoBack,
82
+ useChildMatches,
83
+ useElementScrollRestoration,
84
+ useHydrated,
85
+ useLayoutEffect,
86
+ useLinkProps,
87
+ useLoaderData,
88
+ useLoaderDeps,
89
+ useLocation,
90
+ useMatch,
91
+ useMatches,
92
+ useMatchRoute,
93
+ useNavigate,
94
+ useParams,
95
+ useParentMatches,
96
+ useRouteContext,
97
+ useRouter,
98
+ useRouterState,
99
+ useSearch,
100
+ useTags,
101
+ } from '@tanstack/react-router';
3
102
  export type {
4
103
  Fetcher,
5
104
  FetcherState,
@@ -12,6 +111,7 @@ export {
12
111
  RouteActionResponseError,
13
112
  useFetcher,
14
113
  } from './dataMutation';
114
+ export { Outlet } from './outlet';
15
115
  export {
16
116
  tanstackRouterPlugin,
17
117
  tanstackRouterPlugin as default,
@@ -28,3 +128,8 @@ export type {
28
128
  CompositeComponentProps,
29
129
  } from './rsc/client';
30
130
  export { CompositeComponent } from './rsc/client';
131
+ export type { RouterConfig } from './types';
132
+ export {
133
+ getModernTanstackRouterFastDefaults,
134
+ modernTanstackRouterFastDefaults,
135
+ } from './types';
@@ -0,0 +1,48 @@
1
+ import { Outlet as TanstackOutlet } from '@tanstack/react-router';
2
+ import {
3
+ createElement,
4
+ type ElementType,
5
+ memo,
6
+ type ReactElement,
7
+ } from 'react';
8
+
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) & {
17
+ load?: () => Promise<unknown>;
18
+ preload?: () => Promise<unknown>;
19
+ };
20
+
21
+ export const Outlet = memo(function ModernTanstackOutlet() {
22
+ return <TanstackOutlet />;
23
+ });
24
+
25
+ export function withModernRouteMatchContext(
26
+ component: unknown,
27
+ _routeId: string,
28
+ ): unknown {
29
+ if (component === null || component === undefined) {
30
+ return component;
31
+ }
32
+
33
+ const Component = component as ElementType<RouteComponentProps>;
34
+ const WrappedRouteComponent: WrappedPreloadableComponent = props =>
35
+ createElement(Component, props);
36
+
37
+ const preloadable = component as PreloadableComponent;
38
+ if (typeof preloadable.load === 'function') {
39
+ WrappedRouteComponent.load = preloadable.load.bind(preloadable);
40
+ }
41
+ if (typeof preloadable.preload === 'function') {
42
+ WrappedRouteComponent.preload = preloadable.preload.bind(preloadable);
43
+ } else if (typeof preloadable.load === 'function') {
44
+ WrappedRouteComponent.preload = WrappedRouteComponent.load;
45
+ }
46
+
47
+ return WrappedRouteComponent;
48
+ }
@@ -26,9 +26,9 @@ import {
26
26
  createRouter,
27
27
  RouterProvider,
28
28
  } from '@tanstack/react-router';
29
- import { attachRouterServerSsrUtils } from '@tanstack/react-router/ssr/server';
29
+ import { attachRouterServerSsrUtils } from '@tanstack/router-core/ssr/server';
30
30
  import type React from 'react';
31
- import { Suspense, useContext } from 'react';
31
+ import { useContext } from 'react';
32
32
  import { createModernBasepathRewrite } from './basepathRewrite';
33
33
  import {
34
34
  modifyRoutes as modifyRoutesHook,
@@ -39,6 +39,7 @@ import {
39
39
  onBeforeHydrateRouter as onBeforeHydrateRouterHook,
40
40
  type RouterExtendsHooks,
41
41
  } from './hooks';
42
+ import { wrapTanstackSsrHydrationBoundary } from './hydrationBoundary';
42
43
  import {
43
44
  applyRouterServerPrepareResult,
44
45
  createRouterServerSnapshot,
@@ -52,7 +53,11 @@ import {
52
53
  createTanstackRscServerPayload,
53
54
  handleTanstackRscRedirect,
54
55
  } from './rsc/payloadRouter';
55
- import type { InternalRouterServerSnapshot, RouterConfig } from './types';
56
+ import {
57
+ getModernTanstackRouterFastDefaults,
58
+ type InternalRouterServerSnapshot,
59
+ type RouterConfig,
60
+ } from './types';
56
61
  import { createRouteObjectsFromConfig, urlJoin } from './utils';
57
62
 
58
63
  type ModernTanstackRouterContext = {
@@ -119,6 +124,17 @@ type PreloadableRouteComponent = {
119
124
  preload?: (props?: Record<string, unknown>) => Promise<unknown> | unknown;
120
125
  };
121
126
 
127
+ type ReactLazyRouteComponent = {
128
+ _init?: (payload: unknown) => unknown;
129
+ _payload?: unknown;
130
+ };
131
+
132
+ function isPromiseLike(value: unknown): value is PromiseLike<unknown> {
133
+ return Boolean(
134
+ value && typeof (value as PromiseLike<unknown>).then === 'function',
135
+ );
136
+ }
137
+
122
138
  type TanstackRouterWithServerSsr = AnyRouter & {
123
139
  resolveRedirect?: (redirect: Response) => Response;
124
140
  routesById?: Record<string, RouterRouteWithOptions>;
@@ -149,7 +165,38 @@ function isPreloadableRouteComponent(
149
165
  );
150
166
  }
151
167
 
168
+ function isReactLazyRouteComponent(
169
+ component: unknown,
170
+ ): component is ReactLazyRouteComponent {
171
+ return (
172
+ component !== null &&
173
+ component !== undefined &&
174
+ typeof component === 'object' &&
175
+ typeof (component as ReactLazyRouteComponent)._init === 'function' &&
176
+ '_payload' in component
177
+ );
178
+ }
179
+
180
+ async function preloadReactLazyRouteComponent(
181
+ component: ReactLazyRouteComponent,
182
+ ) {
183
+ try {
184
+ component._init?.(component._payload);
185
+ } catch (thrown) {
186
+ if (!isPromiseLike(thrown)) {
187
+ throw thrown;
188
+ }
189
+ await thrown;
190
+ component._init?.(component._payload);
191
+ }
192
+ }
193
+
152
194
  async function preloadRouteComponent(component: unknown) {
195
+ if (isReactLazyRouteComponent(component)) {
196
+ await preloadReactLazyRouteComponent(component);
197
+ return;
198
+ }
199
+
153
200
  if (!isPreloadableRouteComponent(component)) {
154
201
  return;
155
202
  }
@@ -398,6 +445,7 @@ export const tanstackRouterPlugin = (
398
445
  hooks.onBeforeCreateRouter.call(routerLifecycleContext);
399
446
 
400
447
  const tanstackRouter = createRouter({
448
+ ...getModernTanstackRouterFastDefaults(mergedConfig),
401
449
  routeTree,
402
450
  history,
403
451
  basepath: '/',
@@ -458,9 +506,12 @@ export const tanstackRouterPlugin = (
458
506
  context.ssrContext?.response.status(tanstackRouter.state.statusCode);
459
507
 
460
508
  await serverRouter.serverSsr?.dehydrate?.();
461
- await waitForRouterSerialization(serverRouter);
462
509
 
463
510
  if (isRSCNavigation) {
511
+ // RSC navigations consume the server payload directly. Normal HTML SSR
512
+ // emits the buffered bootstrap script below and must not wait here
513
+ // because Modern's non-streaming hook has not rendered the app yet.
514
+ await waitForRouterSerialization(serverRouter);
464
515
  setTanstackRscServerPayload(
465
516
  createTanstackRscServerPayload(serverRouter, {
466
517
  omitClientLoaderData: true,
@@ -515,10 +566,9 @@ export const tanstackRouterPlugin = (
515
566
  return App ? <App {...props} /> : null;
516
567
  }
517
568
 
518
- const routerWrapper = (
519
- <Suspense fallback={null}>
520
- <RouterProvider router={router as AnyRouter} />
521
- </Suspense>
569
+ const routerWrapper = wrapTanstackSsrHydrationBoundary(
570
+ <RouterProvider router={router as AnyRouter} />,
571
+ true,
522
572
  );
523
573
 
524
574
  return App ? <App>{routerWrapper}</App> : routerWrapper;