@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.1 → 3.2.0-ultramodern.100

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.
Files changed (73) hide show
  1. package/dist/cjs/cli/index.js +15 -6
  2. package/dist/cjs/cli/routeSplitting.js +83 -0
  3. package/dist/cjs/cli/tanstackTypes.js +146 -58
  4. package/dist/cjs/runtime/hydrationBoundary.js +44 -0
  5. package/dist/cjs/runtime/index.js +321 -69
  6. package/dist/cjs/runtime/outlet.js +54 -0
  7. package/dist/cjs/runtime/plugin.js +194 -90
  8. package/dist/cjs/runtime/plugin.node.js +29 -11
  9. package/dist/cjs/runtime/plugin.worker.js +49 -0
  10. package/dist/cjs/runtime/routeTree.js +72 -12
  11. package/dist/cjs/runtime/types.js +27 -1
  12. package/dist/esm/cli/index.mjs +7 -7
  13. package/dist/esm/cli/routeSplitting.mjs +43 -0
  14. package/dist/esm/cli/tanstackTypes.mjs +146 -58
  15. package/dist/esm/runtime/hydrationBoundary.mjs +10 -0
  16. package/dist/esm/runtime/index.mjs +3 -2
  17. package/dist/esm/runtime/outlet.mjs +17 -0
  18. package/dist/esm/runtime/plugin.mjs +197 -93
  19. package/dist/esm/runtime/plugin.node.mjs +30 -12
  20. package/dist/esm/runtime/plugin.worker.mjs +1 -0
  21. package/dist/esm/runtime/routeTree.mjs +73 -13
  22. package/dist/esm/runtime/types.mjs +7 -0
  23. package/dist/esm-node/cli/index.mjs +7 -7
  24. package/dist/esm-node/cli/routeSplitting.mjs +44 -0
  25. package/dist/esm-node/cli/tanstackTypes.mjs +146 -58
  26. package/dist/esm-node/runtime/hydrationBoundary.mjs +11 -0
  27. package/dist/esm-node/runtime/index.mjs +3 -2
  28. package/dist/esm-node/runtime/outlet.mjs +18 -0
  29. package/dist/esm-node/runtime/plugin.mjs +197 -93
  30. package/dist/esm-node/runtime/plugin.node.mjs +30 -12
  31. package/dist/esm-node/runtime/plugin.worker.mjs +2 -0
  32. package/dist/esm-node/runtime/routeTree.mjs +73 -13
  33. package/dist/esm-node/runtime/types.mjs +7 -0
  34. package/dist/types/cli/index.d.ts +4 -0
  35. package/dist/types/cli/routeSplitting.d.ts +29 -0
  36. package/dist/types/runtime/hydrationBoundary.d.ts +2 -0
  37. package/dist/types/runtime/index.d.ts +5 -2
  38. package/dist/types/runtime/outlet.d.ts +2 -0
  39. package/dist/types/runtime/plugin.d.ts +1 -1
  40. package/dist/types/runtime/plugin.node.d.ts +1 -1
  41. package/dist/types/runtime/plugin.worker.d.ts +1 -0
  42. package/dist/types/runtime/types.d.ts +7 -0
  43. package/package.json +14 -14
  44. package/src/cli/index.ts +32 -18
  45. package/src/cli/routeSplitting.ts +81 -0
  46. package/src/cli/tanstackTypes.ts +217 -67
  47. package/src/runtime/basepathRewrite.ts +1 -0
  48. package/src/runtime/dataMutation.tsx +1 -0
  49. package/src/runtime/hydrationBoundary.tsx +12 -0
  50. package/src/runtime/index.tsx +107 -2
  51. package/src/runtime/lifecycle.ts +1 -0
  52. package/src/runtime/outlet.tsx +42 -0
  53. package/src/runtime/plugin.node.tsx +58 -8
  54. package/src/runtime/plugin.tsx +354 -149
  55. package/src/runtime/plugin.worker.tsx +4 -0
  56. package/src/runtime/routeTree.ts +195 -23
  57. package/src/runtime/rsc/ClientSlot.tsx +1 -0
  58. package/src/runtime/rsc/CompositeComponent.tsx +1 -0
  59. package/src/runtime/rsc/ReplayableStream.ts +1 -0
  60. package/src/runtime/rsc/RscNodeRenderer.tsx +1 -0
  61. package/src/runtime/rsc/client.tsx +2 -3
  62. package/src/runtime/rsc/createRscProxy.tsx +1 -0
  63. package/src/runtime/rsc/payloadRouter.ts +1 -0
  64. package/src/runtime/rsc/server.tsx +1 -0
  65. package/src/runtime/rsc/slotUsageSanitizer.ts +1 -0
  66. package/src/runtime/ssr-shim.d.ts +1 -3
  67. package/src/runtime/types.ts +13 -0
  68. package/src/runtime/utils.tsx +1 -0
  69. package/tests/router/cli.test.ts +239 -0
  70. package/tests/router/fastDefaults.test.ts +25 -0
  71. package/tests/router/hydrationBoundary.test.tsx +23 -0
  72. package/tests/router/routeTree.test.ts +416 -1
  73. package/tests/router/tanstackTypes.test.ts +184 -0
