@bleedingdev/modern-js-plugin-tanstack 3.8.1-ultramodern.1 → 3.8.1-ultramodern.3
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/tanstackTypes/shared.js +8 -6
- package/dist/cjs/runtime/clientHydration.js +2 -2
- package/dist/cjs/runtime/loaderBridge.js +11 -8
- package/dist/cjs/runtime/plugin.js +6 -7
- package/dist/cjs/runtime/plugin.node.js +5 -6
- package/dist/cjs/runtime/pluginShared.js +2 -3
- package/dist/cjs/runtime/routeTree/components.js +1 -1
- package/dist/cjs/runtime/routeTree/construction.js +4 -3
- package/dist/cjs/runtime/routeTree/loaders.js +7 -43
- package/dist/cjs/runtime/routeTree/staticData.js +0 -16
- package/dist/cjs/runtime/rsc/client.js +2 -6
- package/dist/cjs/runtime/rsc/server.js +2 -6
- package/dist/cjs/runtime/submitAction.js +3 -12
- package/dist/cjs/runtime/utils.js +2 -7
- package/dist/cjs/{runtime/rsc/index.js → shared/routeStaticData.js} +6 -10
- package/dist/esm/cli/tanstackTypes/shared.mjs +8 -6
- package/dist/esm/runtime/clientHydration.mjs +1 -1
- package/dist/esm/runtime/loaderBridge.mjs +2 -8
- package/dist/esm/runtime/plugin.mjs +5 -6
- package/dist/esm/runtime/plugin.node.mjs +3 -4
- package/dist/esm/runtime/pluginShared.mjs +2 -3
- package/dist/esm/runtime/routeTree/components.mjs +1 -1
- package/dist/esm/runtime/routeTree/construction.mjs +3 -2
- package/dist/esm/runtime/routeTree/loaders.mjs +8 -44
- package/dist/esm/runtime/routeTree/staticData.mjs +1 -14
- package/dist/esm/runtime/rsc/client.mjs +1 -2
- package/dist/esm/runtime/rsc/server.mjs +1 -2
- package/dist/esm/runtime/submitAction.mjs +1 -10
- package/dist/esm/runtime/utils.mjs +2 -7
- package/dist/esm/shared/routeStaticData.mjs +4 -0
- package/dist/esm-node/cli/tanstackTypes/shared.mjs +8 -6
- package/dist/esm-node/runtime/clientHydration.mjs +1 -1
- package/dist/esm-node/runtime/loaderBridge.mjs +2 -8
- package/dist/esm-node/runtime/plugin.mjs +5 -6
- package/dist/esm-node/runtime/plugin.node.mjs +3 -4
- package/dist/esm-node/runtime/pluginShared.mjs +2 -3
- package/dist/esm-node/runtime/routeTree/components.mjs +1 -1
- package/dist/esm-node/runtime/routeTree/construction.mjs +3 -2
- package/dist/esm-node/runtime/routeTree/loaders.mjs +8 -44
- package/dist/esm-node/runtime/routeTree/staticData.mjs +1 -14
- package/dist/esm-node/runtime/rsc/client.mjs +1 -2
- package/dist/esm-node/runtime/rsc/server.mjs +1 -2
- package/dist/esm-node/runtime/submitAction.mjs +1 -10
- package/dist/esm-node/runtime/utils.mjs +2 -7
- package/dist/esm-node/shared/routeStaticData.mjs +5 -0
- package/dist/types/runtime/loaderBridge.d.ts +17 -13
- package/dist/types/runtime/pluginShared.d.ts +1 -3
- package/dist/types/runtime/routeTree/components.d.ts +1 -2
- package/dist/types/runtime/routeTree/staticData.d.ts +2 -14
- package/dist/types/runtime/rsc/client.d.ts +0 -1
- package/dist/types/runtime/rsc/server.d.ts +0 -1
- package/dist/types/runtime/utils.d.ts +0 -3
- package/dist/types/shared/routeStaticData.d.ts +1 -0
- package/package.json +9 -9
- package/src/cli/tanstackTypes/shared.ts +13 -21
- package/src/runtime/loaderBridge.ts +5 -38
- package/src/runtime/plugin.node.tsx +2 -3
- package/src/runtime/plugin.tsx +4 -5
- package/src/runtime/pluginShared.ts +1 -4
- package/src/runtime/routeTree/components.ts +2 -5
- package/src/runtime/routeTree/construction.ts +3 -2
- package/src/runtime/routeTree/loaders.ts +13 -77
- package/src/runtime/routeTree/staticData.ts +2 -53
- package/src/runtime/rsc/client.tsx +0 -2
- package/src/runtime/rsc/server.tsx +0 -2
- package/src/runtime/submitAction.ts +1 -7
- package/src/runtime/utils.tsx +2 -12
- package/src/shared/routeStaticData.ts +7 -0
- package/tests/router/cli.test.ts +3 -1
- package/dist/cjs/runtime/routeTree.js +0 -46
- package/dist/esm/runtime/routeTree.mjs +0 -1
- package/dist/esm/runtime/rsc/index.mjs +0 -1
- package/dist/esm-node/runtime/routeTree.mjs +0 -2
- package/dist/esm-node/runtime/rsc/index.mjs +0 -2
- package/dist/types/runtime/routeTree.d.ts +0 -1
- package/dist/types/runtime/rsc/index.d.ts +0 -2
- package/src/runtime/routeTree.ts +0 -7
- package/src/runtime/rsc/index.ts +0 -10
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { formDataToTextPlain, formDataToUrlSearchParams, toFormData } from "./formData.mjs";
|
|
3
|
+
import { isRedirectResponse } from "./loaderBridge.mjs";
|
|
3
4
|
class RouteActionResponseError extends Error {
|
|
4
5
|
constructor(response, data){
|
|
5
6
|
super(`Route action failed with status ${response.status}`);
|
|
@@ -23,16 +24,6 @@ function resolveRouteHandlers(router, actionTo) {
|
|
|
23
24
|
params: routeParams
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
function isRedirectResponse(value) {
|
|
27
|
-
if (!(value instanceof Response)) return false;
|
|
28
|
-
return [
|
|
29
|
-
301,
|
|
30
|
-
302,
|
|
31
|
-
303,
|
|
32
|
-
307,
|
|
33
|
-
308
|
|
34
|
-
].includes(value.status);
|
|
35
|
-
}
|
|
36
27
|
async function parseResponseData(response) {
|
|
37
28
|
if (204 === response.status) return null;
|
|
38
29
|
const contentType = response.headers.get('Content-Type') || '';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import react from "react";
|
|
4
|
+
import { mergeModernRouteHandle } from "./routeTree/staticData.mjs";
|
|
4
5
|
function withGlobalLayout(Component, globalApp) {
|
|
5
6
|
if (!globalApp) return Component;
|
|
6
7
|
const GlobalLayout = globalApp;
|
|
@@ -11,12 +12,6 @@ function withGlobalLayout(Component, globalApp) {
|
|
|
11
12
|
});
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
|
-
function getRouteHandle(route) {
|
|
15
|
-
return {
|
|
16
|
-
...route.handle,
|
|
17
|
-
...'object' == typeof route.config ? route.config?.handle : {}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
15
|
function toTanstackRouteObject(route, globalApp) {
|
|
21
16
|
if ('nested' === route.type) return {
|
|
22
17
|
path: route.path,
|
|
@@ -24,7 +19,7 @@ function toTanstackRouteObject(route, globalApp) {
|
|
|
24
19
|
loader: route.loader,
|
|
25
20
|
action: route.action,
|
|
26
21
|
shouldRevalidate: route.shouldRevalidate,
|
|
27
|
-
handle:
|
|
22
|
+
handle: mergeModernRouteHandle(route) ?? {},
|
|
28
23
|
index: route.index,
|
|
29
24
|
hasLoader: route.hasLoader || Boolean(route.loader),
|
|
30
25
|
hasClientLoader: route.hasClientLoader || Boolean(route.clientData),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { createRouteStaticData } from '../shared/routeStaticData';
|
|
1
2
|
import { isAbsoluteUrl } from './shared/isAbsoluteUrl';
|
|
2
|
-
export { isAbsoluteUrl };
|
|
3
|
+
export { createRouteStaticData, isAbsoluteUrl };
|
|
3
4
|
/** Router context shape used by the generated TanStack router types. */
|
|
4
5
|
export type ModernRouterContext = {
|
|
5
6
|
request?: Request;
|
|
@@ -25,19 +26,22 @@ export declare function throwTanstackRedirect(location: string): never;
|
|
|
25
26
|
* Modern loaders expect the React Router spelling.
|
|
26
27
|
*/
|
|
27
28
|
export declare function mapSplatParamsForModernLoader(params: Record<string, string>, hasSplat: boolean): Record<string, string>;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
type LoaderLikeContext = {
|
|
30
|
+
abortController?: AbortController;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
context?: ModernRouterContext;
|
|
33
|
+
location?: string | {
|
|
34
|
+
publicHref?: string;
|
|
35
|
+
href?: string;
|
|
36
|
+
url?: {
|
|
37
|
+
href?: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
params?: Record<string, string>;
|
|
40
41
|
};
|
|
42
|
+
export declare function getLoaderHref(ctx: LoaderLikeContext | undefined): string;
|
|
43
|
+
export declare function handleModernLoaderResult<LoaderResult>(result: LoaderResult): LoaderResult;
|
|
44
|
+
export declare function handleModernLoaderError(err: unknown): never;
|
|
41
45
|
/**
|
|
42
46
|
* Wrap a Modern.js data loader (`page.data.ts` loader/action style) into a
|
|
43
47
|
* TanStack Router loader: builds a `Request` from the loader context, maps
|
|
@@ -2,7 +2,6 @@ import { type TInternalRuntimeContext } from '@modern-js/runtime/context';
|
|
|
2
2
|
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
3
3
|
import type { RouterExtendsHooks } from './hooks';
|
|
4
4
|
import type { RouterConfig } from './types';
|
|
5
|
-
import { type SSRMode } from './utils';
|
|
6
5
|
type TanstackRouterRuntimeConfig = {
|
|
7
6
|
plugins?: TanstackRouterRuntimePlugin[];
|
|
8
7
|
router?: Partial<RouterConfig>;
|
|
@@ -29,10 +28,9 @@ type TanstackRouteConfig = {
|
|
|
29
28
|
};
|
|
30
29
|
export declare function getMergedRouterConfig(api: TanstackRouterPluginAPI, userConfig: Partial<RouterConfig>): RouterConfig;
|
|
31
30
|
export declare function getTanstackRouteConfig(api: TanstackRouterPluginAPI, userConfig: Partial<RouterConfig>): TanstackRouteConfig;
|
|
32
|
-
export declare function createTanstackRouteObjects({ hooks, routeConfig,
|
|
31
|
+
export declare function createTanstackRouteObjects({ hooks, routeConfig, }: {
|
|
33
32
|
hooks: RouterExtendsHooks;
|
|
34
33
|
routeConfig: TanstackRouteConfig;
|
|
35
|
-
ssrMode?: SSRMode;
|
|
36
34
|
}): RouteObject[];
|
|
37
35
|
export declare function joinBasename(baseUrl: string, basename: string): string;
|
|
38
36
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
2
2
|
import { type ElementType } from 'react';
|
|
3
|
-
import type { RouteTreeOptions } from './types';
|
|
4
3
|
export declare function pickRouteModuleComponent(routeModule: unknown, seen?: Set<unknown>): ElementType<Record<string, unknown>> | undefined;
|
|
5
|
-
export declare function toRouteComponent(routeObject: RouteObject
|
|
4
|
+
export declare function toRouteComponent(routeObject: RouteObject): unknown;
|
|
6
5
|
export declare function toErrorComponent(routeObject: RouteObject): unknown;
|
|
7
6
|
export declare function toPendingComponent(routeObject: RouteObject): unknown;
|
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
export declare function mergeModernRouteHandle(route: {
|
|
2
|
-
config?:
|
|
3
|
-
handle?: Record<string, unknown>;
|
|
4
|
-
} | unknown;
|
|
2
|
+
config?: unknown;
|
|
5
3
|
handle?: Record<string, unknown>;
|
|
4
|
+
[key: string]: unknown;
|
|
6
5
|
}): {
|
|
7
6
|
[x: string]: unknown;
|
|
8
7
|
} | undefined;
|
|
9
|
-
export declare function createRouteStaticData(opts: {
|
|
10
|
-
modernRouteId?: string;
|
|
11
|
-
modernRouteAction?: unknown;
|
|
12
|
-
modernRouteHandle?: unknown;
|
|
13
|
-
modernRouteHasAction?: boolean;
|
|
14
|
-
modernRouteHasClientLoader?: boolean;
|
|
15
|
-
modernRouteHasLoader?: boolean;
|
|
16
|
-
modernRouteIsClientComponent?: boolean;
|
|
17
|
-
modernRouteLoader?: unknown;
|
|
18
|
-
modernRouteShouldRevalidate?: unknown;
|
|
19
|
-
}): Record<string, unknown> | undefined;
|
|
@@ -10,4 +10,3 @@ type SerializedRsc = {
|
|
|
10
10
|
};
|
|
11
11
|
export declare function createTanstackRscValueFromFlight(serialized: SerializedTanstackRscFlightValue): AnyCompositeComponent;
|
|
12
12
|
export declare function getTanstackRscSerializationAdapters(): import("@tanstack/router-core").SerializationAdapter<AnyCompositeComponent<Record<string, unknown>, import("react").ReactNode>, SerializedRsc, never>[];
|
|
13
|
-
export declare const rscSerializationAdapter: typeof getTanstackRscSerializationAdapters;
|
|
@@ -11,4 +11,3 @@ type SerializedRsc = {
|
|
|
11
11
|
slotUsagesStream?: ReadableStream<RscSlotUsageEvent>;
|
|
12
12
|
};
|
|
13
13
|
export declare function getTanstackRscSerializationAdapters(): import("@tanstack/router-core").SerializationAdapter<AnyCompositeComponent<Record<string, unknown>, React.ReactNode> | AnyRenderableServerComponent<React.ReactNode>, SerializedRsc, never>[];
|
|
14
|
-
export declare const rscSerializationAdapter: typeof getTanstackRscSerializationAdapters;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import type { ModernRoute } from './types';
|
|
4
|
-
export type SSRMode = 'string' | 'stream';
|
|
5
4
|
type RouterConfig = {
|
|
6
5
|
routesConfig: {
|
|
7
6
|
globalApp?: React.ComponentType<any>;
|
|
@@ -10,7 +9,5 @@ type RouterConfig = {
|
|
|
10
9
|
};
|
|
11
10
|
export declare function createTanstackRouteObjectsFromConfig({ routesConfig, }: {
|
|
12
11
|
routesConfig: RouterConfig['routesConfig'];
|
|
13
|
-
props?: Record<string, unknown>;
|
|
14
|
-
ssrMode?: SSRMode;
|
|
15
12
|
}): RouteObject[] | null;
|
|
16
13
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createRouteStaticData<const T extends Record<string, unknown>>(opts: T): Partial<T>;
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"modern.js",
|
|
19
19
|
"tanstack-router"
|
|
20
20
|
],
|
|
21
|
-
"version": "3.8.1-ultramodern.
|
|
21
|
+
"version": "3.8.1-ultramodern.3",
|
|
22
22
|
"engines": {
|
|
23
23
|
"node": ">=20"
|
|
24
24
|
},
|
|
@@ -94,17 +94,17 @@
|
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.8.1-ultramodern.
|
|
98
|
-
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.8.1-ultramodern.
|
|
99
|
-
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.8.1-ultramodern.
|
|
100
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.8.1-ultramodern.
|
|
97
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.8.1-ultramodern.3",
|
|
98
|
+
"@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.8.1-ultramodern.3",
|
|
99
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.8.1-ultramodern.3",
|
|
100
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.8.1-ultramodern.3",
|
|
101
101
|
"@swc/helpers": "^0.5.23",
|
|
102
102
|
"@tanstack/react-router": "1.170.25",
|
|
103
103
|
"@tanstack/router-core": "1.171.21"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
|
-
"@modern-js/app-tools": "3.8.1-ultramodern.
|
|
107
|
-
"@modern-js/runtime": "3.8.1-ultramodern.
|
|
106
|
+
"@modern-js/app-tools": "3.8.1-ultramodern.3",
|
|
107
|
+
"@modern-js/runtime": "3.8.1-ultramodern.3",
|
|
108
108
|
"react": "^19.2.8",
|
|
109
109
|
"react-dom": "^19.2.8",
|
|
110
110
|
"react-server-dom-rspack": "0.0.3"
|
|
@@ -115,8 +115,8 @@
|
|
|
115
115
|
}
|
|
116
116
|
},
|
|
117
117
|
"devDependencies": {
|
|
118
|
-
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.8.1-ultramodern.
|
|
119
|
-
"@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.8.1-ultramodern.
|
|
118
|
+
"@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.8.1-ultramodern.3",
|
|
119
|
+
"@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.8.1-ultramodern.3",
|
|
120
120
|
"@rslib/core": "0.23.2",
|
|
121
121
|
"@scripts/rstest-config": "2.66.0",
|
|
122
122
|
"@tanstack/history": "1.162.1",
|
|
@@ -4,6 +4,8 @@ import { getPathWithoutExt } from '@modern-js/runtime/cli';
|
|
|
4
4
|
import type { NestedRouteForCli, PageRoute } from '@modern-js/types';
|
|
5
5
|
import { findExists, formatImportPath, slash } from '@modern-js/utils';
|
|
6
6
|
|
|
7
|
+
import { createRouteStaticData } from '../../shared/routeStaticData';
|
|
8
|
+
|
|
7
9
|
const JS_OR_TS_EXTS = [
|
|
8
10
|
'.js',
|
|
9
11
|
'.jsx',
|
|
@@ -88,25 +90,15 @@ export function createRouteStaticDataSnippet(opts: {
|
|
|
88
90
|
loaderName?: string | null;
|
|
89
91
|
actionName?: string | null;
|
|
90
92
|
}) {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
staticDataLines.push(`modernRouteAction: ${opts.actionName},`);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (!staticDataLines.length) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return `staticData: createRouteStaticData({\n ${staticDataLines.join(
|
|
110
|
-
'\n ',
|
|
111
|
-
)}\n }),`;
|
|
93
|
+
const staticData = createRouteStaticData({
|
|
94
|
+
modernRouteId: opts.modernRouteId && quote(opts.modernRouteId),
|
|
95
|
+
modernRouteLoader: opts.loaderName,
|
|
96
|
+
modernRouteAction: opts.actionName,
|
|
97
|
+
});
|
|
98
|
+
const entries = Object.entries(staticData);
|
|
99
|
+
return entries.length > 0
|
|
100
|
+
? `staticData: createRouteStaticData({\n ${entries
|
|
101
|
+
.map(([key, value]) => `${key}: ${value},`)
|
|
102
|
+
.join('\n ')}\n }),`
|
|
103
|
+
: null;
|
|
112
104
|
}
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
* helpers for the same reason.
|
|
10
10
|
*/
|
|
11
11
|
import { notFound, redirect } from '@tanstack/react-router';
|
|
12
|
+
import { createRouteStaticData } from '../shared/routeStaticData';
|
|
12
13
|
import { isAbsoluteUrl } from './shared/isAbsoluteUrl';
|
|
13
14
|
|
|
14
|
-
export { isAbsoluteUrl };
|
|
15
|
+
export { createRouteStaticData, isAbsoluteUrl };
|
|
15
16
|
|
|
16
17
|
/** Router context shape used by the generated TanStack router types. */
|
|
17
18
|
export type ModernRouterContext = {
|
|
@@ -83,40 +84,6 @@ export function mapSplatParamsForModernLoader(
|
|
|
83
84
|
return rest;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
/**
|
|
87
|
-
* Static-data factory used by the generated router files: drops empty fields
|
|
88
|
-
* so route static data stays minimal.
|
|
89
|
-
*/
|
|
90
|
-
export function createRouteStaticData(opts: {
|
|
91
|
-
modernRouteId?: string;
|
|
92
|
-
modernRouteAction?: unknown;
|
|
93
|
-
modernRouteLoader?: unknown;
|
|
94
|
-
}): {
|
|
95
|
-
modernRouteId?: string;
|
|
96
|
-
modernRouteAction?: unknown;
|
|
97
|
-
modernRouteLoader?: unknown;
|
|
98
|
-
} {
|
|
99
|
-
const staticData: {
|
|
100
|
-
modernRouteId?: string;
|
|
101
|
-
modernRouteAction?: unknown;
|
|
102
|
-
modernRouteLoader?: unknown;
|
|
103
|
-
} = {};
|
|
104
|
-
|
|
105
|
-
if (typeof opts.modernRouteId === 'string' && opts.modernRouteId.length > 0) {
|
|
106
|
-
staticData.modernRouteId = opts.modernRouteId;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (typeof opts.modernRouteLoader !== 'undefined') {
|
|
110
|
-
staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (typeof opts.modernRouteAction !== 'undefined') {
|
|
114
|
-
staticData.modernRouteAction = opts.modernRouteAction;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return staticData;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
87
|
type LoaderLikeContext = {
|
|
121
88
|
abortController?: AbortController;
|
|
122
89
|
signal?: AbortSignal;
|
|
@@ -142,7 +109,7 @@ function getLoaderSignal(ctx: LoaderLikeContext | undefined): AbortSignal {
|
|
|
142
109
|
return new AbortController().signal;
|
|
143
110
|
}
|
|
144
111
|
|
|
145
|
-
function getLoaderHref(ctx: LoaderLikeContext | undefined): string {
|
|
112
|
+
export function getLoaderHref(ctx: LoaderLikeContext | undefined): string {
|
|
146
113
|
if (typeof ctx?.location === 'string') {
|
|
147
114
|
return ctx.location;
|
|
148
115
|
}
|
|
@@ -169,7 +136,7 @@ function getLoaderParams(
|
|
|
169
136
|
: {};
|
|
170
137
|
}
|
|
171
138
|
|
|
172
|
-
function handleModernLoaderResult<LoaderResult>(
|
|
139
|
+
export function handleModernLoaderResult<LoaderResult>(
|
|
173
140
|
result: LoaderResult,
|
|
174
141
|
): LoaderResult {
|
|
175
142
|
if (isResponse(result)) {
|
|
@@ -185,7 +152,7 @@ function handleModernLoaderResult<LoaderResult>(
|
|
|
185
152
|
return result;
|
|
186
153
|
}
|
|
187
154
|
|
|
188
|
-
function handleModernLoaderError(err: unknown): never {
|
|
155
|
+
export function handleModernLoaderError(err: unknown): never {
|
|
189
156
|
if (isResponse(err)) {
|
|
190
157
|
if (isTanstackRedirect(err)) {
|
|
191
158
|
throw err;
|
|
@@ -75,10 +75,10 @@ export const tanstackRouterPlugin = (
|
|
|
75
75
|
api.onBeforeRender(async (context, interrupt) => {
|
|
76
76
|
const routeConfig = getTanstackRouteConfig(api, userConfig);
|
|
77
77
|
const { mergedConfig } = routeConfig;
|
|
78
|
-
const
|
|
78
|
+
const enableRsc = getGlobalEnableRsc();
|
|
79
|
+
const serializationAdapters = enableRsc
|
|
79
80
|
? (await import('./rsc/server')).getTanstackRscSerializationAdapters()
|
|
80
81
|
: undefined;
|
|
81
|
-
const enableRsc = getGlobalEnableRsc();
|
|
82
82
|
|
|
83
83
|
const { basename = '' } = mergedConfig;
|
|
84
84
|
|
|
@@ -92,7 +92,6 @@ export const tanstackRouterPlugin = (
|
|
|
92
92
|
const modifiedRouteObjects = createTanstackRouteObjects({
|
|
93
93
|
hooks,
|
|
94
94
|
routeConfig,
|
|
95
|
-
ssrMode: context.ssrContext?.mode,
|
|
96
95
|
});
|
|
97
96
|
|
|
98
97
|
if (!modifiedRouteObjects.length) {
|
package/src/runtime/plugin.tsx
CHANGED
|
@@ -222,7 +222,7 @@ export const tanstackRouterPlugin = (
|
|
|
222
222
|
runtimeContext,
|
|
223
223
|
getClientBasename(runtimeContext),
|
|
224
224
|
);
|
|
225
|
-
if (router
|
|
225
|
+
if (router) {
|
|
226
226
|
return getTanstackSsrHydrationPromise(router).then(() => undefined);
|
|
227
227
|
}
|
|
228
228
|
}
|
|
@@ -273,8 +273,7 @@ export const tanstackRouterPlugin = (
|
|
|
273
273
|
typeof window !== 'undefined' &&
|
|
274
274
|
(Boolean((window as WindowWithTanstackSsr).$_TSR) ||
|
|
275
275
|
hasTanstackSsrHydrationRecord(router));
|
|
276
|
-
|
|
277
|
-
if (needsRouterClient) {
|
|
276
|
+
if (hasSSRBootstrap) {
|
|
278
277
|
hooks.onBeforeHydrateRouter.call({
|
|
279
278
|
...lifecycleContext,
|
|
280
279
|
phase: 'hydrate',
|
|
@@ -283,7 +282,7 @@ export const tanstackRouterPlugin = (
|
|
|
283
282
|
});
|
|
284
283
|
}
|
|
285
284
|
|
|
286
|
-
const RouterContent =
|
|
285
|
+
const RouterContent = hasSSRBootstrap ? (
|
|
287
286
|
<ModernRouterClient router={router} />
|
|
288
287
|
) : (
|
|
289
288
|
<RouterProvider router={router} />
|
|
@@ -292,7 +291,7 @@ export const tanstackRouterPlugin = (
|
|
|
292
291
|
RouterContent,
|
|
293
292
|
hasSSRBootstrap,
|
|
294
293
|
);
|
|
295
|
-
if (
|
|
294
|
+
if (hasSSRBootstrap) {
|
|
296
295
|
hooks.onAfterHydrateRouter.call({
|
|
297
296
|
...lifecycleContext,
|
|
298
297
|
phase: 'hydrate',
|
|
@@ -7,7 +7,7 @@ import { merge } from '@modern-js/runtime-utils/merge';
|
|
|
7
7
|
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
8
8
|
import type { RouterExtendsHooks } from './hooks';
|
|
9
9
|
import type { RouterConfig } from './types';
|
|
10
|
-
import { createTanstackRouteObjectsFromConfig
|
|
10
|
+
import { createTanstackRouteObjectsFromConfig } from './utils';
|
|
11
11
|
|
|
12
12
|
type TanstackRouterRuntimeConfig = {
|
|
13
13
|
plugins?: TanstackRouterRuntimePlugin[];
|
|
@@ -80,11 +80,9 @@ export function getTanstackRouteConfig(
|
|
|
80
80
|
export function createTanstackRouteObjects({
|
|
81
81
|
hooks,
|
|
82
82
|
routeConfig,
|
|
83
|
-
ssrMode,
|
|
84
83
|
}: {
|
|
85
84
|
hooks: RouterExtendsHooks;
|
|
86
85
|
routeConfig: TanstackRouteConfig;
|
|
87
|
-
ssrMode?: SSRMode;
|
|
88
86
|
}): RouteObject[] {
|
|
89
87
|
const { mergedConfig, finalRouteConfig } = routeConfig;
|
|
90
88
|
const routeObjects =
|
|
@@ -92,7 +90,6 @@ export function createTanstackRouteObjects({
|
|
|
92
90
|
? mergedConfig.createRoutes()
|
|
93
91
|
: (createTanstackRouteObjectsFromConfig({
|
|
94
92
|
routesConfig: finalRouteConfig,
|
|
95
|
-
ssrMode,
|
|
96
93
|
}) ?? []);
|
|
97
94
|
|
|
98
95
|
return hooks.modifyRoutes.call(routeObjects) as RouteObject[];
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
4
4
|
import { createElement, type ElementType } from 'react';
|
|
5
5
|
|
|
6
|
-
import type { ModernRouteObject
|
|
6
|
+
import type { ModernRouteObject } from './types';
|
|
7
7
|
|
|
8
8
|
type ModernRouteModule = {
|
|
9
9
|
Component?: unknown;
|
|
@@ -85,10 +85,7 @@ function createServerLazyImportComponent(
|
|
|
85
85
|
return Component;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
export function toRouteComponent(
|
|
89
|
-
routeObject: RouteObject,
|
|
90
|
-
options: RouteTreeOptions = {},
|
|
91
|
-
): unknown {
|
|
88
|
+
export function toRouteComponent(routeObject: RouteObject): unknown {
|
|
92
89
|
const route = routeObject as ModernRouteObject;
|
|
93
90
|
const lazyImport =
|
|
94
91
|
typeof route.lazyImport === 'function' ? route.lazyImport : undefined;
|
|
@@ -5,6 +5,7 @@ import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
|
5
5
|
import type { AnyRoute, AnyRouter } from '@tanstack/react-router';
|
|
6
6
|
import { rootRouteId } from '@tanstack/react-router';
|
|
7
7
|
|
|
8
|
+
import { createRouteStaticData } from '../../shared/routeStaticData';
|
|
8
9
|
import { withModernRouteMatchContext } from '../outlet';
|
|
9
10
|
import {
|
|
10
11
|
toErrorComponent,
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
} from './components';
|
|
14
15
|
import { createModernShouldReload, wrapRouteObjectLoader } from './loaders';
|
|
15
16
|
import { isRouteObjectPathlessLayout, toTanstackPath } from './paths';
|
|
16
|
-
import {
|
|
17
|
+
import { mergeModernRouteHandle } from './staticData';
|
|
17
18
|
import {
|
|
18
19
|
createTanstackRootRoute,
|
|
19
20
|
createTanstackRoute,
|
|
@@ -52,7 +53,7 @@ function createRouteFromRouteObject(opts: {
|
|
|
52
53
|
const stableFallbackId =
|
|
53
54
|
routeObject.id || modernRouteObject.file || pathlessFallbackId;
|
|
54
55
|
|
|
55
|
-
const component = toRouteComponent(routeObject
|
|
56
|
+
const component = toRouteComponent(routeObject);
|
|
56
57
|
const base: TanstackRouteOptions = {
|
|
57
58
|
getParentRoute: () => parent,
|
|
58
59
|
component,
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
// @effect-diagnostics asyncFunction:off strictBooleanExpressions:off
|
|
2
2
|
|
|
3
3
|
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
4
|
-
import { notFound } from '@tanstack/react-router';
|
|
5
|
-
|
|
6
4
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
getLoaderHref,
|
|
6
|
+
handleModernLoaderError,
|
|
7
|
+
handleModernLoaderResult,
|
|
8
|
+
mapSplatParamsForModernLoader,
|
|
11
9
|
} from '../loaderBridge';
|
|
12
10
|
import {
|
|
13
11
|
isTanstackRscPayloadNavigationEnabled,
|
|
@@ -16,7 +14,6 @@ import {
|
|
|
16
14
|
import type {
|
|
17
15
|
ModernRouteObject,
|
|
18
16
|
ModernShouldRevalidate,
|
|
19
|
-
RouteParams,
|
|
20
17
|
RouteRevalidationState,
|
|
21
18
|
RouteTreeOptions,
|
|
22
19
|
TanstackLoaderContext,
|
|
@@ -48,31 +45,11 @@ function normalizeModernLoaderResult(result: unknown): unknown {
|
|
|
48
45
|
}
|
|
49
46
|
|
|
50
47
|
function normalizeModernLoaderResponse(result: unknown): unknown {
|
|
51
|
-
|
|
52
|
-
if (isRedirectResponse(result)) {
|
|
53
|
-
const location = result.headers.get('Location') || '/';
|
|
54
|
-
throwTanstackRedirect(location);
|
|
55
|
-
}
|
|
56
|
-
if (result.status === 404) {
|
|
57
|
-
throw notFound();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return normalizeModernLoaderResult(result);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function createModernRequest(input: string, signal: AbortSignal) {
|
|
65
|
-
return new Request(input, { signal });
|
|
48
|
+
return normalizeModernLoaderResult(handleModernLoaderResult(result));
|
|
66
49
|
}
|
|
67
50
|
|
|
68
51
|
function getModernUrlFromLoaderContext(ctx: TanstackLoaderContext): URL {
|
|
69
|
-
const href =
|
|
70
|
-
typeof ctx?.location === 'string'
|
|
71
|
-
? ctx.location
|
|
72
|
-
: ctx?.location?.publicHref ||
|
|
73
|
-
ctx?.location?.href ||
|
|
74
|
-
ctx?.location?.url?.href ||
|
|
75
|
-
'/';
|
|
52
|
+
const href = getLoaderHref(ctx) || '/';
|
|
76
53
|
const baseRequest: Request | undefined =
|
|
77
54
|
ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
|
|
78
55
|
const baseUrl =
|
|
@@ -118,29 +95,6 @@ export function createModernShouldReload(
|
|
|
118
95
|
};
|
|
119
96
|
}
|
|
120
97
|
|
|
121
|
-
function isRouteObjectSplatRoute(route: RouteObject) {
|
|
122
|
-
return typeof route.path === 'string' && route.path.includes('*');
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function mapParamsForRouteObjectLoader({
|
|
126
|
-
route,
|
|
127
|
-
params,
|
|
128
|
-
}: {
|
|
129
|
-
route: RouteObject;
|
|
130
|
-
params: RouteParams;
|
|
131
|
-
}) {
|
|
132
|
-
if (isRouteObjectSplatRoute(route)) {
|
|
133
|
-
const { _splat, ...rest } = params as RouteParams & {
|
|
134
|
-
_splat?: string;
|
|
135
|
-
};
|
|
136
|
-
if (typeof _splat !== 'undefined') {
|
|
137
|
-
return { ...rest, '*': _splat };
|
|
138
|
-
}
|
|
139
|
-
return rest;
|
|
140
|
-
}
|
|
141
|
-
return params;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
98
|
export function wrapRouteObjectLoader(
|
|
145
99
|
route: RouteObject,
|
|
146
100
|
revalidationState?: RouteRevalidationState,
|
|
@@ -173,23 +127,17 @@ export function wrapRouteObjectLoader(
|
|
|
173
127
|
? ctx.context.request
|
|
174
128
|
: undefined;
|
|
175
129
|
|
|
176
|
-
const href =
|
|
177
|
-
typeof ctx?.location === 'string'
|
|
178
|
-
? ctx.location
|
|
179
|
-
: ctx?.location?.publicHref ||
|
|
180
|
-
ctx?.location?.href ||
|
|
181
|
-
ctx?.location?.url?.href ||
|
|
182
|
-
'';
|
|
130
|
+
const href = getLoaderHref(ctx);
|
|
183
131
|
|
|
184
132
|
const request =
|
|
185
133
|
baseRequest !== undefined
|
|
186
134
|
? new Request(baseRequest, { signal })
|
|
187
|
-
:
|
|
135
|
+
: new Request(href, { signal });
|
|
188
136
|
|
|
189
|
-
const params =
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
137
|
+
const params = mapSplatParamsForModernLoader(
|
|
138
|
+
ctx.params || {},
|
|
139
|
+
typeof route.path === 'string' && route.path.includes('*'),
|
|
140
|
+
);
|
|
193
141
|
|
|
194
142
|
const loadModernData = async () => {
|
|
195
143
|
const result = await routeLoader({
|
|
@@ -214,19 +162,7 @@ export function wrapRouteObjectLoader(
|
|
|
214
162
|
|
|
215
163
|
return loadModernData();
|
|
216
164
|
} catch (err) {
|
|
217
|
-
|
|
218
|
-
if (isTanstackRedirect(err)) {
|
|
219
|
-
throw err;
|
|
220
|
-
}
|
|
221
|
-
if (isRedirectResponse(err)) {
|
|
222
|
-
const location = err.headers.get('Location') || '/';
|
|
223
|
-
throwTanstackRedirect(location);
|
|
224
|
-
}
|
|
225
|
-
if (err.status === 404) {
|
|
226
|
-
throw notFound();
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
throw err;
|
|
165
|
+
handleModernLoaderError(err);
|
|
230
166
|
}
|
|
231
167
|
};
|
|
232
168
|
}
|