@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.12 → 3.2.0-ultramodern.121
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 +89 -31
- package/dist/cjs/cli/routeSplitting.js +55 -0
- package/dist/cjs/cli/tanstackTypes.js +172 -170
- package/dist/cjs/cli.js +12 -8
- package/dist/cjs/runtime/basepathRewrite.js +12 -8
- package/dist/cjs/runtime/dataMutation.js +9 -5
- package/dist/cjs/runtime/hooks.js +20 -19
- package/dist/cjs/runtime/hydrationBoundary.js +48 -0
- package/dist/cjs/runtime/index.js +79 -35
- package/dist/cjs/runtime/lifecycle.js +21 -91
- package/dist/cjs/runtime/loaderBridge.js +173 -0
- package/dist/cjs/runtime/outlet.js +58 -0
- package/dist/cjs/runtime/plugin.js +195 -114
- package/dist/cjs/runtime/plugin.node.js +45 -45
- package/dist/cjs/runtime/plugin.worker.js +53 -0
- package/dist/cjs/runtime/pluginCore.js +55 -0
- package/dist/cjs/runtime/prefetchLink.js +10 -6
- package/dist/cjs/runtime/register.js +56 -0
- package/dist/cjs/runtime/routeTree.js +74 -207
- package/dist/cjs/runtime/router.js +41 -0
- 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 +44 -6
- 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/state.js +45 -0
- package/dist/cjs/runtime/types.js +31 -1
- package/dist/cjs/runtime/utils.js +9 -10
- package/dist/cjs/runtime.js +9 -5
- package/dist/esm/cli/index.mjs +75 -27
- package/dist/esm/cli/routeSplitting.mjs +14 -0
- package/dist/esm/cli/tanstackTypes.mjs +158 -160
- package/dist/esm/runtime/hooks.mjs +1 -8
- package/dist/esm/runtime/hydrationBoundary.mjs +10 -0
- package/dist/esm/runtime/index.mjs +5 -2
- package/dist/esm/runtime/lifecycle.mjs +1 -82
- package/dist/esm/runtime/loaderBridge.mjs +114 -0
- package/dist/esm/runtime/outlet.mjs +17 -0
- package/dist/esm/runtime/plugin.mjs +191 -114
- package/dist/esm/runtime/plugin.node.mjs +40 -44
- package/dist/esm/runtime/plugin.worker.mjs +1 -0
- package/dist/esm/runtime/pluginCore.mjs +14 -0
- package/dist/esm/runtime/prefetchLink.mjs +1 -1
- package/dist/esm/runtime/register.mjs +18 -0
- package/dist/esm/runtime/routeTree.mjs +59 -193
- package/dist/esm/runtime/router.mjs +2 -0
- package/dist/esm/runtime/rsc/payloadRouter.mjs +35 -1
- package/dist/esm/runtime/state.mjs +7 -0
- package/dist/esm/runtime/types.mjs +7 -0
- package/dist/esm/runtime/utils.mjs +0 -5
- package/dist/esm-node/cli/index.mjs +75 -27
- package/dist/esm-node/cli/routeSplitting.mjs +15 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +158 -160
- package/dist/esm-node/runtime/hooks.mjs +1 -8
- package/dist/esm-node/runtime/hydrationBoundary.mjs +11 -0
- package/dist/esm-node/runtime/index.mjs +5 -2
- package/dist/esm-node/runtime/lifecycle.mjs +1 -82
- package/dist/esm-node/runtime/loaderBridge.mjs +115 -0
- package/dist/esm-node/runtime/outlet.mjs +18 -0
- package/dist/esm-node/runtime/plugin.mjs +191 -114
- package/dist/esm-node/runtime/plugin.node.mjs +40 -44
- package/dist/esm-node/runtime/plugin.worker.mjs +2 -0
- package/dist/esm-node/runtime/pluginCore.mjs +15 -0
- package/dist/esm-node/runtime/prefetchLink.mjs +1 -1
- package/dist/esm-node/runtime/register.mjs +19 -0
- package/dist/esm-node/runtime/routeTree.mjs +59 -193
- package/dist/esm-node/runtime/router.mjs +3 -0
- package/dist/esm-node/runtime/rsc/payloadRouter.mjs +35 -1
- package/dist/esm-node/runtime/state.mjs +8 -0
- package/dist/esm-node/runtime/types.mjs +7 -0
- package/dist/esm-node/runtime/utils.mjs +0 -5
- package/dist/types/cli/index.d.ts +14 -1
- package/dist/types/cli/routeSplitting.d.ts +20 -0
- package/dist/types/cli/tanstackTypes.d.ts +21 -1
- package/dist/types/runtime/hooks.d.ts +8 -33
- package/dist/types/runtime/hydrationBoundary.d.ts +2 -0
- package/dist/types/runtime/index.d.ts +8 -3
- package/dist/types/runtime/lifecycle.d.ts +7 -22
- package/dist/types/runtime/loaderBridge.d.ts +48 -0
- package/dist/types/runtime/outlet.d.ts +2 -0
- package/dist/types/runtime/plugin.d.ts +2 -15
- package/dist/types/runtime/plugin.node.d.ts +2 -15
- package/dist/types/runtime/plugin.worker.d.ts +1 -0
- package/dist/types/runtime/pluginCore.d.ts +21 -0
- package/dist/types/runtime/register.d.ts +9 -0
- package/dist/types/runtime/routeTree.d.ts +0 -2
- package/dist/types/runtime/router.d.ts +14 -0
- package/dist/types/runtime/state.d.ts +16 -0
- package/dist/types/runtime/types.d.ts +14 -53
- package/package.json +42 -40
- package/rstest.config.mts +6 -0
- package/src/cli/index.ts +162 -23
- package/src/cli/routeSplitting.ts +43 -0
- package/src/cli/tanstackTypes.ts +331 -187
- package/src/runtime/hooks.ts +10 -27
- package/src/runtime/hydrationBoundary.tsx +12 -0
- package/src/runtime/index.tsx +17 -7
- package/src/runtime/lifecycle.ts +16 -151
- package/src/runtime/loaderBridge.ts +257 -0
- package/src/runtime/outlet.tsx +48 -0
- package/src/runtime/plugin.node.tsx +72 -85
- package/src/runtime/plugin.tsx +361 -206
- package/src/runtime/plugin.worker.tsx +4 -0
- package/src/runtime/pluginCore.ts +48 -0
- package/src/runtime/prefetchLink.tsx +1 -1
- package/src/runtime/register.ts +58 -0
- package/src/runtime/routeTree.ts +163 -354
- package/src/runtime/router.ts +15 -0
- package/src/runtime/rsc/payloadRouter.ts +45 -2
- package/src/runtime/ssr-shim.d.ts +1 -3
- package/src/runtime/state.ts +29 -0
- package/src/runtime/types.ts +32 -66
- package/src/runtime/utils.tsx +3 -6
- package/tests/router/cli.test.ts +586 -5
- package/tests/router/fastDefaults.test.ts +25 -0
- package/tests/router/hooks.test.ts +26 -0
- package/tests/router/hydrationBoundary.test.tsx +23 -0
- package/tests/router/loaderBridge.test.ts +211 -0
- package/tests/router/packageSurface.test.ts +24 -0
- package/tests/router/prefetchLink.test.tsx +43 -7
- package/tests/router/register.test.ts +46 -0
- package/tests/router/routeTree.test.ts +381 -81
- package/tests/router/rsc.test.tsx +70 -0
- package/tests/router/tanstackTypes.test.ts +573 -1
- package/dist/cjs/runtime/DefaultNotFound.js +0 -47
- package/dist/esm/runtime/DefaultNotFound.mjs +0 -13
- package/dist/esm-node/runtime/DefaultNotFound.mjs +0 -14
- package/dist/types/runtime/DefaultNotFound.d.ts +0 -2
- package/src/runtime/DefaultNotFound.tsx +0 -15
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// @effect-diagnostics asyncFunction:off globalFetch:off strictBooleanExpressions:off
|
|
1
|
+
// @effect-diagnostics asyncFunction:off globalFetch:off processEnv:off strictBooleanExpressions:off
|
|
2
2
|
import type { PayloadRoute, ServerPayload } from '@modern-js/runtime/context';
|
|
3
|
+
import { isRouteErrorResponse } from '@modern-js/runtime-utils/router';
|
|
3
4
|
import { notFound, redirect } from '@tanstack/react-router';
|
|
4
5
|
|
|
5
6
|
type PayloadDecoder = (stream: ReadableStream<Uint8Array>) => Promise<unknown>;
|
|
@@ -103,6 +104,48 @@ function toPayloadRoute(match: RouterMatchLike): PayloadRoute | undefined {
|
|
|
103
104
|
};
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
function shouldRedactServerError(status = 500) {
|
|
108
|
+
return (
|
|
109
|
+
status >= 500 &&
|
|
110
|
+
process.env.NODE_ENV !== 'development' &&
|
|
111
|
+
process.env.NODE_ENV !== 'test'
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function serializePayloadError(error: unknown): unknown {
|
|
116
|
+
if (isRouteErrorResponse(error)) {
|
|
117
|
+
if (shouldRedactServerError(error.status)) {
|
|
118
|
+
return {
|
|
119
|
+
status: error.status,
|
|
120
|
+
statusText: 'Internal Server Error',
|
|
121
|
+
data: 'Unexpected Server Error',
|
|
122
|
+
__type: 'RouteErrorResponse',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return { ...error, __type: 'RouteErrorResponse' };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (error instanceof Error) {
|
|
130
|
+
if (shouldRedactServerError()) {
|
|
131
|
+
return {
|
|
132
|
+
message: 'Unexpected Server Error',
|
|
133
|
+
stack: undefined,
|
|
134
|
+
__type: 'Error',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
message: error.message,
|
|
140
|
+
stack: error.stack,
|
|
141
|
+
__type: 'Error',
|
|
142
|
+
...(error.name !== 'Error' ? { __subType: error.name } : {}),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return error;
|
|
147
|
+
}
|
|
148
|
+
|
|
106
149
|
export function createTanstackRscServerPayload(
|
|
107
150
|
router: TanstackPayloadRouterLike,
|
|
108
151
|
options: {
|
|
@@ -133,7 +176,7 @@ export function createTanstackRscServerPayload(
|
|
|
133
176
|
}
|
|
134
177
|
|
|
135
178
|
if (typeof match.error !== 'undefined') {
|
|
136
|
-
errors[payloadRoute.id] = match.error;
|
|
179
|
+
errors[payloadRoute.id] = serializePayloadError(match.error);
|
|
137
180
|
}
|
|
138
181
|
}
|
|
139
182
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
declare module '@tanstack/react-router/ssr/client' {
|
|
2
|
-
export function
|
|
3
|
-
router: unknown;
|
|
4
|
-
}): import('react').JSX.Element;
|
|
2
|
+
export function hydrate(router: unknown): Promise<unknown>;
|
|
5
3
|
}
|
|
6
4
|
|
|
7
5
|
declare module '@tanstack/react-router/ssr/server' {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getRouterRuntimeState } from '@modern-js/runtime/context';
|
|
2
|
+
import type { AnyRouter } from '@tanstack/react-router';
|
|
3
|
+
import type { InternalRouterRuntimeState } from './types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Router runtime state as published by the TanStack router provider into the
|
|
7
|
+
* runtime-context extension slot.
|
|
8
|
+
*/
|
|
9
|
+
export interface TanstackRouterState
|
|
10
|
+
extends Omit<InternalRouterRuntimeState, 'framework' | 'instance'> {
|
|
11
|
+
framework: 'tanstack';
|
|
12
|
+
instance?: AnyRouter;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Typed accessor for the TanStack router state stored on a Modern.js runtime
|
|
17
|
+
* context. Returns `undefined` when the active router provider is not
|
|
18
|
+
* TanStack (e.g. react-router) or no router has been created yet.
|
|
19
|
+
*/
|
|
20
|
+
export function getTanstackRouterState(
|
|
21
|
+
context: object,
|
|
22
|
+
): TanstackRouterState | undefined {
|
|
23
|
+
const state = getRouterRuntimeState(context);
|
|
24
|
+
if (state === undefined || state.framework !== 'tanstack') {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return state as TanstackRouterState;
|
|
29
|
+
}
|
package/src/runtime/types.ts
CHANGED
|
@@ -1,83 +1,49 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
RouterFramework,
|
|
3
|
+
// The router runtime state types are owned by @modern-js/runtime; they are
|
|
4
|
+
// imported through the `/context` seam instead of being copied here so
|
|
5
|
+
// upstream fixes propagate to this package automatically.
|
|
6
|
+
} from '@modern-js/runtime/context';
|
|
2
7
|
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
3
8
|
import type { NestedRoute, PageRoute } from '@modern-js/types';
|
|
4
9
|
import type React from 'react';
|
|
5
10
|
|
|
6
|
-
export type
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
export type {
|
|
12
|
+
BuiltInRouterFramework,
|
|
13
|
+
InternalRouterRuntimeState,
|
|
14
|
+
InternalRouterServerSnapshot,
|
|
15
|
+
RouterFramework,
|
|
16
|
+
RouterRouteMatchSnapshot,
|
|
17
|
+
RouterServerPrepareResult,
|
|
18
|
+
} from '@modern-js/runtime/context';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* TanStack-specific router config. Unlike the react-router provider config,
|
|
22
|
+
* this intentionally has no `oldVersion`/`future` fields — those are
|
|
23
|
+
* react-router-only knobs with no meaning here.
|
|
24
|
+
*/
|
|
9
25
|
export type RouterConfig = {
|
|
10
26
|
framework?: RouterFramework;
|
|
11
27
|
routesConfig: {
|
|
12
28
|
globalApp?: React.ComponentType<any>;
|
|
13
29
|
routes?: (NestedRoute | PageRoute)[];
|
|
14
30
|
};
|
|
15
|
-
oldVersion?: boolean;
|
|
16
31
|
serverBase?: string[];
|
|
17
32
|
supportHtml5History?: boolean;
|
|
18
33
|
basename?: string;
|
|
19
34
|
createRoutes?: () => RouteObject[];
|
|
20
|
-
|
|
21
|
-
v7_startTransition: boolean;
|
|
22
|
-
}>;
|
|
35
|
+
defaultStructuralSharing?: boolean;
|
|
23
36
|
unstable_reloadOnURLMismatch?: boolean;
|
|
24
37
|
};
|
|
25
38
|
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
errors?: Record<string, unknown>;
|
|
38
|
-
routerData?: {
|
|
39
|
-
loaderData?: Record<string, unknown>;
|
|
40
|
-
errors?: Record<string, unknown>;
|
|
41
|
-
};
|
|
42
|
-
hydrationScript?: string;
|
|
43
|
-
hydrationScripts?: string[];
|
|
44
|
-
matchedRouteIds?: string[];
|
|
45
|
-
matches?: RouterRouteMatchSnapshot[];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface InternalRouterRuntimeState {
|
|
49
|
-
framework: RouterFramework;
|
|
50
|
-
basename?: string;
|
|
51
|
-
instance?: unknown;
|
|
52
|
-
hydrationScript?: string;
|
|
53
|
-
hydrationScripts?: string[];
|
|
54
|
-
matchedRouteIds?: string[];
|
|
55
|
-
matches?: RouterRouteMatchSnapshot[];
|
|
56
|
-
serverSnapshot?: InternalRouterServerSnapshot;
|
|
57
|
-
cleanup?: () => void | Promise<void>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface RouterServerPrepareResult {
|
|
61
|
-
state: InternalRouterRuntimeState;
|
|
62
|
-
snapshot?: InternalRouterServerSnapshot;
|
|
63
|
-
redirect?: Response;
|
|
64
|
-
cleanup?: () => void | Promise<void>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
interface DataFunctionArgs<D = any> {
|
|
68
|
-
request: Request;
|
|
69
|
-
params: Record<string, string>;
|
|
70
|
-
context?: D;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export type LoaderFunctionArgs<
|
|
74
|
-
P extends Record<string, unknown> = Record<string, unknown>,
|
|
75
|
-
> = DataFunctionArgs<RequestContext<P>>;
|
|
76
|
-
|
|
77
|
-
type DataFunctionValue = Response | NonNullable<unknown> | null;
|
|
78
|
-
|
|
79
|
-
export type LoaderFunction = <
|
|
80
|
-
P extends Record<string, unknown> = Record<string, unknown>,
|
|
81
|
-
>(
|
|
82
|
-
args: LoaderFunctionArgs<P>,
|
|
83
|
-
) => Promise<DataFunctionValue> | DataFunctionValue;
|
|
39
|
+
export const modernTanstackRouterFastDefaults = {
|
|
40
|
+
defaultStructuralSharing: true,
|
|
41
|
+
} as const;
|
|
42
|
+
|
|
43
|
+
export const getModernTanstackRouterFastDefaults = (
|
|
44
|
+
config: Partial<Pick<RouterConfig, 'defaultStructuralSharing'>> = {},
|
|
45
|
+
) => ({
|
|
46
|
+
defaultStructuralSharing:
|
|
47
|
+
config.defaultStructuralSharing ??
|
|
48
|
+
modernTanstackRouterFastDefaults.defaultStructuralSharing,
|
|
49
|
+
});
|
package/src/runtime/utils.tsx
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import type { RouteObject } from '@modern-js/runtime-utils/router';
|
|
3
3
|
import type { NestedRoute, PageRoute, SSRMode } from '@modern-js/types';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import { DefaultNotFound } from './DefaultNotFound';
|
|
6
5
|
|
|
7
6
|
type RouterConfig = {
|
|
8
7
|
routesConfig: {
|
|
@@ -106,11 +105,9 @@ export function getRouteObjects(
|
|
|
106
105
|
}
|
|
107
106
|
}
|
|
108
107
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
});
|
|
113
|
-
|
|
108
|
+
// No synthetic `{ path: '*' }` 404 route here: TanStack Router handles
|
|
109
|
+
// not-found matches through the root route's `notFoundComponent`
|
|
110
|
+
// (see routeTree.ts), so the react-router style catch-all is unnecessary.
|
|
114
111
|
return routeObjects;
|
|
115
112
|
}
|
|
116
113
|
|