@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.1 → 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.
Files changed (73) hide show
  1. package/dist/cjs/cli/index.js +15 -6
  2. package/dist/cjs/cli/routeSplitting.js +83 -0
  3. package/dist/cjs/cli/tanstackTypes.js +146 -58
  4. package/dist/cjs/runtime/hydrationBoundary.js +44 -0
  5. package/dist/cjs/runtime/index.js +321 -69
  6. package/dist/cjs/runtime/outlet.js +54 -0
  7. package/dist/cjs/runtime/plugin.js +194 -90
  8. package/dist/cjs/runtime/plugin.node.js +29 -11
  9. package/dist/cjs/runtime/plugin.worker.js +49 -0
  10. package/dist/cjs/runtime/routeTree.js +72 -12
  11. package/dist/cjs/runtime/types.js +27 -1
  12. package/dist/esm/cli/index.mjs +7 -7
  13. package/dist/esm/cli/routeSplitting.mjs +43 -0
  14. package/dist/esm/cli/tanstackTypes.mjs +146 -58
  15. package/dist/esm/runtime/hydrationBoundary.mjs +10 -0
  16. package/dist/esm/runtime/index.mjs +3 -2
  17. package/dist/esm/runtime/outlet.mjs +17 -0
  18. package/dist/esm/runtime/plugin.mjs +197 -93
  19. package/dist/esm/runtime/plugin.node.mjs +30 -12
  20. package/dist/esm/runtime/plugin.worker.mjs +1 -0
  21. package/dist/esm/runtime/routeTree.mjs +73 -13
  22. package/dist/esm/runtime/types.mjs +7 -0
  23. package/dist/esm-node/cli/index.mjs +7 -7
  24. package/dist/esm-node/cli/routeSplitting.mjs +44 -0
  25. package/dist/esm-node/cli/tanstackTypes.mjs +146 -58
  26. package/dist/esm-node/runtime/hydrationBoundary.mjs +11 -0
  27. package/dist/esm-node/runtime/index.mjs +3 -2
  28. package/dist/esm-node/runtime/outlet.mjs +18 -0
  29. package/dist/esm-node/runtime/plugin.mjs +197 -93
  30. package/dist/esm-node/runtime/plugin.node.mjs +30 -12
  31. package/dist/esm-node/runtime/plugin.worker.mjs +2 -0
  32. package/dist/esm-node/runtime/routeTree.mjs +73 -13
  33. package/dist/esm-node/runtime/types.mjs +7 -0
  34. package/dist/types/cli/index.d.ts +4 -0
  35. package/dist/types/cli/routeSplitting.d.ts +29 -0
  36. package/dist/types/runtime/hydrationBoundary.d.ts +2 -0
  37. package/dist/types/runtime/index.d.ts +5 -2
  38. package/dist/types/runtime/outlet.d.ts +2 -0
  39. package/dist/types/runtime/plugin.d.ts +1 -1
  40. package/dist/types/runtime/plugin.node.d.ts +1 -1
  41. package/dist/types/runtime/plugin.worker.d.ts +1 -0
  42. package/dist/types/runtime/types.d.ts +7 -0
  43. package/package.json +14 -14
  44. package/src/cli/index.ts +32 -18
  45. package/src/cli/routeSplitting.ts +81 -0
  46. package/src/cli/tanstackTypes.ts +217 -67
  47. package/src/runtime/basepathRewrite.ts +1 -0
  48. package/src/runtime/dataMutation.tsx +1 -0
  49. package/src/runtime/hydrationBoundary.tsx +12 -0
  50. package/src/runtime/index.tsx +107 -2
  51. package/src/runtime/lifecycle.ts +1 -0
  52. package/src/runtime/outlet.tsx +42 -0
  53. package/src/runtime/plugin.node.tsx +58 -8
  54. package/src/runtime/plugin.tsx +354 -149
  55. package/src/runtime/plugin.worker.tsx +4 -0
  56. package/src/runtime/routeTree.ts +195 -23
  57. package/src/runtime/rsc/ClientSlot.tsx +1 -0
  58. package/src/runtime/rsc/CompositeComponent.tsx +1 -0
  59. package/src/runtime/rsc/ReplayableStream.ts +1 -0
  60. package/src/runtime/rsc/RscNodeRenderer.tsx +1 -0
  61. package/src/runtime/rsc/client.tsx +2 -3
  62. package/src/runtime/rsc/createRscProxy.tsx +1 -0
  63. package/src/runtime/rsc/payloadRouter.ts +1 -0
  64. package/src/runtime/rsc/server.tsx +1 -0
  65. package/src/runtime/rsc/slotUsageSanitizer.ts +1 -0
  66. package/src/runtime/ssr-shim.d.ts +1 -3
  67. package/src/runtime/types.ts +13 -0
  68. package/src/runtime/utils.tsx +1 -0
  69. package/tests/router/cli.test.ts +239 -0
  70. package/tests/router/fastDefaults.test.ts +25 -0
  71. package/tests/router/hydrationBoundary.test.tsx +23 -0
  72. package/tests/router/routeTree.test.ts +416 -1
  73. package/tests/router/tanstackTypes.test.ts +184 -0
