@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.12 → 3.2.0-ultramodern.120
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 +47 -9
- package/dist/cjs/cli/routeSplitting.js +87 -0
- package/dist/cjs/cli/tanstackTypes.js +230 -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 +28 -6
- package/dist/esm/cli/routeSplitting.mjs +43 -0
- package/dist/esm/cli/tanstackTypes.mjs +219 -59
- 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 +28 -6
- package/dist/esm-node/cli/routeSplitting.mjs +44 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +219 -59
- 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 +7 -1
- package/dist/types/cli/routeSplitting.d.ts +29 -0
- package/dist/types/cli/tanstackTypes.d.ts +9 -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 +20 -20
- package/src/cli/index.ts +59 -2
- package/src/cli/routeSplitting.ts +81 -0
- package/src/cli/tanstackTypes.ts +347 -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 +315 -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 +415 -1
package/tests/router/cli.test.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { mkdir, mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { mergeConfig } from '@modern-js/plugin/cli';
|
|
4
5
|
import type { Entrypoint } from '@modern-js/types';
|
|
5
6
|
import { fs, NESTED_ROUTE_SPEC_FILE } from '@modern-js/utils';
|
|
6
7
|
import {
|
|
8
|
+
createTanstackRsbuildRouteSplittingProfile,
|
|
9
|
+
isTanstackStartRouteModuleSource,
|
|
7
10
|
tanstackRouterPlugin,
|
|
8
11
|
writeTanstackRegisterFile,
|
|
9
12
|
writeTanstackRouterTypesForEntries,
|
|
@@ -120,6 +123,82 @@ describe('tanstack router cli plugin', () => {
|
|
|
120
123
|
);
|
|
121
124
|
});
|
|
122
125
|
|
|
126
|
+
test('writes plugin-i18n module augmentation when canonicalRoutes are provided', async () => {
|
|
127
|
+
tempDir = await mkdtemp(path.join(tmpdir(), 'modern-tanstack-cli-'));
|
|
128
|
+
const srcDirectory = path.join(tempDir, 'src');
|
|
129
|
+
|
|
130
|
+
await writeTanstackRegisterFile({
|
|
131
|
+
entries: ['main'],
|
|
132
|
+
generatedDirName: 'tanstack',
|
|
133
|
+
srcDirectory,
|
|
134
|
+
canonicalRoutes: {
|
|
135
|
+
'/': 'Record<string, never>',
|
|
136
|
+
'/products/$slug': '{ "slug": string }',
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const register = await readFile(
|
|
141
|
+
path.join(srcDirectory, 'tanstack', 'register.gen.d.ts'),
|
|
142
|
+
'utf-8',
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
expect(register).toContain(
|
|
146
|
+
"declare module '@modern-js/plugin-i18n/runtime'",
|
|
147
|
+
);
|
|
148
|
+
expect(register).toContain('interface UltramodernCanonicalRoutes');
|
|
149
|
+
expect(register).toContain("'/': Record<string, never>;");
|
|
150
|
+
expect(register).toContain('\'/products/$slug\': { "slug": string };');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('does not emit plugin-i18n augmentation when canonicalRoutes is absent (back-compat)', async () => {
|
|
154
|
+
tempDir = await mkdtemp(path.join(tmpdir(), 'modern-tanstack-cli-'));
|
|
155
|
+
const srcDirectory = path.join(tempDir, 'src');
|
|
156
|
+
|
|
157
|
+
await writeTanstackRegisterFile({
|
|
158
|
+
entries: ['main'],
|
|
159
|
+
generatedDirName: 'tanstack',
|
|
160
|
+
srcDirectory,
|
|
161
|
+
// No canonicalRoutes provided at all — plain TanStack app
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const register = await readFile(
|
|
165
|
+
path.join(srcDirectory, 'tanstack', 'register.gen.d.ts'),
|
|
166
|
+
'utf-8',
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
expect(register).not.toContain('plugin-i18n');
|
|
170
|
+
expect(register).not.toContain('UltramodernCanonicalRoutes');
|
|
171
|
+
// But the standard TanStack runtime augmentation must still be present.
|
|
172
|
+
expect(register).toContain(
|
|
173
|
+
"declare module '@modern-js/plugin-tanstack/runtime'",
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('uses a custom i18nRuntimeModule when specified', async () => {
|
|
178
|
+
tempDir = await mkdtemp(path.join(tmpdir(), 'modern-tanstack-cli-'));
|
|
179
|
+
const srcDirectory = path.join(tempDir, 'src');
|
|
180
|
+
|
|
181
|
+
await writeTanstackRegisterFile({
|
|
182
|
+
entries: ['main'],
|
|
183
|
+
generatedDirName: 'tanstack',
|
|
184
|
+
srcDirectory,
|
|
185
|
+
canonicalRoutes: {
|
|
186
|
+
'/talks': 'Record<string, never>',
|
|
187
|
+
},
|
|
188
|
+
i18nRuntimeModule: '@my-org/i18n/runtime',
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const register = await readFile(
|
|
192
|
+
path.join(srcDirectory, 'tanstack', 'register.gen.d.ts'),
|
|
193
|
+
'utf-8',
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
expect(register).toContain("declare module '@my-org/i18n/runtime'");
|
|
197
|
+
expect(register).not.toContain(
|
|
198
|
+
"declare module '@modern-js/plugin-i18n/runtime'",
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
|
|
123
202
|
test('claims custom routes, injects runtime plugin, and merges route specs', async () => {
|
|
124
203
|
tempDir = await mkdtemp(path.join(tmpdir(), 'modern-tanstack-cli-'));
|
|
125
204
|
const srcDirectory = path.join(tempDir, 'src');
|
|
@@ -193,6 +272,12 @@ describe('tanstack router cli plugin', () => {
|
|
|
193
272
|
},
|
|
194
273
|
]);
|
|
195
274
|
|
|
275
|
+
expect(taps.config()).toMatchObject({
|
|
276
|
+
output: {
|
|
277
|
+
splitRouteChunks: true,
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
|
|
196
281
|
const specPath = path.join(distDirectory, NESTED_ROUTE_SPEC_FILE);
|
|
197
282
|
await fs.outputJSON(specPath, {
|
|
198
283
|
existing: [{ id: 'keep-me' }],
|
|
@@ -383,4 +468,234 @@ describe('tanstack router cli plugin', () => {
|
|
|
383
468
|
}),
|
|
384
469
|
);
|
|
385
470
|
});
|
|
471
|
+
|
|
472
|
+
test('can opt out of Modern-owned route code splitting', async () => {
|
|
473
|
+
const taps: Record<string, any> = {};
|
|
474
|
+
const api = {
|
|
475
|
+
getAppContext: () => ({
|
|
476
|
+
srcDirectory: '/tmp/app/src',
|
|
477
|
+
serverRoutes: [],
|
|
478
|
+
}),
|
|
479
|
+
_internalRuntimePlugins: () => {},
|
|
480
|
+
checkEntryPoint: () => {},
|
|
481
|
+
config: (tap: any) => {
|
|
482
|
+
taps.config = tap;
|
|
483
|
+
},
|
|
484
|
+
modifyEntrypoints: () => {},
|
|
485
|
+
generateEntryCode: () => {},
|
|
486
|
+
onFileChanged: () => {},
|
|
487
|
+
modifyFileSystemRoutes: () => {},
|
|
488
|
+
onBeforeGenerateRoutes: () => {},
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
tanstackRouterPlugin({ routeCodeSplitting: false }).setup!(api as any);
|
|
492
|
+
|
|
493
|
+
expect(taps.config()).toMatchObject({
|
|
494
|
+
output: {
|
|
495
|
+
splitRouteChunks: false,
|
|
496
|
+
},
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
test('documents why TanStack Start Rspack splitter is not registered for Modern routes', () => {
|
|
501
|
+
const profile = createTanstackRsbuildRouteSplittingProfile({});
|
|
502
|
+
|
|
503
|
+
expect(profile).toMatchObject({
|
|
504
|
+
defaultConfig: {
|
|
505
|
+
output: {
|
|
506
|
+
splitRouteChunks: true,
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
modernRouteChunks: {
|
|
510
|
+
enabled: true,
|
|
511
|
+
owner: 'modern',
|
|
512
|
+
},
|
|
513
|
+
builderChunkSplit: {
|
|
514
|
+
owner: 'modern-rsbuild',
|
|
515
|
+
preserved: true,
|
|
516
|
+
},
|
|
517
|
+
tanstackStartRspackSplitter: {
|
|
518
|
+
compatible: false,
|
|
519
|
+
clientDeleteNodes: ['ssr', 'server', 'headers'],
|
|
520
|
+
},
|
|
521
|
+
});
|
|
522
|
+
expect(
|
|
523
|
+
isTanstackStartRouteModuleSource(
|
|
524
|
+
"export const Route = createFileRoute('/dashboard')({ component })",
|
|
525
|
+
),
|
|
526
|
+
).toBe(true);
|
|
527
|
+
expect(
|
|
528
|
+
isTanstackStartRouteModuleSource(
|
|
529
|
+
'export const route = createRoute({ getParentRoute, path })',
|
|
530
|
+
),
|
|
531
|
+
).toBe(false);
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
test('preserves user-selected route and builder chunk splitting modes', () => {
|
|
535
|
+
const pluginDefaults = createTanstackRsbuildRouteSplittingProfile(
|
|
536
|
+
{},
|
|
537
|
+
).defaultConfig;
|
|
538
|
+
const chunkSplits = [
|
|
539
|
+
{ strategy: 'split-by-module' },
|
|
540
|
+
{ strategy: 'split-by-experience' },
|
|
541
|
+
{ strategy: 'all-in-one' },
|
|
542
|
+
{ strategy: 'single-vendor' },
|
|
543
|
+
{ strategy: 'split-by-size', minSize: 10_000, maxSize: 60_000 },
|
|
544
|
+
{
|
|
545
|
+
strategy: 'custom',
|
|
546
|
+
splitChunks: {
|
|
547
|
+
chunks: 'all',
|
|
548
|
+
cacheGroups: {
|
|
549
|
+
tractors: {
|
|
550
|
+
name: 'tractors',
|
|
551
|
+
test: /tractors/u,
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
},
|
|
556
|
+
];
|
|
557
|
+
|
|
558
|
+
for (const chunkSplit of chunkSplits) {
|
|
559
|
+
expect(
|
|
560
|
+
mergeConfig([
|
|
561
|
+
pluginDefaults,
|
|
562
|
+
{
|
|
563
|
+
output: {
|
|
564
|
+
splitRouteChunks: false,
|
|
565
|
+
},
|
|
566
|
+
performance: {
|
|
567
|
+
chunkSplit,
|
|
568
|
+
},
|
|
569
|
+
splitChunks: false,
|
|
570
|
+
},
|
|
571
|
+
]),
|
|
572
|
+
).toMatchObject({
|
|
573
|
+
output: {
|
|
574
|
+
splitRouteChunks: false,
|
|
575
|
+
},
|
|
576
|
+
performance: {
|
|
577
|
+
chunkSplit,
|
|
578
|
+
},
|
|
579
|
+
splitChunks: false,
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
const pageSplitWithManualAsyncChunks = mergeConfig([
|
|
584
|
+
pluginDefaults,
|
|
585
|
+
{
|
|
586
|
+
performance: {
|
|
587
|
+
chunkSplit: {
|
|
588
|
+
strategy: 'custom',
|
|
589
|
+
splitChunks: {
|
|
590
|
+
chunks: 'async',
|
|
591
|
+
},
|
|
592
|
+
},
|
|
593
|
+
},
|
|
594
|
+
},
|
|
595
|
+
]);
|
|
596
|
+
|
|
597
|
+
expect(pageSplitWithManualAsyncChunks).toMatchObject({
|
|
598
|
+
output: {
|
|
599
|
+
splitRouteChunks: true,
|
|
600
|
+
},
|
|
601
|
+
performance: {
|
|
602
|
+
chunkSplit: {
|
|
603
|
+
strategy: 'custom',
|
|
604
|
+
splitChunks: {
|
|
605
|
+
chunks: 'async',
|
|
606
|
+
},
|
|
607
|
+
},
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
test('keeps custom cache group details intact', () => {
|
|
613
|
+
const pluginDefaults = createTanstackRsbuildRouteSplittingProfile(
|
|
614
|
+
{},
|
|
615
|
+
).defaultConfig;
|
|
616
|
+
|
|
617
|
+
const mergedConfig = mergeConfig([
|
|
618
|
+
pluginDefaults,
|
|
619
|
+
{
|
|
620
|
+
performance: {
|
|
621
|
+
chunkSplit: {
|
|
622
|
+
strategy: 'custom',
|
|
623
|
+
splitChunks: {
|
|
624
|
+
chunks: 'all',
|
|
625
|
+
cacheGroups: {
|
|
626
|
+
tractors: {
|
|
627
|
+
name: 'tractors',
|
|
628
|
+
test: /tractors/u,
|
|
629
|
+
},
|
|
630
|
+
},
|
|
631
|
+
},
|
|
632
|
+
},
|
|
633
|
+
},
|
|
634
|
+
},
|
|
635
|
+
]);
|
|
636
|
+
|
|
637
|
+
expect(
|
|
638
|
+
(
|
|
639
|
+
mergedConfig as {
|
|
640
|
+
performance?: {
|
|
641
|
+
chunkSplit?: {
|
|
642
|
+
splitChunks?: {
|
|
643
|
+
cacheGroups?: {
|
|
644
|
+
tractors?: {
|
|
645
|
+
test?: RegExp;
|
|
646
|
+
};
|
|
647
|
+
};
|
|
648
|
+
};
|
|
649
|
+
};
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
).performance?.chunkSplit?.splitChunks?.cacheGroups?.tractors?.test,
|
|
653
|
+
).toEqual(/tractors/u);
|
|
654
|
+
expect(mergedConfig).toMatchObject({
|
|
655
|
+
output: {
|
|
656
|
+
splitRouteChunks: true,
|
|
657
|
+
},
|
|
658
|
+
performance: {
|
|
659
|
+
chunkSplit: {
|
|
660
|
+
strategy: 'custom',
|
|
661
|
+
splitChunks: {
|
|
662
|
+
chunks: 'all',
|
|
663
|
+
cacheGroups: {
|
|
664
|
+
tractors: {
|
|
665
|
+
name: 'tractors',
|
|
666
|
+
},
|
|
667
|
+
},
|
|
668
|
+
},
|
|
669
|
+
},
|
|
670
|
+
},
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
test('plugin opt-out can still combine with manual builder chunking', () => {
|
|
675
|
+
const pluginDefaults = createTanstackRsbuildRouteSplittingProfile({
|
|
676
|
+
routeCodeSplitting: false,
|
|
677
|
+
}).defaultConfig;
|
|
678
|
+
|
|
679
|
+
expect(
|
|
680
|
+
mergeConfig([
|
|
681
|
+
pluginDefaults,
|
|
682
|
+
{
|
|
683
|
+
performance: {
|
|
684
|
+
chunkSplit: {
|
|
685
|
+
strategy: 'single-vendor',
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
},
|
|
689
|
+
]),
|
|
690
|
+
).toMatchObject({
|
|
691
|
+
output: {
|
|
692
|
+
splitRouteChunks: false,
|
|
693
|
+
},
|
|
694
|
+
performance: {
|
|
695
|
+
chunkSplit: {
|
|
696
|
+
strategy: 'single-vendor',
|
|
697
|
+
},
|
|
698
|
+
},
|
|
699
|
+
});
|
|
700
|
+
});
|
|
386
701
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getModernTanstackRouterFastDefaults,
|
|
3
|
+
modernTanstackRouterFastDefaults,
|
|
4
|
+
} from '../../src/runtime/types';
|
|
5
|
+
|
|
6
|
+
describe('tanstack router fast defaults', () => {
|
|
7
|
+
test('enables structural sharing by default', () => {
|
|
8
|
+
expect(modernTanstackRouterFastDefaults).toEqual({
|
|
9
|
+
defaultStructuralSharing: true,
|
|
10
|
+
});
|
|
11
|
+
expect(getModernTanstackRouterFastDefaults()).toEqual({
|
|
12
|
+
defaultStructuralSharing: true,
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('allows explicit structural sharing override', () => {
|
|
17
|
+
expect(
|
|
18
|
+
getModernTanstackRouterFastDefaults({
|
|
19
|
+
defaultStructuralSharing: false,
|
|
20
|
+
}),
|
|
21
|
+
).toEqual({
|
|
22
|
+
defaultStructuralSharing: false,
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isValidElement, Suspense } from 'react';
|
|
2
|
+
import { wrapTanstackSsrHydrationBoundary } from '../../src/runtime/hydrationBoundary';
|
|
3
|
+
|
|
4
|
+
describe('tanstack SSR hydration boundary', () => {
|
|
5
|
+
it('wraps SSR hydration content in a Suspense boundary', () => {
|
|
6
|
+
const routerContent = <main data-testid="router" />;
|
|
7
|
+
|
|
8
|
+
const wrapped = wrapTanstackSsrHydrationBoundary(routerContent, true);
|
|
9
|
+
|
|
10
|
+
expect(isValidElement(wrapped)).toBe(true);
|
|
11
|
+
expect(wrapped.type).toBe(Suspense);
|
|
12
|
+
expect(wrapped.props.fallback).toBe(null);
|
|
13
|
+
expect(wrapped.props.children).toBe(routerContent);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('keeps non-SSR router content unwrapped', () => {
|
|
17
|
+
const routerContent = <main data-testid="router" />;
|
|
18
|
+
|
|
19
|
+
expect(wrapTanstackSsrHydrationBoundary(routerContent, false)).toBe(
|
|
20
|
+
routerContent,
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { render } from '@testing-library/react';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { Link } from '../../src/runtime/prefetchLink';
|
|
3
|
+
import { Link, NavLink } from '../../src/runtime/prefetchLink';
|
|
4
4
|
|
|
5
5
|
type MockLinkProps = {
|
|
6
6
|
children?: React.ReactNode;
|
|
@@ -21,23 +21,59 @@ describe('tanstack prefetch link adapter', () => {
|
|
|
21
21
|
capturedPreloads = [];
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it('
|
|
24
|
+
it('defaults TanStack preload to viewport', () => {
|
|
25
|
+
render(<Link to="/settings">Settings</Link>);
|
|
26
|
+
|
|
27
|
+
expect(capturedPreloads).toEqual(['viewport']);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('preserves explicit preload', () => {
|
|
25
31
|
render(
|
|
26
|
-
<Link to="/settings" prefetch="
|
|
32
|
+
<Link to="/settings" prefetch="render" preload="intent">
|
|
27
33
|
Settings
|
|
28
34
|
</Link>,
|
|
29
35
|
);
|
|
30
36
|
|
|
31
|
-
expect(capturedPreloads).toEqual(['
|
|
37
|
+
expect(capturedPreloads).toEqual(['intent']);
|
|
32
38
|
});
|
|
33
39
|
|
|
34
|
-
it('
|
|
40
|
+
it('preserves explicit disabled preload', () => {
|
|
35
41
|
render(
|
|
36
|
-
<Link to="/settings" prefetch="
|
|
42
|
+
<Link to="/settings" prefetch="render" preload={false}>
|
|
37
43
|
Settings
|
|
38
44
|
</Link>,
|
|
39
45
|
);
|
|
40
46
|
|
|
41
|
-
expect(capturedPreloads).toEqual([
|
|
47
|
+
expect(capturedPreloads).toEqual([false]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('maps none prefetch to disabled TanStack preload', () => {
|
|
51
|
+
render(
|
|
52
|
+
<Link to="/settings" prefetch="none">
|
|
53
|
+
Settings
|
|
54
|
+
</Link>,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
expect(capturedPreloads).toEqual([false]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it.each([
|
|
61
|
+
'intent',
|
|
62
|
+
'render',
|
|
63
|
+
'viewport',
|
|
64
|
+
] as const)('maps %s prefetch to TanStack preload', prefetch => {
|
|
65
|
+
render(
|
|
66
|
+
<Link to="/settings" prefetch={prefetch}>
|
|
67
|
+
Settings
|
|
68
|
+
</Link>,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(capturedPreloads).toEqual([prefetch]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('defaults NavLink preload to viewport', () => {
|
|
75
|
+
render(<NavLink to="/settings">Settings</NavLink>);
|
|
76
|
+
|
|
77
|
+
expect(capturedPreloads).toEqual(['viewport']);
|
|
42
78
|
});
|
|
43
79
|
});
|