@@ -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,
@@ -193,6 +196,12 @@ describe('tanstack router cli plugin', () => {
193
196
  },
194
197
  ]);
195
198
 
199
+ expect(taps.config()).toMatchObject({
200
+ output: {
201
+ splitRouteChunks: true,
202
+ },
203
+ });
204
+
196
205
  const specPath = path.join(distDirectory, NESTED_ROUTE_SPEC_FILE);
197
206
  await fs.outputJSON(specPath, {
198
207
  existing: [{ id: 'keep-me' }],
@@ -383,4 +392,234 @@ describe('tanstack router cli plugin', () => {
383
392
  }),
384
393
  );
385
394
  });
395
+
396
+ test('can opt out of Modern-owned route code splitting', async () => {
397
+ const taps: Record<string, any> = {};
398
+ const api = {
399
+ getAppContext: () => ({
400
+ srcDirectory: '/tmp/app/src',
401
+ serverRoutes: [],
402
+ }),
403
+ _internalRuntimePlugins: () => {},
404
+ checkEntryPoint: () => {},
405
+ config: (tap: any) => {
406
+ taps.config = tap;
407
+ },
408
+ modifyEntrypoints: () => {},
409
+ generateEntryCode: () => {},
410
+ onFileChanged: () => {},
411
+ modifyFileSystemRoutes: () => {},
412
+ onBeforeGenerateRoutes: () => {},
413
+ };
414
+
415
+ tanstackRouterPlugin({ routeCodeSplitting: false }).setup!(api as any);
416
+
417
+ expect(taps.config()).toMatchObject({
418
+ output: {
419
+ splitRouteChunks: false,
420
+ },
421
+ });
422
+ });
423
+
424
+ test('documents why TanStack Start Rspack splitter is not registered for Modern routes', () => {
425
+ const profile = createTanstackRsbuildRouteSplittingProfile({});
426
+
427
+ expect(profile).toMatchObject({
428
+ defaultConfig: {
429
+ output: {
430
+ splitRouteChunks: true,
431
+ },
432
+ },
433
+ modernRouteChunks: {
434
+ enabled: true,
435
+ owner: 'modern',
436
+ },
437
+ builderChunkSplit: {
438
+ owner: 'modern-rsbuild',
439
+ preserved: true,
440
+ },
441
+ tanstackStartRspackSplitter: {
442
+ compatible: false,
443
+ clientDeleteNodes: ['ssr', 'server', 'headers'],
444
+ },
445
+ });
446
+ expect(
447
+ isTanstackStartRouteModuleSource(
448
+ "export const Route = createFileRoute('/dashboard')({ component })",
449
+ ),
450
+ ).toBe(true);
451
+ expect(
452
+ isTanstackStartRouteModuleSource(
453
+ 'export const route = createRoute({ getParentRoute, path })',
454
+ ),
455
+ ).toBe(false);
456
+ });
457
+
458
+ test('preserves user-selected route and builder chunk splitting modes', () => {
459
+ const pluginDefaults = createTanstackRsbuildRouteSplittingProfile(
460
+ {},
461
+ ).defaultConfig;
462
+ const chunkSplits = [
463
+ { strategy: 'split-by-module' },
464
+ { strategy: 'split-by-experience' },
465
+ { strategy: 'all-in-one' },
466
+ { strategy: 'single-vendor' },
467
+ { strategy: 'split-by-size', minSize: 10_000, maxSize: 60_000 },
468
+ {
469
+ strategy: 'custom',
470
+ splitChunks: {
471
+ chunks: 'all',
472
+ cacheGroups: {
473
+ tractors: {
474
+ name: 'tractors',
475
+ test: /tractors/u,
476
+ },
477
+ },
478
+ },
479
+ },
480
+ ];
481
+
482
+ for (const chunkSplit of chunkSplits) {
483
+ expect(
484
+ mergeConfig([
485
+ pluginDefaults,
486
+ {
487
+ output: {
488
+ splitRouteChunks: false,
489
+ },
490
+ performance: {
491
+ chunkSplit,
492
+ },
493
+ splitChunks: false,
494
+ },
495
+ ]),
496
+ ).toMatchObject({
497
+ output: {
498
+ splitRouteChunks: false,
499
+ },
500
+ performance: {
501
+ chunkSplit,
502
+ },
503
+ splitChunks: false,
504
+ });
505
+ }
506
+
507
+ const pageSplitWithManualAsyncChunks = mergeConfig([
508
+ pluginDefaults,
509
+ {
510
+ performance: {
511
+ chunkSplit: {
512
+ strategy: 'custom',
513
+ splitChunks: {
514
+ chunks: 'async',
515
+ },
516
+ },
517
+ },
518
+ },
519
+ ]);
520
+
521
+ expect(pageSplitWithManualAsyncChunks).toMatchObject({
522
+ output: {
523
+ splitRouteChunks: true,
524
+ },
525
+ performance: {
526
+ chunkSplit: {
527
+ strategy: 'custom',
528
+ splitChunks: {
529
+ chunks: 'async',
530
+ },
531
+ },
532
+ },
533
+ });
534
+ });
535
+
536
+ test('keeps custom cache group details intact', () => {
537
+ const pluginDefaults = createTanstackRsbuildRouteSplittingProfile(
538
+ {},
539
+ ).defaultConfig;
540
+
541
+ const mergedConfig = mergeConfig([
542
+ pluginDefaults,
543
+ {
544
+ performance: {
545
+ chunkSplit: {
546
+ strategy: 'custom',
547
+ splitChunks: {
548
+ chunks: 'all',
549
+ cacheGroups: {
550
+ tractors: {
551
+ name: 'tractors',
552
+ test: /tractors/u,
553
+ },
554
+ },
555
+ },
556
+ },
557
+ },
558
+ },
559
+ ]);
560
+
561
+ expect(
562
+ (
563
+ mergedConfig as {
564
+ performance?: {
565
+ chunkSplit?: {
566
+ splitChunks?: {
567
+ cacheGroups?: {
568
+ tractors?: {
569
+ test?: RegExp;
570
+ };
571
+ };
572
+ };
573
+ };
574
+ };
575
+ }
576
+ ).performance?.chunkSplit?.splitChunks?.cacheGroups?.tractors?.test,
577
+ ).toEqual(/tractors/u);
578
+ expect(mergedConfig).toMatchObject({
579
+ output: {
580
+ splitRouteChunks: true,
581
+ },
582
+ performance: {
583
+ chunkSplit: {
584
+ strategy: 'custom',
585
+ splitChunks: {
586
+ chunks: 'all',
587
+ cacheGroups: {
588
+ tractors: {
589
+ name: 'tractors',
590
+ },
591
+ },
592
+ },
593
+ },
594
+ },
595
+ });
596
+ });
597
+
598
+ test('plugin opt-out can still combine with manual builder chunking', () => {
599
+ const pluginDefaults = createTanstackRsbuildRouteSplittingProfile({
600
+ routeCodeSplitting: false,
601
+ }).defaultConfig;
602
+
603
+ expect(
604
+ mergeConfig([
605
+ pluginDefaults,
606
+ {
607
+ performance: {
608
+ chunkSplit: {
609
+ strategy: 'single-vendor',
610
+ },
611
+ },
612
+ },
613
+ ]),
614
+ ).toMatchObject({
615
+ output: {
616
+ splitRouteChunks: false,
617
+ },
618
+ performance: {
619
+ chunkSplit: {
620
+ strategy: 'single-vendor',
621
+ },
622
+ },
623
+ });
624
+ });
386
625
  });
@@ -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
+ });