@bleedingdev/modern-js-plugin-tanstack 3.8.3-ultramodern.6 → 3.9.0-ultramodern.10

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 (114) hide show
  1. package/dist/cjs/cli/index.js +9 -0
  2. package/dist/cjs/cli/tanstackTypes/source.js +3 -1
  3. package/dist/cjs/runtime/basepathRewrite.js +13 -6
  4. package/dist/cjs/runtime/lifecycle.js +7 -7
  5. package/dist/cjs/runtime/plugin.js +1 -1
  6. package/dist/cjs/runtime/plugin.node.js +5 -1
  7. package/dist/cjs/runtime/prefetchLink.js +2 -7
  8. package/dist/cjs/runtime/register.js +0 -2
  9. package/dist/cjs/runtime/routeTree/construction.js +2 -0
  10. package/dist/cjs/runtime/router.js +25 -9
  11. package/dist/cjs/runtime/state.js +2 -2
  12. package/dist/cjs/runtime/utils.js +2 -0
  13. package/dist/esm/cli/index.mjs +13 -5
  14. package/dist/esm/cli/tanstackTypes/source.mjs +3 -1
  15. package/dist/esm/runtime/basepathRewrite.mjs +10 -3
  16. package/dist/esm/runtime/lifecycle.mjs +1 -1
  17. package/dist/esm/runtime/plugin.mjs +1 -1
  18. package/dist/esm/runtime/plugin.node.mjs +5 -1
  19. package/dist/esm/runtime/prefetchLink.mjs +1 -6
  20. package/dist/esm/runtime/register.mjs +0 -2
  21. package/dist/esm/runtime/routeTree/construction.mjs +2 -0
  22. package/dist/esm/runtime/router.mjs +27 -11
  23. package/dist/esm/runtime/state.mjs +1 -1
  24. package/dist/esm/runtime/utils.mjs +2 -0
  25. package/dist/esm-node/cli/index.mjs +15 -5
  26. package/dist/esm-node/cli/tanstackTypes/source.mjs +3 -1
  27. package/dist/esm-node/runtime/basepathRewrite.mjs +10 -3
  28. package/dist/esm-node/runtime/lifecycle.mjs +1 -1
  29. package/dist/esm-node/runtime/plugin.mjs +1 -1
  30. package/dist/esm-node/runtime/plugin.node.mjs +5 -1
  31. package/dist/esm-node/runtime/prefetchLink.mjs +1 -6
  32. package/dist/esm-node/runtime/register.mjs +0 -2
  33. package/dist/esm-node/runtime/routeTree/construction.mjs +2 -0
  34. package/dist/esm-node/runtime/router.mjs +27 -11
  35. package/dist/esm-node/runtime/state.mjs +1 -1
  36. package/dist/esm-node/runtime/utils.mjs +2 -0
  37. package/dist/types/cli/index.d.ts +5 -5
  38. package/dist/types/cli/tanstackTypes/shared.d.ts +1 -1
  39. package/dist/types/cli/tanstackTypes.d.ts +3 -3
  40. package/dist/types/cli.d.ts +2 -2
  41. package/dist/types/runtime/basepathRewrite.d.ts +2 -1
  42. package/dist/types/runtime/dataMutation.d.ts +3 -3
  43. package/dist/types/runtime/index.d.ts +14 -14
  44. package/dist/types/runtime/lifecycle.d.ts +9 -2
  45. package/dist/types/runtime/loaderBridge.d.ts +2 -2
  46. package/dist/types/runtime/plugin.d.ts +2 -2
  47. package/dist/types/runtime/plugin.node.d.ts +2 -2
  48. package/dist/types/runtime/plugin.worker.d.ts +1 -1
  49. package/dist/types/runtime/pluginShared.d.ts +2 -2
  50. package/dist/types/runtime/register.d.ts +1 -9
  51. package/dist/types/runtime/routeTree/construction.d.ts +1 -1
  52. package/dist/types/runtime/routeTree/index.d.ts +2 -2
  53. package/dist/types/runtime/routeTree/loaders.d.ts +1 -1
  54. package/dist/types/runtime/routeTree/tanstackRoutes.d.ts +1 -1
  55. package/dist/types/runtime/router.d.ts +2 -13
  56. package/dist/types/runtime/rsc/CompositeComponent.d.ts +1 -1
  57. package/dist/types/runtime/rsc/RscNodeRenderer.d.ts +1 -1
  58. package/dist/types/runtime/rsc/client.d.ts +4 -4
  59. package/dist/types/runtime/rsc/createRscProxy.d.ts +1 -1
  60. package/dist/types/runtime/rsc/payloadFetch.d.ts +1 -1
  61. package/dist/types/runtime/rsc/payloadRouter.d.ts +2 -2
  62. package/dist/types/runtime/rsc/payloadStorage.d.ts +1 -1
  63. package/dist/types/runtime/rsc/server.d.ts +3 -3
  64. package/dist/types/runtime/rsc/shared.d.ts +1 -1
  65. package/dist/types/runtime/rsc/slotUsageSanitizer.d.ts +1 -1
  66. package/dist/types/runtime/ssrManagedTags.d.ts +1 -1
  67. package/dist/types/runtime/ssrPreload.d.ts +1 -1
  68. package/dist/types/runtime/state.d.ts +1 -1
  69. package/dist/types/runtime/submitAction.d.ts +1 -1
  70. package/dist/types/runtime/types.d.ts +2 -1
  71. package/dist/types/runtime/utils.d.ts +1 -1
  72. package/dist/types/runtime.d.ts +1 -1
  73. package/package.json +19 -16
  74. package/rstest.config.mts +1 -24
  75. package/src/cli/index.ts +10 -0
  76. package/src/cli/tanstackTypes/source.ts +3 -1
  77. package/src/runtime/basepathRewrite.ts +11 -2
  78. package/src/runtime/lifecycle.ts +14 -3
  79. package/src/runtime/plugin.node.tsx +9 -2
  80. package/src/runtime/plugin.tsx +5 -1
  81. package/src/runtime/prefetchLink.tsx +1 -23
  82. package/src/runtime/register.ts +1 -12
  83. package/src/runtime/routeTree/construction.ts +2 -0
  84. package/src/runtime/router.ts +25 -40
  85. package/src/runtime/state.ts +1 -1
  86. package/src/runtime/types.ts +2 -2
  87. package/src/runtime/utils.tsx +3 -1
  88. package/tests/router/cli.test.ts +148 -824
  89. package/tests/router/dataMutation.test.tsx +17 -85
  90. package/tests/router/flightSerialization.roundtrip.test.tsx +9 -6
  91. package/tests/router/generateRouteArtifacts.test.ts +68 -28
  92. package/tests/router/loaderBridge.test.ts +0 -25
  93. package/tests/router/localisedIdentity.test.tsx +95 -0
  94. package/tests/router/prefetchLink.test.tsx +17 -21
  95. package/tests/router/prefetchLinkPreload.test.tsx +11 -31
  96. package/tests/router/routeHooks.test.ts +41 -105
  97. package/tests/router/routeTree.test.ts +144 -836
  98. package/tests/router/rsc.test.tsx +131 -166
  99. package/tests/router/serverPlugin.test.ts +43 -1
  100. package/tests/router/tanstackTypes.test.ts +109 -973
  101. package/tests/realm-isolation.test.ts +0 -114
  102. package/tests/router/fastDefaults.test.ts +0 -32
  103. package/tests/router/fixtures/legacyRuntimeRouter.ts +0 -10
  104. package/tests/router/fixtures/rscDecoderSecurityChild.cjs +0 -162
  105. package/tests/router/hooks.test.ts +0 -40
  106. package/tests/router/hydrationBoundary.test.tsx +0 -23
  107. package/tests/router/packageSurface.test.ts +0 -24
  108. package/tests/router/preloadRedirect.test.ts +0 -64
  109. package/tests/router/register.test.ts +0 -8
  110. package/tests/router/routerCompatibility.test.ts +0 -239
  111. package/tests/router/rscDecoderSecurity.test.ts +0 -113
  112. package/tests/router/rscPayloadRouterMatrix.test.ts +0 -197
  113. /package/dist/esm/{rslib-runtime.mjs → rslib-runtime~1.mjs} +0 -0
  114. /package/dist/esm-node/{rslib-runtime.mjs → rslib-runtime~0.mjs} +0 -0
