@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.0
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/LICENSE +21 -0
- package/dist/cjs/cli/index.js +268 -0
- package/dist/cjs/cli/tanstackTypes.js +388 -0
- package/dist/cjs/cli.js +65 -0
- package/dist/cjs/runtime/DefaultNotFound.js +47 -0
- package/dist/cjs/runtime/basepathRewrite.js +62 -0
- package/dist/cjs/runtime/dataMutation.js +345 -0
- package/dist/cjs/runtime/hooks.js +57 -0
- package/dist/cjs/runtime/index.js +114 -0
- package/dist/cjs/runtime/lifecycle.js +125 -0
- package/dist/cjs/runtime/plugin.js +250 -0
- package/dist/cjs/runtime/plugin.node.js +304 -0
- package/dist/cjs/runtime/prefetchLink.js +55 -0
- package/dist/cjs/runtime/routeTree.js +492 -0
- package/dist/cjs/runtime/rsc/ClientSlot.js +53 -0
- package/dist/cjs/runtime/rsc/CompositeComponent.js +75 -0
- package/dist/cjs/runtime/rsc/ReplayableStream.js +141 -0
- package/dist/cjs/runtime/rsc/RscNodeRenderer.js +65 -0
- package/dist/cjs/runtime/rsc/SlotContext.js +54 -0
- package/dist/cjs/runtime/rsc/client.js +93 -0
- package/dist/cjs/runtime/rsc/createRscProxy.js +141 -0
- package/dist/cjs/runtime/rsc/index.js +42 -0
- package/dist/cjs/runtime/rsc/payloadRouter.js +211 -0
- package/dist/cjs/runtime/rsc/server.js +246 -0
- package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +65 -0
- package/dist/cjs/runtime/rsc/symbols.js +72 -0
- package/dist/cjs/runtime/types.js +18 -0
- package/dist/cjs/runtime/utils.js +142 -0
- package/dist/cjs/runtime.js +58 -0
- package/dist/esm/cli/index.mjs +201 -0
- package/dist/esm/cli/tanstackTypes.mjs +341 -0
- package/dist/esm/cli.mjs +2 -0
- package/dist/esm/rslib-runtime.mjs +18 -0
- package/dist/esm/runtime/DefaultNotFound.mjs +13 -0
- package/dist/esm/runtime/basepathRewrite.mjs +28 -0
- package/dist/esm/runtime/dataMutation.mjs +305 -0
- package/dist/esm/runtime/hooks.mjs +8 -0
- package/dist/esm/runtime/index.mjs +6 -0
- package/dist/esm/runtime/lifecycle.mjs +82 -0
- package/dist/esm/runtime/plugin.mjs +214 -0
- package/dist/esm/runtime/plugin.node.mjs +268 -0
- package/dist/esm/runtime/prefetchLink.mjs +18 -0
- package/dist/esm/runtime/routeTree.mjs +452 -0
- package/dist/esm/runtime/rsc/ClientSlot.mjs +19 -0
- package/dist/esm/runtime/rsc/CompositeComponent.mjs +41 -0
- package/dist/esm/runtime/rsc/ReplayableStream.mjs +104 -0
- package/dist/esm/runtime/rsc/RscNodeRenderer.mjs +31 -0
- package/dist/esm/runtime/rsc/SlotContext.mjs +17 -0
- package/dist/esm/runtime/rsc/client.mjs +53 -0
- package/dist/esm/runtime/rsc/createRscProxy.mjs +107 -0
- package/dist/esm/runtime/rsc/index.mjs +1 -0
- package/dist/esm/runtime/rsc/payloadRouter.mjs +162 -0
- package/dist/esm/runtime/rsc/server.mjs +200 -0
- package/dist/esm/runtime/rsc/slotUsageSanitizer.mjs +31 -0
- package/dist/esm/runtime/rsc/symbols.mjs +17 -0
- package/dist/esm/runtime/types.mjs +0 -0
- package/dist/esm/runtime/utils.mjs +89 -0
- package/dist/esm/runtime.mjs +1 -0
- package/dist/esm-node/cli/index.mjs +205 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +342 -0
- package/dist/esm-node/cli.mjs +3 -0
- package/dist/esm-node/rslib-runtime.mjs +19 -0
- package/dist/esm-node/runtime/DefaultNotFound.mjs +14 -0
- package/dist/esm-node/runtime/basepathRewrite.mjs +29 -0
- package/dist/esm-node/runtime/dataMutation.mjs +306 -0
- package/dist/esm-node/runtime/hooks.mjs +9 -0
- package/dist/esm-node/runtime/index.mjs +7 -0
- package/dist/esm-node/runtime/lifecycle.mjs +83 -0
- package/dist/esm-node/runtime/plugin.mjs +215 -0
- package/dist/esm-node/runtime/plugin.node.mjs +269 -0
- package/dist/esm-node/runtime/prefetchLink.mjs +19 -0
- package/dist/esm-node/runtime/routeTree.mjs +453 -0
- package/dist/esm-node/runtime/rsc/ClientSlot.mjs +20 -0
- package/dist/esm-node/runtime/rsc/CompositeComponent.mjs +42 -0
- package/dist/esm-node/runtime/rsc/ReplayableStream.mjs +105 -0
- package/dist/esm-node/runtime/rsc/RscNodeRenderer.mjs +32 -0
- package/dist/esm-node/runtime/rsc/SlotContext.mjs +18 -0
- package/dist/esm-node/runtime/rsc/client.mjs +54 -0
- package/dist/esm-node/runtime/rsc/createRscProxy.mjs +108 -0
- package/dist/esm-node/runtime/rsc/index.mjs +2 -0
- package/dist/esm-node/runtime/rsc/payloadRouter.mjs +163 -0
- package/dist/esm-node/runtime/rsc/server.mjs +201 -0
- package/dist/esm-node/runtime/rsc/slotUsageSanitizer.mjs +32 -0
- package/dist/esm-node/runtime/rsc/symbols.mjs +18 -0
- package/dist/esm-node/runtime/types.mjs +1 -0
- package/dist/esm-node/runtime/utils.mjs +90 -0
- package/dist/esm-node/runtime.mjs +2 -0
- package/dist/types/cli/index.d.ts +20 -0
- package/dist/types/cli/tanstackTypes.d.ts +11 -0
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types/runtime/basepathRewrite.d.ts +8 -0
- package/dist/types/runtime/dataMutation.d.ts +29 -0
- package/dist/types/runtime/hooks.d.ts +18 -0
- package/dist/types/runtime/index.d.ts +9 -0
- package/dist/types/runtime/lifecycle.d.ts +22 -0
- package/dist/types/runtime/plugin.d.ts +17 -0
- package/dist/types/runtime/plugin.node.d.ts +17 -0
- package/dist/types/runtime/prefetchLink.d.ts +11 -0
- package/dist/types/runtime/routeTree.d.ts +11 -0
- package/dist/types/runtime/rsc/ClientSlot.d.ts +5 -0
- package/dist/types/runtime/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types/runtime/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types/runtime/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types/runtime/rsc/SlotContext.d.ts +11 -0
- package/dist/types/runtime/rsc/client.d.ts +11 -0
- package/dist/types/runtime/rsc/createRscProxy.d.ts +7 -0
- package/dist/types/runtime/rsc/index.d.ts +2 -0
- package/dist/types/runtime/rsc/payloadRouter.d.ts +24 -0
- package/dist/types/runtime/rsc/server.d.ts +14 -0
- package/dist/types/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types/runtime/rsc/symbols.d.ts +46 -0
- package/dist/types/runtime/types.d.ts +68 -0
- package/dist/types/runtime/utils.d.ts +36 -0
- package/dist/types/runtime.d.ts +1 -0
- package/dist/types-direct/cli/index.d.ts +20 -0
- package/dist/types-direct/cli/tanstackTypes.d.ts +11 -0
- package/dist/types-direct/cli.d.ts +2 -0
- package/dist/types-direct/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types-direct/runtime/basepathRewrite.d.ts +8 -0
- package/dist/types-direct/runtime/dataMutation.d.ts +29 -0
- package/dist/types-direct/runtime/hooks.d.ts +18 -0
- package/dist/types-direct/runtime/index.d.ts +9 -0
- package/dist/types-direct/runtime/lifecycle.d.ts +22 -0
- package/dist/types-direct/runtime/plugin.d.ts +17 -0
- package/dist/types-direct/runtime/plugin.node.d.ts +17 -0
- package/dist/types-direct/runtime/prefetchLink.d.ts +11 -0
- package/dist/types-direct/runtime/routeTree.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/ClientSlot.d.ts +5 -0
- package/dist/types-direct/runtime/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types-direct/runtime/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types-direct/runtime/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types-direct/runtime/rsc/SlotContext.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/client.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/createRscProxy.d.ts +7 -0
- package/dist/types-direct/runtime/rsc/index.d.ts +2 -0
- package/dist/types-direct/runtime/rsc/payloadRouter.d.ts +24 -0
- package/dist/types-direct/runtime/rsc/server.d.ts +14 -0
- package/dist/types-direct/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types-direct/runtime/rsc/symbols.d.ts +46 -0
- package/dist/types-direct/runtime/types.d.ts +68 -0
- package/dist/types-direct/runtime/utils.d.ts +36 -0
- package/dist/types-direct/runtime.d.ts +1 -0
- package/package.json +126 -0
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +43 -0
- package/src/cli/index.ts +388 -0
- package/src/cli/tanstackTypes.ts +503 -0
- package/src/cli.ts +2 -0
- package/src/runtime/DefaultNotFound.tsx +15 -0
- package/src/runtime/basepathRewrite.ts +59 -0
- package/src/runtime/dataMutation.tsx +517 -0
- package/src/runtime/hooks.ts +34 -0
- package/src/runtime/index.tsx +30 -0
- package/src/runtime/lifecycle.ts +150 -0
- package/src/runtime/plugin.node.tsx +534 -0
- package/src/runtime/plugin.tsx +395 -0
- package/src/runtime/prefetchLink.tsx +87 -0
- package/src/runtime/routeTree.ts +942 -0
- package/src/runtime/rsc/ClientSlot.tsx +25 -0
- package/src/runtime/rsc/CompositeComponent.tsx +65 -0
- package/src/runtime/rsc/ReplayableStream.ts +155 -0
- package/src/runtime/rsc/RscNodeRenderer.tsx +45 -0
- package/src/runtime/rsc/SlotContext.tsx +31 -0
- package/src/runtime/rsc/client.tsx +90 -0
- package/src/runtime/rsc/createRscProxy.tsx +189 -0
- package/src/runtime/rsc/index.ts +10 -0
- package/src/runtime/rsc/payloadRouter.ts +318 -0
- package/src/runtime/rsc/server.tsx +303 -0
- package/src/runtime/rsc/slotUsageSanitizer.ts +76 -0
- package/src/runtime/rsc/symbols.ts +106 -0
- package/src/runtime/ssr-shim.d.ts +12 -0
- package/src/runtime/types.ts +83 -0
- package/src/runtime/utils.tsx +161 -0
- package/src/runtime.ts +1 -0
- package/tests/router/cli.test.ts +386 -0
- package/tests/router/dataMutation.test.tsx +396 -0
- package/tests/router/prefetchLink.test.tsx +43 -0
- package/tests/router/routeTree.test.ts +502 -0
- package/tests/router/rsc.test.tsx +256 -0
- package/tests/router/tanstackTypes.test.ts +62 -0
- package/tsconfig.json +12 -0
- package/tsconfig.tsgo.json +6 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { isValidElement } from 'react';
|
|
3
|
+
import { createRscProxy } from '../../src/runtime/rsc/createRscProxy';
|
|
4
|
+
import {
|
|
5
|
+
__setTanstackRscPayloadDecoderForTests,
|
|
6
|
+
createTanstackRscServerPayload,
|
|
7
|
+
handleTanstackRscRedirect,
|
|
8
|
+
loadTanstackRscRouteData,
|
|
9
|
+
} from '../../src/runtime/rsc/payloadRouter';
|
|
10
|
+
import { ReplayableStream } from '../../src/runtime/rsc/ReplayableStream';
|
|
11
|
+
import {
|
|
12
|
+
RENDERABLE_RSC,
|
|
13
|
+
RSC_PROXY_PATH,
|
|
14
|
+
SERVER_COMPONENT_STREAM,
|
|
15
|
+
type ServerComponentStream,
|
|
16
|
+
} from '../../src/runtime/rsc/symbols';
|
|
17
|
+
|
|
18
|
+
async function readAll(stream: ReadableStream<Uint8Array>) {
|
|
19
|
+
const reader = stream.getReader();
|
|
20
|
+
const chunks: number[] = [];
|
|
21
|
+
|
|
22
|
+
for (;;) {
|
|
23
|
+
const { done, value } = await reader.read();
|
|
24
|
+
if (done) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
chunks.push(...value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return chunks;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe('tanstack rsc runtime helpers', () => {
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
__setTanstackRscPayloadDecoderForTests();
|
|
36
|
+
rstest.restoreAllMocks();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('ReplayableStream creates independent readers from one source', async () => {
|
|
40
|
+
const source = new ReadableStream<Uint8Array>({
|
|
41
|
+
start(controller) {
|
|
42
|
+
controller.enqueue(new Uint8Array([1, 2]));
|
|
43
|
+
controller.enqueue(new Uint8Array([3]));
|
|
44
|
+
controller.close();
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const replayable = new ReplayableStream(source);
|
|
48
|
+
|
|
49
|
+
await expect(readAll(replayable.createReplayStream())).resolves.toEqual([
|
|
50
|
+
1, 2, 3,
|
|
51
|
+
]);
|
|
52
|
+
await expect(readAll(replayable.createReplayStream())).resolves.toEqual([
|
|
53
|
+
1, 2, 3,
|
|
54
|
+
]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('renderable RSC proxies preserve React element behavior and metadata', () => {
|
|
58
|
+
const stream: ServerComponentStream = {
|
|
59
|
+
createReplayStream: () => new ReadableStream<Uint8Array>(),
|
|
60
|
+
};
|
|
61
|
+
const proxy = createRscProxy(() => ({ sidebar: 'ok' }), {
|
|
62
|
+
renderable: true,
|
|
63
|
+
stream,
|
|
64
|
+
}) as React.ReactElement & Record<PropertyKey, unknown>;
|
|
65
|
+
|
|
66
|
+
expect(isValidElement(proxy)).toBe(true);
|
|
67
|
+
expect(proxy[SERVER_COMPONENT_STREAM]).toBe(stream);
|
|
68
|
+
expect(proxy[RENDERABLE_RSC]).toBe(true);
|
|
69
|
+
expect(proxy.then).toBeUndefined();
|
|
70
|
+
expect('__SEROVAL_STREAM__' in proxy).toBe(false);
|
|
71
|
+
expect('__SEROVAL_SEQUENCE__' in proxy).toBe(false);
|
|
72
|
+
expect(Symbol.iterator in proxy).toBe(false);
|
|
73
|
+
|
|
74
|
+
const sidebar = proxy.sidebar as Record<PropertyKey, unknown>;
|
|
75
|
+
expect(sidebar[RSC_PROXY_PATH]).toEqual(['sidebar']);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('creates TanStack RSC server payload and omits client-loader data during RSC navigation', () => {
|
|
79
|
+
const payload = createTanstackRscServerPayload(
|
|
80
|
+
{
|
|
81
|
+
state: {
|
|
82
|
+
location: { href: '/products' },
|
|
83
|
+
matches: [
|
|
84
|
+
{
|
|
85
|
+
loaderData: { shell: true },
|
|
86
|
+
params: {},
|
|
87
|
+
pathname: '/',
|
|
88
|
+
pathnameBase: '/',
|
|
89
|
+
route: {
|
|
90
|
+
id: '__root__',
|
|
91
|
+
options: {
|
|
92
|
+
staticData: {
|
|
93
|
+
modernRouteHasLoader: true,
|
|
94
|
+
modernRouteId: 'root',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
routeId: '__root__',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
loaderData: { product: 1 },
|
|
102
|
+
params: {},
|
|
103
|
+
pathname: '/products',
|
|
104
|
+
pathnameBase: '/products',
|
|
105
|
+
route: {
|
|
106
|
+
id: '/products',
|
|
107
|
+
parentRoute: { id: '__root__' },
|
|
108
|
+
options: {
|
|
109
|
+
path: 'products',
|
|
110
|
+
staticData: {
|
|
111
|
+
modernRouteHandle: { section: 'shop' },
|
|
112
|
+
modernRouteHasClientLoader: true,
|
|
113
|
+
modernRouteHasLoader: true,
|
|
114
|
+
modernRouteId: 'products',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
routeId: '/products',
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{ omitClientLoaderData: true },
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(payload).toMatchObject({
|
|
127
|
+
type: 'render',
|
|
128
|
+
loaderData: {
|
|
129
|
+
__root__: { shell: true },
|
|
130
|
+
},
|
|
131
|
+
routes: [
|
|
132
|
+
{
|
|
133
|
+
hasClientLoader: false,
|
|
134
|
+
hasLoader: true,
|
|
135
|
+
id: '__root__',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
handle: { section: 'shop' },
|
|
139
|
+
hasClientLoader: true,
|
|
140
|
+
hasLoader: true,
|
|
141
|
+
id: '/products',
|
|
142
|
+
parentId: '__root__',
|
|
143
|
+
path: 'products',
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
});
|
|
147
|
+
expect(
|
|
148
|
+
(payload.loaderData as Record<string, unknown>)['/products'],
|
|
149
|
+
).toBeUndefined();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('converts TanStack RSC redirects to Modern RSC navigation headers', () => {
|
|
153
|
+
const response = handleTanstackRscRedirect(
|
|
154
|
+
new Headers({ Location: '/base/login' }),
|
|
155
|
+
'/base',
|
|
156
|
+
302,
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
expect(response.status).toBe(302);
|
|
160
|
+
expect(response.headers.get('Location')).toBeNull();
|
|
161
|
+
expect(response.headers.get('X-Modernjs-Redirect')).toBe('/login');
|
|
162
|
+
expect(response.headers.get('X-Modernjs-BaseUrl')).toBe('/base');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('loads one RSC payload for multiple server route loaders', async () => {
|
|
166
|
+
const payload = {
|
|
167
|
+
type: 'render',
|
|
168
|
+
actionData: null,
|
|
169
|
+
errors: null,
|
|
170
|
+
loaderData: {
|
|
171
|
+
__root__: { shell: true },
|
|
172
|
+
'/products': { product: 1 },
|
|
173
|
+
},
|
|
174
|
+
location: { href: '/products' },
|
|
175
|
+
routes: [
|
|
176
|
+
{ id: '__root__', hasLoader: true },
|
|
177
|
+
{ id: '/products', hasLoader: true },
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
const fetchMock = rstest.fn(() => Promise.resolve(new Response('payload')));
|
|
181
|
+
const decodeMock = rstest.fn(async () => payload);
|
|
182
|
+
rstest.stubGlobal('fetch', fetchMock);
|
|
183
|
+
__setTanstackRscPayloadDecoderForTests(decodeMock);
|
|
184
|
+
|
|
185
|
+
const request = new Request('http://localhost/products');
|
|
186
|
+
const [rootData, productData] = await Promise.all([
|
|
187
|
+
loadTanstackRscRouteData({
|
|
188
|
+
loadClientData: async () => ({ fallback: 'root' }),
|
|
189
|
+
request,
|
|
190
|
+
routeId: '__root__',
|
|
191
|
+
}),
|
|
192
|
+
loadTanstackRscRouteData({
|
|
193
|
+
loadClientData: async () => ({ fallback: 'product' }),
|
|
194
|
+
request,
|
|
195
|
+
routeId: '/products',
|
|
196
|
+
}),
|
|
197
|
+
]);
|
|
198
|
+
|
|
199
|
+
expect(rootData).toEqual({ shell: true });
|
|
200
|
+
expect(productData).toEqual({ product: 1 });
|
|
201
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
202
|
+
expect(fetchMock.mock.calls[0]?.[1]?.headers.get('x-rsc-tree')).toBe(
|
|
203
|
+
'true',
|
|
204
|
+
);
|
|
205
|
+
expect(decodeMock).toHaveBeenCalledTimes(1);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('uses client loader data without requesting an RSC payload for client-loader routes', async () => {
|
|
209
|
+
const fetchMock = rstest.fn();
|
|
210
|
+
const loadClientData = rstest.fn(async () => ({ client: true }));
|
|
211
|
+
rstest.stubGlobal('fetch', fetchMock);
|
|
212
|
+
|
|
213
|
+
await expect(
|
|
214
|
+
loadTanstackRscRouteData({
|
|
215
|
+
hasClientLoader: true,
|
|
216
|
+
loadClientData,
|
|
217
|
+
request: new Request('http://localhost/client'),
|
|
218
|
+
routeId: '/client',
|
|
219
|
+
}),
|
|
220
|
+
).resolves.toEqual({ client: true });
|
|
221
|
+
|
|
222
|
+
expect(loadClientData).toHaveBeenCalledTimes(1);
|
|
223
|
+
expect(fetchMock).not.toHaveBeenCalled();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('rethrows serialized notFound payload errors for the matched route', async () => {
|
|
227
|
+
const payload = {
|
|
228
|
+
type: 'render',
|
|
229
|
+
actionData: null,
|
|
230
|
+
errors: {
|
|
231
|
+
'/missing': {
|
|
232
|
+
isNotFound: true,
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
loaderData: {},
|
|
236
|
+
location: { href: '/missing' },
|
|
237
|
+
routes: [{ id: '/missing', hasLoader: true }],
|
|
238
|
+
};
|
|
239
|
+
rstest.stubGlobal(
|
|
240
|
+
'fetch',
|
|
241
|
+
rstest.fn(() => Promise.resolve(new Response('payload'))),
|
|
242
|
+
);
|
|
243
|
+
__setTanstackRscPayloadDecoderForTests(async () => payload);
|
|
244
|
+
|
|
245
|
+
await expect(
|
|
246
|
+
loadTanstackRscRouteData({
|
|
247
|
+
loadClientData: async () => ({ fallback: true }),
|
|
248
|
+
request: new Request('http://localhost/missing'),
|
|
249
|
+
routeId: '/missing',
|
|
250
|
+
}),
|
|
251
|
+
).rejects.toMatchObject({
|
|
252
|
+
isNotFound: true,
|
|
253
|
+
routeId: '/missing',
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { generateTanstackRouterTypesSourceForEntry } from '../../src/cli/tanstackTypes';
|
|
5
|
+
|
|
6
|
+
describe('tanstack router type generation', () => {
|
|
7
|
+
let tempDir: string | undefined;
|
|
8
|
+
|
|
9
|
+
afterEach(async () => {
|
|
10
|
+
if (tempDir) {
|
|
11
|
+
await rm(tempDir, { recursive: true, force: true });
|
|
12
|
+
tempDir = undefined;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('emits inline data actions into route static data', async () => {
|
|
17
|
+
tempDir = await mkdtemp(path.join(tmpdir(), 'modern-tanstack-types-'));
|
|
18
|
+
const srcDirectory = path.join(tempDir, 'src');
|
|
19
|
+
const routeDir = path.join(srcDirectory, 'routes', 'mf');
|
|
20
|
+
await mkdir(routeDir, { recursive: true });
|
|
21
|
+
await writeFile(
|
|
22
|
+
path.join(routeDir, 'page.data.ts'),
|
|
23
|
+
[
|
|
24
|
+
'export const loader = () => ({ count: 0 });',
|
|
25
|
+
'export const action = () => Response.json({ count: 1 });',
|
|
26
|
+
].join('\n'),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const { routerGenTs } = await generateTanstackRouterTypesSourceForEntry({
|
|
30
|
+
appContext: {
|
|
31
|
+
srcDirectory,
|
|
32
|
+
internalSrcAlias: '@/_',
|
|
33
|
+
} as any,
|
|
34
|
+
entryName: 'index',
|
|
35
|
+
routes: [
|
|
36
|
+
{
|
|
37
|
+
type: 'nested',
|
|
38
|
+
id: 'layout',
|
|
39
|
+
isRoot: true,
|
|
40
|
+
children: [
|
|
41
|
+
{
|
|
42
|
+
type: 'nested',
|
|
43
|
+
id: 'mf/page',
|
|
44
|
+
path: 'mf',
|
|
45
|
+
data: '@/_/routes/mf/page.data',
|
|
46
|
+
action: '@/_/routes/mf/page.data',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
] as any,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(routerGenTs).toContain(
|
|
54
|
+
'import { loader as loader_0, action as action_0 } from "../../routes/mf/page.data";',
|
|
55
|
+
);
|
|
56
|
+
expect(routerGenTs).toContain('modernRouteLoader: loader_0');
|
|
57
|
+
expect(routerGenTs).toContain('modernRouteAction: action_0');
|
|
58
|
+
expect(routerGenTs).toContain(
|
|
59
|
+
"} from '@modern-js/plugin-tanstack/runtime';",
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
});
|
package/tsconfig.json
ADDED