@@ -1,6 +1,8 @@
1
1
  import "node:module";
2
- import { createRootRoute, createRoute, notFound, redirect } from "@tanstack/react-router";
2
+ import { createRootRoute, createRoute, notFound, redirect, rootRouteId } from "@tanstack/react-router";
3
+ import { createElement } from "react";
3
4
  import { DefaultNotFound } from "./DefaultNotFound.mjs";
5
+ import { withModernRouteMatchContext } from "./outlet.mjs";
4
6
  import { isTanstackRscPayloadNavigationEnabled, loadTanstackRscRouteData } from "./rsc/payloadRouter.mjs";
5
7
  function createTanstackRoute(options) {
6
8
  return createRoute(options);
@@ -8,6 +10,10 @@ function createTanstackRoute(options) {
8
10
  function createTanstackRootRoute(options) {
9
11
  return createRootRoute(options);
10
12
  }
13
+ function wrapRouteComponentWithModernContext(route, component, routeId) {
14
+ const routeMatchId = routeId || route.id;
15
+ if (component && routeMatchId) route.options.component = withModernRouteMatchContext(component, routeMatchId);
16
+ }
11
17
  function toTanstackPath(pathname) {
12
18
  return pathname.split('/').map((segment)=>{
13
19
  if (!segment) return segment;
@@ -55,6 +61,40 @@ function normalizeModernLoaderResponse(result) {
55
61
  }
56
62
  return normalizeModernLoaderResult(result);
57
63
  }
64
+ function pickRouteModuleComponent(routeModule, seen = new Set()) {
65
+ if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
66
+ if (!routeModule || 'object' != typeof routeModule) return;
67
+ if (seen.has(routeModule)) return;
68
+ seen.add(routeModule);
69
+ const module = routeModule;
70
+ for (const candidate of [
71
+ module.default,
72
+ module.Component
73
+ ]){
74
+ const component = pickRouteModuleComponent(candidate, seen);
75
+ if (component) return component;
76
+ }
77
+ }
78
+ function createServerLazyImportComponent(lazyImport, fallbackComponent) {
79
+ if ("u" > typeof document) return fallbackComponent;
80
+ let resolvedComponent;
81
+ let pendingLoad;
82
+ const load = async ()=>{
83
+ if (resolvedComponent) return resolvedComponent;
84
+ const routeModule = await lazyImport();
85
+ const component = pickRouteModuleComponent(routeModule);
86
+ if (component) resolvedComponent = component;
87
+ return resolvedComponent;
88
+ };
89
+ const Component = (props)=>{
90
+ if (resolvedComponent) return createElement(resolvedComponent, props);
91
+ pendingLoad ||= load();
92
+ throw pendingLoad;
93
+ };
94
+ Component.load = load;
95
+ Component.preload = load;
96
+ return Component;
97
+ }
58
98
  function isAbsoluteUrl(value) {
59
99
  try {
60
100
  new URL(value);
@@ -127,7 +167,7 @@ function wrapModernLoader(modernRoute, modernLoader, revalidationState, options
127
167
  const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
128
168
  const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
129
169
  const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
130
- const request = baseRequest ? new Request(baseRequest, {
170
+ const request = void 0 !== baseRequest ? new Request(baseRequest, {
131
171
  signal
132
172
  }) : createModernRequest(href, signal);
133
173
  const params = mapParamsForModernLoader({
@@ -192,7 +232,7 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
192
232
  const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
193
233
  const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
194
234
  const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
195
- const request = baseRequest ? new Request(baseRequest, {
235
+ const request = void 0 !== baseRequest ? new Request(baseRequest, {
196
236
  signal
197
237
  }) : createModernRequest(href, signal);
198
238
  const params = mapParamsForRouteObjectLoader({
@@ -229,10 +269,18 @@ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
229
269
  }
230
270
  function toRouteComponent(routeObject) {
231
271
  const route = routeObject;
272
+ const lazyImport = 'function' == typeof route.lazyImport ? route.lazyImport : void 0;
273
+ const fallbackComponent = route.Component ? route.Component : route.element ? ()=>route.element : void 0;
274
+ if (lazyImport && fallbackComponent) return createServerLazyImportComponent(lazyImport, fallbackComponent);
232
275
  if (route.Component) return route.Component;
233
276
  const element = route.element;
234
277
  if (element) return ()=>element;
235
278
  }
279
+ function toModernRouteComponent(route) {
280
+ const component = route.component || void 0;
281
+ if ('function' == typeof route.lazyImport && component) return createServerLazyImportComponent(route.lazyImport, component);
282
+ return component;
283
+ }
236
284
  function toErrorComponent(routeObject) {
237
285
  const route = routeObject;
238
286
  if (route.ErrorBoundary) return route.ErrorBoundary;
@@ -270,12 +318,14 @@ function createRouteFromRouteObject(opts) {
270
318
  const shouldRevalidate = modernRouteObject.shouldRevalidate;
271
319
  const shouldReload = createModernShouldReload(shouldRevalidate, revalidationState);
272
320
  const stableFallbackId = routeObject.id || modernRouteObject.file || routeObject.path || 'pathless';
321
+ const component = toRouteComponent(routeObject);
273
322
  const base = {
274
323
  getParentRoute: ()=>parent,
275
- component: toRouteComponent(routeObject),
324
+ component,
276
325
  pendingComponent: toPendingComponent(routeObject),
277
326
  errorComponent: toErrorComponent(routeObject),
278
- wrapInSuspense: true,
327
+ validateSearch: modernRouteObject.validateSearch,
328
+ loaderDeps: modernRouteObject.loaderDeps,
279
329
  staticData: createRouteStaticData({
280
330
  modernRouteId: routeObject.id,
281
331
  modernRouteAction: modernRouteObject.action,
@@ -294,6 +344,7 @@ function createRouteFromRouteObject(opts) {
294
344
  if (isRouteObjectPathlessLayout(routeObject)) base.id = stableFallbackId;
295
345
  else base.path = routeObject.index ? '/' : toTanstackPath(routeObject.path || '');
296
346
  const route = createTanstackRoute(base);
347
+ wrapRouteComponentWithModernContext(route, component, routeObject.id);
297
348
  const children = routeObject.children;
298
349
  if (children && children.length > 0) {
299
350
  const childRoutes = children.map((child)=>createRouteFromRouteObject({
@@ -313,7 +364,7 @@ function createRouteFromModernRoute(opts) {
313
364
  const stableFallbackId = modernId || route._component || route.filename || route.data || ('function' == typeof route.loader ? route.id : void 0);
314
365
  const pendingComponent = route.loading || route.pendingComponent;
315
366
  const errorComponent = route.error || route.errorComponent;
316
- const component = route.component;
367
+ const component = toModernRouteComponent(route);
317
368
  const modernLoader = route.loader;
318
369
  const modernAction = route.action;
319
370
  const modernShouldRevalidate = route.shouldRevalidate;
@@ -325,7 +376,8 @@ function createRouteFromModernRoute(opts) {
325
376
  component: component || void 0,
326
377
  pendingComponent: pendingComponent || void 0,
327
378
  errorComponent: errorComponent || void 0,
328
- wrapInSuspense: true,
379
+ validateSearch: route.validateSearch,
380
+ loaderDeps: route.loaderDeps,
329
381
  staticData: createRouteStaticData({
330
382
  modernRouteId: modernId,
331
383
  modernRouteAction: modernAction,
@@ -347,6 +399,7 @@ function createRouteFromModernRoute(opts) {
347
399
  base.path = isIndexRoute ? '/' : toTanstackPath(rawPath || '');
348
400
  }
349
401
  const tanstackRoute = createTanstackRoute(base);
402
+ wrapRouteComponentWithModernContext(tanstackRoute, component, modernId);
350
403
  const children = route.children;
351
404
  if (children && children.length > 0) {
352
405
  const childRoutes = children.map((child)=>createRouteFromModernRoute({
@@ -360,7 +413,7 @@ function createRouteFromModernRoute(opts) {
360
413
  }
361
414
  function createRouteTreeFromModernRoutes(routes, options = {}) {
362
415
  const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
363
- const rootComponent = rootModern?.component;
416
+ const rootComponent = rootModern ? toModernRouteComponent(rootModern) : void 0;
364
417
  const pendingComponent = rootModern?.loading;
365
418
  const errorComponent = rootModern?.error;
366
419
  const rootLoader = rootModern?.loader;
@@ -373,7 +426,8 @@ function createRouteTreeFromModernRoutes(routes, options = {}) {
373
426
  component: rootComponent || void 0,
374
427
  pendingComponent: pendingComponent || void 0,
375
428
  errorComponent: errorComponent || void 0,
376
- wrapInSuspense: true,
429
+ validateSearch: rootModern?.validateSearch,
430
+ loaderDeps: rootModern?.loaderDeps,
377
431
  notFoundComponent: DefaultNotFound,
378
432
  staticData: createRouteStaticData({
379
433
  modernRouteId: rootModernId,
@@ -391,6 +445,7 @@ function createRouteTreeFromModernRoutes(routes, options = {}) {
391
445
  if (rootShouldReload) rootRouteOptions.shouldReload = rootShouldReload;
392
446
  if (rootModern?.inValidSSRRoute) rootRouteOptions.ssr = false;
393
447
  const rootRoute = createTanstackRootRoute(rootRouteOptions);
448
+ if (rootComponent) rootRoute.options.component = withModernRouteMatchContext(rootComponent, rootRouteId);
394
449
  const topLevel = rootModern ? rootModern.children || [] : routes;
395
450
  const childRoutes = topLevel.map((child)=>createRouteFromModernRoute({
396
451
  options,
@@ -408,11 +463,13 @@ function createRouteTreeFromRouteObjects(routes, options = {}) {
408
463
  const rootRevalidationState = {};
409
464
  const rootShouldRevalidate = rootLikeRoute?.shouldRevalidate;
410
465
  const rootShouldReload = createModernShouldReload(rootShouldRevalidate, rootRevalidationState);
466
+ const rootComponent = rootLikeRoute ? toRouteComponent(rootLikeRoute) : void 0;
411
467
  const rootRouteOptions = {
412
- component: rootLikeRoute ? toRouteComponent(rootLikeRoute) : void 0,
468
+ component: rootComponent,
413
469
  pendingComponent: rootLikeRoute ? toPendingComponent(rootLikeRoute) : void 0,
414
470
  errorComponent: rootLikeRoute ? toErrorComponent(rootLikeRoute) : void 0,
415
- wrapInSuspense: true,
471
+ validateSearch: rootLikeRoute?.validateSearch,
472
+ loaderDeps: rootLikeRoute?.loaderDeps,
416
473
  notFoundComponent: DefaultNotFound,
417
474
  staticData: createRouteStaticData({
418
475
  modernRouteId: rootLikeRoute?.id,
@@ -430,6 +487,7 @@ function createRouteTreeFromRouteObjects(routes, options = {}) {
430
487
  if (rootShouldReload) rootRouteOptions.shouldReload = rootShouldReload;
431
488
  if (rootLikeRoute?.inValidSSRRoute) rootRouteOptions.ssr = false;
432
489
  const rootRoute = createTanstackRootRoute(rootRouteOptions);
490
+ if (rootComponent) rootRoute.options.component = withModernRouteMatchContext(rootComponent, rootRouteId);
433
491
  const topLevel = rootLikeRoute ? [
434
492
  ...rootLikeRoute.children || [],
435
493
  ...routes.filter((route)=>route !== rootLikeRoute)
@@ -444,9 +502,11 @@ function createRouteTreeFromRouteObjects(routes, options = {}) {
444
502
  }
445
503
  function getModernRouteIdsFromMatches(router) {
446
504
  const matches = router.state.matches || [];
505
+ const routesById = router.routesById;
447
506
  const ids = matches.map((match)=>{
448
- const route = match.route;
449
- return route?.options?.staticData?.modernRouteId;
507
+ const normalizedMatch = match;
508
+ const routeId = 'string' == typeof normalizedMatch.routeId ? normalizedMatch.routeId : void 0;
509
+ return normalizedMatch.route?.options?.staticData?.modernRouteId ?? (routeId ? routesById?.[routeId]?.options?.staticData?.modernRouteId : void 0);
450
510
  }).filter((id)=>'string' == typeof id);
451
511
  return Array.from(new Set(ids));
452
512
  }
@@ -1 +1,8 @@
1
1
  import "node:module";
2
+ const modernTanstackRouterFastDefaults = {
3
+ defaultStructuralSharing: true
4
+ };
5
+ const getModernTanstackRouterFastDefaults = (config = {})=>({
6
+ defaultStructuralSharing: config.defaultStructuralSharing ?? modernTanstackRouterFastDefaults.defaultStructuralSharing
7
+ });
8
+ export { getModernTanstackRouterFastDefaults, modernTanstackRouterFastDefaults };
@@ -1,9 +1,13 @@
1
1
  import type { AppTools, AppToolsContext, CliPlugin } from '@modern-js/app-tools';
2
2
  import type { NestedRouteForCli, PageRoute } from '@modern-js/types';
3
+ import { type TanstackRouteCodeSplittingOption } from './routeSplitting';
4
+ export type { TanstackRouteCodeSplittingOption, TanstackRsbuildRouteSplittingProfile, } from './routeSplitting';
5
+ export { createTanstackRsbuildRouteSplittingProfile, isTanstackStartRouteModuleSource, resolveTanstackRouteCodeSplittingEnabled, } from './routeSplitting';
3
6
  export { generateTanstackRouterTypesSourceForEntry, isTanstackRouterFrameworkEnabled, } from './tanstackTypes';
4
7
  export type TanstackRouterPluginOptions = {
5
8
  routesDir?: string;
6
9
  generatedDirName?: string;
10
+ routeCodeSplitting?: TanstackRouteCodeSplittingOption;
7
11
  };
8
12
  export declare function writeTanstackRegisterFile(opts: {
9
13
  entries: string[];
@@ -0,0 +1,29 @@
1
+ export type TanstackRouteCodeSplittingOption = boolean | {
2
+ enabled?: boolean;
3
+ };
4
+ export type TanstackRsbuildRouteSplittingProfile = {
5
+ defaultConfig: {
6
+ output: {
7
+ splitRouteChunks: boolean;
8
+ };
9
+ };
10
+ modernRouteChunks: {
11
+ enabled: boolean;
12
+ owner: 'modern';
13
+ };
14
+ builderChunkSplit: {
15
+ owner: 'modern-rsbuild';
16
+ preserved: true;
17
+ };
18
+ tanstackStartRspackSplitter: {
19
+ compatible: boolean;
20
+ reason: string;
21
+ clientDeleteNodes: string[];
22
+ routeFactoryCalls: string[];
23
+ };
24
+ };
25
+ export declare function isTanstackStartRouteModuleSource(source: string): boolean;
26
+ export declare function resolveTanstackRouteCodeSplittingEnabled(option?: TanstackRouteCodeSplittingOption): boolean;
27
+ export declare function createTanstackRsbuildRouteSplittingProfile(opts: {
28
+ routeCodeSplitting?: TanstackRouteCodeSplittingOption;
29
+ }): TanstackRsbuildRouteSplittingProfile;
@@ -0,0 +1,2 @@
1
+ import { type ReactElement } from 'react';
2
+ export declare function wrapTanstackSsrHydrationBoundary(routerContent: ReactElement, shouldWrap: boolean): import("react").JSX.Element;
@@ -1,9 +1,12 @@
1
- export * from '@tanstack/react-router';
2
- export { useMatch } from '@tanstack/react-router';
1
+ export type * from '@tanstack/react-router';
2
+ export { Asset, Await, Block, CatchBoundary, CatchNotFound, ClientOnly, cleanPath, composeRewrites, createBrowserHistory, createControlledPromise, createFileRoute, createHashHistory, createHistory, createLazyFileRoute, createLazyRoute, createLink, createMemoryHistory, createRootRoute, createRootRouteWithContext, createRoute, createRouteMask, createRouter, createRouterConfig, createSerializationAdapter, DEFAULT_PROTOCOL_ALLOWLIST, DefaultGlobalNotFound, deepEqual, defaultParseSearch, defaultStringifySearch, defer, ErrorComponent, FileRoute, FileRouteLoader, functionalUpdate, getRouteApi, HeadContent, interpolatePath, isMatch, isNotFound, isPlainArray, isPlainObject, isRedirect, joinPaths, LazyRoute, lazyFn, lazyRouteComponent, linkOptions, Match, Matches, MatchRoute, Navigate, NotFoundRoute, notFound, parseSearchWith, RootRoute, Route, RouteApi, Router, RouterContextProvider, RouterProvider, reactUse, redirect, replaceEqualDeep, resolvePath, retainSearchParams, rootRouteId, rootRouteWithContext, ScriptOnce, Scripts, ScrollRestoration, SearchParamError, stringifySearchWith, stripSearchParams, trimPath, trimPathLeft, trimPathRight, useAwaited, useBlocker, useCanGoBack, useChildMatches, useElementScrollRestoration, useHydrated, useLayoutEffect, useLinkProps, useLoaderData, useLoaderDeps, useLocation, useMatch, useMatches, useMatchRoute, useNavigate, useParams, useParentMatches, useRouteContext, useRouter, useRouterState, useSearch, useTags, } from '@tanstack/react-router';
3
3
  export type { Fetcher, FetcherState, FetcherSubmitOptions, FormProps, SubmitOptions, } from './dataMutation';
4
4
  export { Form, RouteActionResponseError, useFetcher, } from './dataMutation';
5
+ export { Outlet } from './outlet';
5
6
  export { tanstackRouterPlugin, tanstackRouterPlugin as default, } from './plugin';
6
7
  export type { LinkProps, NavLinkProps, PrefetchBehavior, } from './prefetchLink';
7
8
  export { Link, NavLink } from './prefetchLink';
8
9
  export type { AnyCompositeComponent, AnyRenderableServerComponent, CompositeComponentProps, } from './rsc/client';
9
10
  export { CompositeComponent } from './rsc/client';
11
+ export type { RouterConfig } from './types';
12
+ export { getModernTanstackRouterFastDefaults, modernTanstackRouterFastDefaults, } from './types';
@@ -0,0 +1,2 @@
1
+ export declare const Outlet: import("react").MemoExoticComponent<() => import("react").JSX.Element>;
2
+ export declare function withModernRouteMatchContext(component: unknown, _routeId: string): unknown;
@@ -2,7 +2,7 @@ import type { Plugin, RuntimePluginExtends } from '@modern-js/plugin';
2
2
  import type { RuntimePluginAPI } from '@modern-js/plugin/runtime';
3
3
  import { type TInternalRuntimeContext } from '@modern-js/runtime/context';
4
4
  import { type RouterExtendsHooks } from './hooks';
5
- import type { RouterConfig } from './types';
5
+ import { type RouterConfig } from './types';
6
6
  type TanstackRouterRuntimeConfig = {
7
7
  plugins?: TanstackRouterRuntimePlugin[];
8
8
  router?: Partial<RouterConfig>;
@@ -2,7 +2,7 @@ import type { Plugin, RuntimePluginExtends } from '@modern-js/plugin';
2
2
  import type { RuntimePluginAPI } from '@modern-js/plugin/runtime';
3
3
  import { type TInternalRuntimeContext } from '@modern-js/runtime/context';
4
4
  import { type RouterExtendsHooks } from './hooks';
5
- import type { RouterConfig } from './types';
5
+ import { type RouterConfig } from './types';
6
6
  type TanstackRouterRuntimeConfig = {
7
7
  plugins?: TanstackRouterRuntimePlugin[];
8
8
  router?: Partial<RouterConfig>;
@@ -0,0 +1 @@
1
+ export { default, tanstackRouterPlugin, } from './plugin.node';
@@ -18,8 +18,15 @@ export type RouterConfig = {
18
18
  future?: Partial<{
19
19
  v7_startTransition: boolean;
20
20
  }>;
21
+ defaultStructuralSharing?: boolean;
21
22
  unstable_reloadOnURLMismatch?: boolean;
22
23
  };
24
+ export declare const modernTanstackRouterFastDefaults: {
25
+ readonly defaultStructuralSharing: true;
26
+ };
27
+ export declare const getModernTanstackRouterFastDefaults: (config?: Partial<Pick<RouterConfig, 'defaultStructuralSharing'>>) => {
28
+ defaultStructuralSharing: boolean;
29
+ };
23
30
  export interface RouterRouteMatchSnapshot {
24
31
  routeId: string;
25
32
  assetRouteId?: string;
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "modern.js",
19
19
  "tanstack-router"
20
20
  ],
21
- "version": "3.2.0-ultramodern.1",
21
+ "version": "3.2.0-ultramodern.100",
22
22
  "engines": {
23
23
  "node": ">=20"
24
24
  },
@@ -85,16 +85,16 @@
85
85
  }
86
86
  },
87
87
  "dependencies": {
88
- "@swc/helpers": "^0.5.21",
89
- "@tanstack/react-router": "1.170.1",
90
- "@tanstack/router-core": "1.170.1",
91
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.1",
92
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.1",
93
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.1",
94
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.1"
88
+ "@swc/helpers": "^0.5.23",
89
+ "@tanstack/react-router": "1.170.11",
90
+ "@tanstack/router-core": "1.171.9",
91
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.100",
92
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.100",
93
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.100",
94
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.100"
95
95
  },
96
96
  "peerDependencies": {
97
- "@modern-js/runtime": "3.2.0-ultramodern.1",
97
+ "@modern-js/runtime": "3.2.0-ultramodern.100",
98
98
  "react": "^19.2.6",
99
99
  "react-dom": "^19.2.6"
100
100
  },
@@ -103,14 +103,14 @@
103
103
  "@tanstack/history": "1.162.0",
104
104
  "@testing-library/dom": "^10.4.1",
105
105
  "@testing-library/react": "^16.3.2",
106
- "@types/node": "^25.8.0",
107
- "@types/react": "^19.2.14",
106
+ "@types/node": "^25.9.1",
107
+ "@types/react": "^19.2.15",
108
108
  "@types/react-dom": "^19.2.3",
109
- "@typescript/native-preview": "7.0.0-dev.20260516.1",
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.1",
113
- "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.2.0-ultramodern.1",
112
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.100",
113
+ "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.2.0-ultramodern.100",
114
114
  "@scripts/rstest-config": "2.66.0"
115
115
  },
116
116
  "sideEffects": false,
package/src/cli/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ // @effect-diagnostics asyncFunction:off nodeBuiltinImport:off strictBooleanExpressions:off
1
2
  import path from 'node:path';
2
3
  import type {
3
4
  AppNormalizedConfig,
@@ -17,11 +18,24 @@ import {
17
18
  fs,
18
19
  NESTED_ROUTE_SPEC_FILE,
19
20
  } from '@modern-js/utils';
21
+ import {
22
+ createTanstackRsbuildRouteSplittingProfile,
23
+ type TanstackRouteCodeSplittingOption,
24
+ } from './routeSplitting';
20
25
  import {
21
26
  generateTanstackRouterTypesSourceForEntry,
22
27
  isTanstackRouterFrameworkEnabled,
23
28
  } from './tanstackTypes';
24
29
 
30
+ export type {
31
+ TanstackRouteCodeSplittingOption,
32
+ TanstackRsbuildRouteSplittingProfile,
33
+ } from './routeSplitting';
34
+ export {
35
+ createTanstackRsbuildRouteSplittingProfile,
36
+ isTanstackStartRouteModuleSource,
37
+ resolveTanstackRouteCodeSplittingEnabled,
38
+ } from './routeSplitting';
25
39
  export {
26
40
  generateTanstackRouterTypesSourceForEntry,
27
41
  isTanstackRouterFrameworkEnabled,
@@ -34,6 +48,7 @@ const ENTRYPOINTS_KEY = '@modern-js/plugin-tanstack';
34
48
  export type TanstackRouterPluginOptions = {
35
49
  routesDir?: string;
36
50
  generatedDirName?: string;
51
+ routeCodeSplitting?: TanstackRouteCodeSplittingOption;
37
52
  };
38
53
 
39
54
  type RuntimeRouterCliHelpers = {
@@ -223,6 +238,8 @@ export function tanstackRouterPlugin(
223
238
  const routesDir = options.routesDir || DEFAULT_ROUTES_DIR;
224
239
  const generatedDirName =
225
240
  options.generatedDirName || DEFAULT_GENERATED_DIR_NAME;
241
+ const routeSplittingProfile =
242
+ createTanstackRsbuildRouteSplittingProfile(options);
226
243
 
227
244
  return {
228
245
  name: '@modern-js/plugin-tanstack',
@@ -257,24 +274,21 @@ export function tanstackRouterPlugin(
257
274
  return { entrypoint, plugins };
258
275
  });
259
276
 
260
- api.checkEntryPoint(({ path: entryPath, entry }) => {
261
- const { isRouteEntry } = getRuntimeRouterCli();
262
- return {
263
- path: entryPath,
264
- entry: entry || isRouteEntry(entryPath, routesDir),
265
- };
266
- });
267
-
268
- api.config(() => {
269
- return {
270
- source: {
271
- include: [
272
- /[\\/]node_modules[\\/]@tanstack[\\/]react-router[\\/]/,
273
- path.resolve(__dirname, '../runtime').replace('cjs', 'esm'),
274
- ],
275
- },
276
- };
277
- });
277
+ api.checkEntryPoint(({ path: entryPath, entry }) => ({
278
+ path: entryPath,
279
+ entry:
280
+ entry || getRuntimeRouterCli().isRouteEntry(entryPath, routesDir),
281
+ }));
282
+
283
+ api.config(() => ({
284
+ ...routeSplittingProfile.defaultConfig,
285
+ source: {
286
+ include: [
287
+ /[\\/]node_modules[\\/]@tanstack[\\/]react-router[\\/]/,
288
+ path.resolve(__dirname, '../runtime').replace('cjs', 'esm'),
289
+ ],
290
+ },
291
+ }));
278
292
 
279
293
  api.modifyEntrypoints(async ({ entrypoints }) => {
280
294
  const { handleModifyEntrypoints } = getRuntimeRouterCli();
@@ -0,0 +1,81 @@
1
+ export type TanstackRouteCodeSplittingOption =
2
+ | boolean
3
+ | {
4
+ enabled?: boolean;
5
+ };
6
+
7
+ export type TanstackRsbuildRouteSplittingProfile = {
8
+ defaultConfig: {
9
+ output: {
10
+ splitRouteChunks: boolean;
11
+ };
12
+ };
13
+ modernRouteChunks: {
14
+ enabled: boolean;
15
+ owner: 'modern';
16
+ };
17
+ builderChunkSplit: {
18
+ owner: 'modern-rsbuild';
19
+ preserved: true;
20
+ };
21
+ tanstackStartRspackSplitter: {
22
+ compatible: boolean;
23
+ reason: string;
24
+ clientDeleteNodes: string[];
25
+ routeFactoryCalls: string[];
26
+ };
27
+ };
28
+
29
+ const TANSTACK_START_ROUTE_FACTORY_CALLS = [
30
+ 'createFileRoute',
31
+ 'createRootRoute',
32
+ 'createRootRouteWithContext',
33
+ ] as const;
34
+
35
+ const TANSTACK_START_ROUTE_FACTORY_REGEX =
36
+ /\b(createFileRoute|createRootRoute|createRootRouteWithContext)\s*(?:<|\()/;
37
+
38
+ export function isTanstackStartRouteModuleSource(source: string) {
39
+ return TANSTACK_START_ROUTE_FACTORY_REGEX.test(source);
40
+ }
41
+
42
+ export function resolveTanstackRouteCodeSplittingEnabled(
43
+ option?: TanstackRouteCodeSplittingOption,
44
+ ) {
45
+ if (typeof option === 'boolean') {
46
+ return option;
47
+ }
48
+
49
+ return option?.enabled ?? true;
50
+ }
51
+
52
+ export function createTanstackRsbuildRouteSplittingProfile(opts: {
53
+ routeCodeSplitting?: TanstackRouteCodeSplittingOption;
54
+ }): TanstackRsbuildRouteSplittingProfile {
55
+ return {
56
+ defaultConfig: {
57
+ output: {
58
+ splitRouteChunks: resolveTanstackRouteCodeSplittingEnabled(
59
+ opts.routeCodeSplitting,
60
+ ),
61
+ },
62
+ },
63
+ modernRouteChunks: {
64
+ enabled: resolveTanstackRouteCodeSplittingEnabled(
65
+ opts.routeCodeSplitting,
66
+ ),
67
+ owner: 'modern',
68
+ },
69
+ builderChunkSplit: {
70
+ owner: 'modern-rsbuild',
71
+ preserved: true,
72
+ },
73
+ tanstackStartRspackSplitter: {
74
+ compatible: false,
75
+ reason:
76
+ 'TanStack Start Rsbuild route splitting is tied to TanStack file-route factory modules; Modern generates TanStack route trees from Modern route metadata and owns route chunking through output.splitRouteChunks.',
77
+ clientDeleteNodes: ['ssr', 'server', 'headers'],
78
+ routeFactoryCalls: [...TANSTACK_START_ROUTE_FACTORY_CALLS],
79
+ },
80
+ };
81
+ }