@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.11 → 3.2.0-ultramodern.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/index.js +21 -5
- package/dist/cjs/cli/routeSplitting.js +87 -0
- package/dist/cjs/cli/tanstackTypes.js +155 -63
- package/dist/cjs/cli.js +12 -8
- package/dist/cjs/runtime/DefaultNotFound.js +9 -5
- package/dist/cjs/runtime/basepathRewrite.js +12 -8
- package/dist/cjs/runtime/dataMutation.js +9 -5
- package/dist/cjs/runtime/hooks.js +9 -5
- package/dist/cjs/runtime/hydrationBoundary.js +48 -0
- package/dist/cjs/runtime/index.js +330 -74
- package/dist/cjs/runtime/lifecycle.js +15 -11
- package/dist/cjs/runtime/outlet.js +58 -0
- package/dist/cjs/runtime/plugin.js +203 -98
- package/dist/cjs/runtime/plugin.node.js +38 -16
- package/dist/cjs/runtime/plugin.worker.js +53 -0
- package/dist/cjs/runtime/prefetchLink.js +10 -6
- package/dist/cjs/runtime/routeTree.js +81 -17
- package/dist/cjs/runtime/rsc/ClientSlot.js +9 -5
- package/dist/cjs/runtime/rsc/CompositeComponent.js +9 -5
- package/dist/cjs/runtime/rsc/ReplayableStream.js +14 -9
- package/dist/cjs/runtime/rsc/RscNodeRenderer.js +9 -5
- package/dist/cjs/runtime/rsc/SlotContext.js +9 -5
- package/dist/cjs/runtime/rsc/client.js +9 -5
- package/dist/cjs/runtime/rsc/createRscProxy.js +9 -5
- package/dist/cjs/runtime/rsc/index.js +9 -5
- package/dist/cjs/runtime/rsc/payloadRouter.js +9 -5
- package/dist/cjs/runtime/rsc/server.js +9 -5
- package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +9 -5
- package/dist/cjs/runtime/rsc/symbols.js +20 -15
- package/dist/cjs/runtime/types.js +31 -1
- package/dist/cjs/runtime/utils.js +9 -5
- package/dist/cjs/runtime.js +9 -5
- package/dist/esm/cli/index.mjs +4 -1
- package/dist/esm/cli/routeSplitting.mjs +43 -0
- package/dist/esm/cli/tanstackTypes.mjs +146 -58
- package/dist/esm/runtime/hydrationBoundary.mjs +10 -0
- package/dist/esm/runtime/index.mjs +3 -2
- package/dist/esm/runtime/outlet.mjs +17 -0
- package/dist/esm/runtime/plugin.mjs +197 -96
- package/dist/esm/runtime/plugin.node.mjs +30 -12
- package/dist/esm/runtime/plugin.worker.mjs +1 -0
- package/dist/esm/runtime/prefetchLink.mjs +1 -1
- package/dist/esm/runtime/routeTree.mjs +73 -13
- package/dist/esm/runtime/types.mjs +7 -0
- package/dist/esm-node/cli/index.mjs +4 -1
- package/dist/esm-node/cli/routeSplitting.mjs +44 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +146 -58
- package/dist/esm-node/runtime/hydrationBoundary.mjs +11 -0
- package/dist/esm-node/runtime/index.mjs +3 -2
- package/dist/esm-node/runtime/outlet.mjs +18 -0
- package/dist/esm-node/runtime/plugin.mjs +197 -96
- package/dist/esm-node/runtime/plugin.node.mjs +30 -12
- package/dist/esm-node/runtime/plugin.worker.mjs +2 -0
- package/dist/esm-node/runtime/prefetchLink.mjs +1 -1
- package/dist/esm-node/runtime/routeTree.mjs +73 -13
- package/dist/esm-node/runtime/types.mjs +7 -0
- package/dist/types/cli/index.d.ts +4 -0
- package/dist/types/cli/routeSplitting.d.ts +29 -0
- package/dist/types/runtime/hooks.d.ts +9 -24
- package/dist/types/runtime/hydrationBoundary.d.ts +2 -0
- package/dist/types/runtime/index.d.ts +5 -2
- package/dist/types/runtime/outlet.d.ts +2 -0
- package/dist/types/runtime/plugin.d.ts +1 -1
- package/dist/types/runtime/plugin.node.d.ts +1 -1
- package/dist/types/runtime/plugin.worker.d.ts +1 -0
- package/dist/types/runtime/types.d.ts +7 -0
- package/package.json +19 -19
- package/src/cli/index.ts +17 -0
- package/src/cli/routeSplitting.ts +81 -0
- package/src/cli/tanstackTypes.ts +216 -67
- package/src/runtime/hydrationBoundary.tsx +12 -0
- package/src/runtime/index.tsx +107 -2
- package/src/runtime/outlet.tsx +48 -0
- package/src/runtime/plugin.node.tsx +58 -8
- package/src/runtime/plugin.tsx +372 -157
- package/src/runtime/plugin.worker.tsx +4 -0
- package/src/runtime/prefetchLink.tsx +1 -1
- package/src/runtime/routeTree.ts +194 -23
- package/src/runtime/ssr-shim.d.ts +1 -3
- package/src/runtime/types.ts +13 -0
- package/tests/router/cli.test.ts +239 -0
- package/tests/router/fastDefaults.test.ts +25 -0
- package/tests/router/hydrationBoundary.test.tsx +23 -0
- package/tests/router/prefetchLink.test.tsx +43 -7
- package/tests/router/routeTree.test.ts +416 -1
- 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
|
|
324
|
+
component,
|
|
276
325
|
pendingComponent: toPendingComponent(routeObject),
|
|
277
326
|
errorComponent: toErrorComponent(routeObject),
|
|
278
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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:
|
|
468
|
+
component: rootComponent,
|
|
413
469
|
pendingComponent: rootLikeRoute ? toPendingComponent(rootLikeRoute) : void 0,
|
|
414
470
|
errorComponent: rootLikeRoute ? toErrorComponent(rootLikeRoute) : void 0,
|
|
415
|
-
|
|
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
|
|
449
|
-
|
|
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;
|
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare const onBeforeCreateRoutes:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
declare const
|
|
10
|
-
tap: (cb: any) => void;
|
|
11
|
-
call: (...params: any[]) => any;
|
|
12
|
-
};
|
|
13
|
-
declare const onAfterCreateRouter: {
|
|
14
|
-
tap: (cb: any) => void;
|
|
15
|
-
call: (...params: any[]) => any;
|
|
16
|
-
};
|
|
17
|
-
declare const onBeforeHydrateRouter: {
|
|
18
|
-
tap: (cb: any) => void;
|
|
19
|
-
call: (...params: any[]) => any;
|
|
20
|
-
};
|
|
21
|
-
declare const onAfterHydrateRouter: {
|
|
22
|
-
tap: (cb: any) => void;
|
|
23
|
-
call: (...params: any[]) => any;
|
|
24
|
-
};
|
|
1
|
+
import type { TRuntimeContext } from '@modern-js/runtime/context';
|
|
2
|
+
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
3
|
+
import type { RouterLifecycleContext } from './lifecycle';
|
|
4
|
+
declare const modifyRoutes: import("@modern-js/plugin").SyncHook<(routes: RouteObject[]) => RouteObject[]>;
|
|
5
|
+
declare const onBeforeCreateRoutes: import("@modern-js/plugin").SyncHook<(context: TRuntimeContext) => void>;
|
|
6
|
+
declare const onBeforeCreateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
|
|
7
|
+
declare const onAfterCreateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
|
|
8
|
+
declare const onBeforeHydrateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
|
|
9
|
+
declare const onAfterHydrateRouter: import("@modern-js/plugin").SyncHook<(context: RouterLifecycleContext) => void>;
|
|
25
10
|
export { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter, };
|
|
26
11
|
export type RouterExtendsHooks = {
|
|
27
12
|
modifyRoutes: typeof modifyRoutes;
|
|
@@ -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';
|
|
@@ -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
|
|
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
|
|
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.
|
|
21
|
+
"version": "3.2.0-ultramodern.111",
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=20"
|
|
24
24
|
},
|
|
@@ -85,33 +85,33 @@
|
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@swc/helpers": "^0.5.
|
|
89
|
-
"@tanstack/react-router": "1.170.
|
|
90
|
-
"@tanstack/router-core": "1.
|
|
91
|
-
"@modern-js/
|
|
92
|
-
"@modern-js/
|
|
93
|
-
"@modern-js/
|
|
94
|
-
"@modern-js/
|
|
88
|
+
"@swc/helpers": "^0.5.23",
|
|
89
|
+
"@tanstack/react-router": "1.170.15",
|
|
90
|
+
"@tanstack/router-core": "1.171.13",
|
|
91
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.2.0-ultramodern.111",
|
|
92
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.2.0-ultramodern.111",
|
|
93
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.2.0-ultramodern.111",
|
|
94
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.2.0-ultramodern.111"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
|
-
"@modern-js/runtime": "3.2.0-ultramodern.
|
|
98
|
-
"react": "^19.2.
|
|
99
|
-
"react-dom": "^19.2.
|
|
97
|
+
"@modern-js/runtime": "3.2.0-ultramodern.111",
|
|
98
|
+
"react": "^19.2.7",
|
|
99
|
+
"react-dom": "^19.2.7"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@rslib/core": "0.21.5",
|
|
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.
|
|
107
|
-
"@types/react": "^19.2.
|
|
106
|
+
"@types/node": "^25.9.1",
|
|
107
|
+
"@types/react": "^19.2.17",
|
|
108
108
|
"@types/react-dom": "^19.2.3",
|
|
109
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
110
|
-
"react": "^19.2.
|
|
111
|
-
"react-dom": "^19.2.
|
|
112
|
-
"@modern-js/
|
|
113
|
-
"@
|
|
114
|
-
"@
|
|
109
|
+
"@typescript/native-preview": "7.0.0-dev.20260606.1",
|
|
110
|
+
"react": "^19.2.7",
|
|
111
|
+
"react-dom": "^19.2.7",
|
|
112
|
+
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.2.0-ultramodern.111",
|
|
113
|
+
"@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.2.0-ultramodern.111",
|
|
114
|
+
"@scripts/rstest-config": "2.66.0"
|
|
115
115
|
},
|
|
116
116
|
"sideEffects": false,
|
|
117
117
|
"publishConfig": {
|
package/src/cli/index.ts
CHANGED
|
@@ -18,11 +18,24 @@ import {
|
|
|
18
18
|
fs,
|
|
19
19
|
NESTED_ROUTE_SPEC_FILE,
|
|
20
20
|
} from '@modern-js/utils';
|
|
21
|
+
import {
|
|
22
|
+
createTanstackRsbuildRouteSplittingProfile,
|
|
23
|
+
type TanstackRouteCodeSplittingOption,
|
|
24
|
+
} from './routeSplitting';
|
|
21
25
|
import {
|
|
22
26
|
generateTanstackRouterTypesSourceForEntry,
|
|
23
27
|
isTanstackRouterFrameworkEnabled,
|
|
24
28
|
} from './tanstackTypes';
|
|
25
29
|
|
|
30
|
+
export type {
|
|
31
|
+
TanstackRouteCodeSplittingOption,
|
|
32
|
+
TanstackRsbuildRouteSplittingProfile,
|
|
33
|
+
} from './routeSplitting';
|
|
34
|
+
export {
|
|
35
|
+
createTanstackRsbuildRouteSplittingProfile,
|
|
36
|
+
isTanstackStartRouteModuleSource,
|
|
37
|
+
resolveTanstackRouteCodeSplittingEnabled,
|
|
38
|
+
} from './routeSplitting';
|
|
26
39
|
export {
|
|
27
40
|
generateTanstackRouterTypesSourceForEntry,
|
|
28
41
|
isTanstackRouterFrameworkEnabled,
|
|
@@ -35,6 +48,7 @@ const ENTRYPOINTS_KEY = '@modern-js/plugin-tanstack';
|
|
|
35
48
|
export type TanstackRouterPluginOptions = {
|
|
36
49
|
routesDir?: string;
|
|
37
50
|
generatedDirName?: string;
|
|
51
|
+
routeCodeSplitting?: TanstackRouteCodeSplittingOption;
|
|
38
52
|
};
|
|
39
53
|
|
|
40
54
|
type RuntimeRouterCliHelpers = {
|
|
@@ -224,6 +238,8 @@ export function tanstackRouterPlugin(
|
|
|
224
238
|
const routesDir = options.routesDir || DEFAULT_ROUTES_DIR;
|
|
225
239
|
const generatedDirName =
|
|
226
240
|
options.generatedDirName || DEFAULT_GENERATED_DIR_NAME;
|
|
241
|
+
const routeSplittingProfile =
|
|
242
|
+
createTanstackRsbuildRouteSplittingProfile(options);
|
|
227
243
|
|
|
228
244
|
return {
|
|
229
245
|
name: '@modern-js/plugin-tanstack',
|
|
@@ -265,6 +281,7 @@ export function tanstackRouterPlugin(
|
|
|
265
281
|
}));
|
|
266
282
|
|
|
267
283
|
api.config(() => ({
|
|
284
|
+
...routeSplittingProfile.defaultConfig,
|
|
268
285
|
source: {
|
|
269
286
|
include: [
|
|
270
287
|
/[\\/]node_modules[\\/]@tanstack[\\/]react-router[\\/]/,
|
|
@@ -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
|
+
}
|