@@ -1,113 +1,49 @@
1
- const calls: Record<string, unknown[]> = {
2
- useChildMatches: [],
3
- useMatch: [],
4
- useMatches: [],
5
- useParentMatches: [],
6
- useRouterState: [],
7
- };
8
-
9
- rstest.mock('@tanstack/react-router', () => ({
10
- useChildMatches: (options: unknown) => {
11
- calls.useChildMatches.push(options);
12
- return options;
13
- },
14
- useMatch: (options: unknown) => {
15
- calls.useMatch.push(options);
16
- return options;
17
- },
18
- useMatches: (options: unknown) => {
19
- calls.useMatches.push(options);
20
- return options;
21
- },
22
- useParentMatches: (options: unknown) => {
23
- calls.useParentMatches.push(options);
24
- return options;
25
- },
26
- useRouterState: (options: unknown) => {
27
- calls.useRouterState.push(options);
28
- return options;
29
- },
30
- }));
31
-
1
+ import { createMemoryHistory } from '@tanstack/history';
32
2
  import {
33
- useChildMatches,
34
- useMatch,
35
- useMatches,
36
- useParentMatches,
37
- useRouterState,
38
- } from '../../src/runtime/routeHooks';
39
-
40
- const getLastCall = (hookName: keyof typeof calls) => {
41
- const callList = calls[hookName];
42
- return callList[callList.length - 1];
43
- };
44
-
45
- describe('tanstack route hook structural sharing guards', () => {
46
- beforeEach(() => {
47
- for (const hookName of Object.keys(calls)) {
48
- calls[hookName] = [];
49
- }
3
+ createRootRoute,
4
+ createRoute,
5
+ createRouter,
6
+ RouterProvider,
7
+ } from '@tanstack/react-router';
8
+ import React from 'react';
9
+ import { renderToString } from 'react-dom/server';
10
+ import { useMatches } from '../../src/runtime/routeHooks';
11
+
12
+ function MatchIds() {
13
+ const matches = useMatches();
14
+ return React.createElement(
15
+ 'output',
16
+ { 'data-testid': 'route-ids' },
17
+ matches.map(match => match.routeId).join(','),
18
+ );
19
+ }
20
+
21
+ test('updates whole match objects after navigation with the structural-sharing guard', async () => {
22
+ const rootRoute = createRootRoute({ component: MatchIds });
23
+ const homeRoute = createRoute({
24
+ getParentRoute: () => rootRoute,
25
+ path: '/',
26
+ component: () => null,
50
27
  });
51
-
52
- test('disables structural sharing for full internal router objects', () => {
53
- useMatch({ from: '/' } as never);
54
- useMatches();
55
- useParentMatches();
56
- useChildMatches();
57
- useRouterState();
58
-
59
- expect(getLastCall('useMatch')).toEqual({
60
- from: '/',
61
- structuralSharing: false,
62
- });
63
- expect(getLastCall('useMatches')).toEqual({
64
- structuralSharing: false,
65
- });
66
- expect(getLastCall('useParentMatches')).toEqual({
67
- structuralSharing: false,
68
- });
69
- expect(getLastCall('useChildMatches')).toEqual({
70
- structuralSharing: false,
71
- });
72
- expect(getLastCall('useRouterState')).toEqual({
73
- structuralSharing: false,
74
- });
28
+ const settingsRoute = createRoute({
29
+ getParentRoute: () => rootRoute,
30
+ path: '/settings',
31
+ component: () => null,
75
32
  });
76
-
77
- test('keeps selected data on the router default', () => {
78
- const select = (value: unknown) => value;
79
- const matchOptions = { from: '/', select };
80
- const matchesOptions = { select };
81
- const stateOptions = { select };
82
-
83
- useMatch(matchOptions as never);
84
- useMatches(matchesOptions as never);
85
- useParentMatches(matchesOptions as never);
86
- useChildMatches(matchesOptions as never);
87
- useRouterState(stateOptions as never);
88
-
89
- expect(getLastCall('useMatch')).toBe(matchOptions);
90
- expect(getLastCall('useMatches')).toBe(matchesOptions);
91
- expect(getLastCall('useParentMatches')).toBe(matchesOptions);
92
- expect(getLastCall('useChildMatches')).toBe(matchesOptions);
93
- expect(getLastCall('useRouterState')).toBe(stateOptions);
33
+ const router = createRouter({
34
+ routeTree: rootRoute.addChildren([homeRoute, settingsRoute]),
35
+ history: createMemoryHistory({ initialEntries: ['/'] }),
36
+ defaultStructuralSharing: true,
94
37
  });
95
38
 
96
- test('honors explicit structural sharing choices', () => {
97
- const enabled = { structuralSharing: true };
98
- const disabled = { structuralSharing: false };
99
- const matchEnabled = { from: '/', structuralSharing: true };
39
+ await router.load();
40
+ expect(
41
+ renderToString(React.createElement(RouterProvider, { router })),
42
+ ).toContain('__root__');
100
43
 
101
- useMatch(matchEnabled as never);
102
- useMatches(enabled as never);
103
- useParentMatches(disabled as never);
104
- useChildMatches(enabled as never);
105
- useRouterState(disabled as never);
44
+ await router.navigate({ to: '/settings' });
106
45
 
107
- expect(getLastCall('useMatch')).toBe(matchEnabled);
108
- expect(getLastCall('useMatches')).toBe(enabled);
109
- expect(getLastCall('useParentMatches')).toBe(disabled);
110
- expect(getLastCall('useChildMatches')).toBe(enabled);
111
- expect(getLastCall('useRouterState')).toBe(disabled);
112
- });
46
+ expect(
47
+ renderToString(React.createElement(RouterProvider, { router })),
48
+ ).toContain('/settings');
113
49
  });