@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.5 → 3.2.0-ultramodern.51

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 (41) hide show
  1. package/dist/cjs/cli/index.js +3 -6
  2. package/dist/cjs/cli/tanstackTypes.js +20 -6
  3. package/dist/cjs/runtime/plugin.js +2 -0
  4. package/dist/cjs/runtime/plugin.node.js +17 -1
  5. package/dist/cjs/runtime/plugin.worker.js +49 -0
  6. package/dist/cjs/runtime/routeTree.js +38 -2
  7. package/dist/esm/cli/index.mjs +3 -6
  8. package/dist/esm/cli/tanstackTypes.mjs +20 -6
  9. package/dist/esm/runtime/plugin.mjs +2 -0
  10. package/dist/esm/runtime/plugin.node.mjs +17 -1
  11. package/dist/esm/runtime/plugin.worker.mjs +1 -0
  12. package/dist/esm/runtime/routeTree.mjs +38 -2
  13. package/dist/esm-node/cli/index.mjs +3 -6
  14. package/dist/esm-node/cli/tanstackTypes.mjs +20 -6
  15. package/dist/esm-node/runtime/plugin.mjs +2 -0
  16. package/dist/esm-node/runtime/plugin.node.mjs +17 -1
  17. package/dist/esm-node/runtime/plugin.worker.mjs +2 -0
  18. package/dist/esm-node/runtime/routeTree.mjs +38 -2
  19. package/dist/types/runtime/plugin.worker.d.ts +1 -0
  20. package/package.json +14 -14
  21. package/src/cli/index.ts +15 -18
  22. package/src/cli/tanstackTypes.ts +34 -9
  23. package/src/runtime/basepathRewrite.ts +1 -0
  24. package/src/runtime/dataMutation.tsx +1 -0
  25. package/src/runtime/lifecycle.ts +1 -0
  26. package/src/runtime/plugin.node.tsx +43 -1
  27. package/src/runtime/plugin.tsx +3 -0
  28. package/src/runtime/plugin.worker.tsx +4 -0
  29. package/src/runtime/routeTree.ts +102 -2
  30. package/src/runtime/rsc/ClientSlot.tsx +1 -0
  31. package/src/runtime/rsc/CompositeComponent.tsx +1 -0
  32. package/src/runtime/rsc/ReplayableStream.ts +1 -0
  33. package/src/runtime/rsc/RscNodeRenderer.tsx +1 -0
  34. package/src/runtime/rsc/client.tsx +2 -3
  35. package/src/runtime/rsc/createRscProxy.tsx +1 -0
  36. package/src/runtime/rsc/payloadRouter.ts +1 -0
  37. package/src/runtime/rsc/server.tsx +1 -0
  38. package/src/runtime/rsc/slotUsageSanitizer.ts +1 -0
  39. package/src/runtime/utils.tsx +1 -0
  40. package/tests/router/routeTree.test.ts +72 -1
  41. package/tests/router/tanstackTypes.test.ts +64 -0
@@ -1,7 +1,10 @@
1
1
  import type { RouteObject } from '@modern-js/runtime-utils/router';
2
2
  import type { NestedRoute } from '@modern-js/types';
3
3
  import { createMemoryHistory } from '@tanstack/history';
4
- import { createRouter } from '@tanstack/react-router';
4
+ import { createRouter, Outlet, RouterProvider } from '@tanstack/react-router';
5
+ import type { ComponentType } from 'react';
6
+ import { createElement, lazy } from 'react';
7
+ import { renderToStaticMarkup } from 'react-dom/server';
5
8
  import {
6
9
  createRouteTreeFromModernRoutes,
7
10
  createRouteTreeFromRouteObjects,
@@ -23,6 +26,7 @@ type TestRouteObject = RouteObject & {
23
26
  hasLoader?: boolean;
24
27
  inValidSSRRoute?: boolean;
25
28
  isClientComponent?: boolean;
29
+ lazyImport?: () => Promise<{ default: ComponentType }>;
26
30
  };
27
31
 
28
32
  type TestNestedRoute = NestedRoute & {
@@ -234,6 +238,73 @@ describe('tanstack route tree from RouteObject[]', () => {
234
238
  expect(splatParamValue).toBe('a/b/c');
235
239
  });
236
240
 
241
+ test('preloads lazy Modern route components for server rendering', async () => {
242
+ const LazyRouteComponent = () =>
243
+ createElement('main', null, 'Lazy route ready');
244
+ const lazyImport = rstest.fn(async () => ({
245
+ default: LazyRouteComponent,
246
+ }));
247
+ const routes: TestRouteObject[] = [
248
+ {
249
+ id: 'root',
250
+ path: '/',
251
+ Component: () => null,
252
+ children: [
253
+ {
254
+ id: 'lazy',
255
+ path: 'lazy',
256
+ Component: lazy(lazyImport),
257
+ lazyImport,
258
+ },
259
+ ],
260
+ },
261
+ ];
262
+
263
+ const routeTree = createRouteTreeFromRouteObjects(routes);
264
+ const router = await loadRouteTree(routeTree, '/lazy');
265
+ const lazyRoute = getLooseRoute(router, '/lazy');
266
+ const component = lazyRoute.options.component as ComponentType & {
267
+ preload?: () => Promise<unknown>;
268
+ };
269
+
270
+ await component.preload?.();
271
+
272
+ expect(renderToStaticMarkup(createElement(component))).toContain(
273
+ 'Lazy route ready',
274
+ );
275
+ expect(lazyImport).toHaveBeenCalled();
276
+ });
277
+
278
+ test('renders preloaded lazy child routes through TanStack router SSR', async () => {
279
+ const LazyRouteComponent = () =>
280
+ createElement('main', null, 'Lazy child route ready');
281
+ const lazyImport = rstest.fn(async () => ({
282
+ default: LazyRouteComponent,
283
+ }));
284
+ const routes: TestRouteObject[] = [
285
+ {
286
+ id: 'root',
287
+ path: '/',
288
+ Component: () => createElement('section', null, createElement(Outlet)),
289
+ children: [
290
+ {
291
+ id: 'lazy',
292
+ path: 'lazy',
293
+ Component: lazy(lazyImport),
294
+ lazyImport,
295
+ },
296
+ ],
297
+ },
298
+ ];
299
+
300
+ const routeTree = createRouteTreeFromRouteObjects(routes);
301
+ const router = await loadRouteTree(routeTree, '/lazy');
302
+
303
+ expect(
304
+ renderToStaticMarkup(createElement(RouterProvider, { router } as never)),
305
+ ).toContain('Lazy child route ready');
306
+ });
307
+
237
308
  test('preserves route handle and maps shouldRevalidate to shouldReload', async () => {
238
309
  const shouldRevalidate = rstest.fn(({ nextUrl }: ShouldRevalidateArgs) =>
239
310
  nextUrl.pathname.endsWith('/456'),
@@ -55,8 +55,72 @@ describe('tanstack router type generation', () => {
55
55
  );
56
56
  expect(routerGenTs).toContain('modernRouteLoader: loader_0');
57
57
  expect(routerGenTs).toContain('modernRouteAction: action_0');
58
+ expect(routerGenTs).toContain('modernRouteId?: string;');
59
+ expect(routerGenTs).not.toContain(
60
+ 'return Object.keys(staticData).length > 0 ? staticData : undefined;',
61
+ );
58
62
  expect(routerGenTs).toContain(
59
63
  "} from '@modern-js/plugin-tanstack/runtime';",
60
64
  );
61
65
  });
66
+
67
+ test('preserves typed child trees for localized nested route aliases', async () => {
68
+ tempDir = await mkdtemp(path.join(tmpdir(), 'modern-tanstack-types-'));
69
+ const srcDirectory = path.join(tempDir, 'src');
70
+
71
+ const { routerGenTs } = await generateTanstackRouterTypesSourceForEntry({
72
+ appContext: {
73
+ srcDirectory,
74
+ internalSrcAlias: '@/_',
75
+ } as any,
76
+ entryName: 'index',
77
+ routes: [
78
+ {
79
+ type: 'nested',
80
+ id: 'layout',
81
+ isRoot: true,
82
+ children: [
83
+ {
84
+ type: 'nested',
85
+ id: '(lang)/layout',
86
+ path: ':lang',
87
+ children: [
88
+ {
89
+ type: 'nested',
90
+ id: '(lang)/products/(slug)/page',
91
+ path: 'products/:slug',
92
+ },
93
+ {
94
+ type: 'nested',
95
+ id: '(lang)/products/(slug)/page__localised_produkty_slug',
96
+ path: 'produkty/:slug',
97
+ },
98
+ {
99
+ type: 'nested',
100
+ id: '(lang)/optional/(slug$)/page__localised_volitelne_slug',
101
+ path: 'volitelne/:slug?',
102
+ },
103
+ ],
104
+ },
105
+ ],
106
+ },
107
+ ] as any,
108
+ });
109
+
110
+ expect(routerGenTs).toContain(
111
+ 'const route__lang__layout__base = createRoute({',
112
+ );
113
+ expect(routerGenTs).toContain(
114
+ 'getParentRoute: () => route__lang__layout__base,',
115
+ );
116
+ expect(routerGenTs).toContain('path: "produkty/$slug",');
117
+ expect(routerGenTs).toContain('path: "volitelne/{-$slug}",');
118
+ expect(routerGenTs).toContain(
119
+ 'const route__lang__layout = route__lang__layout__base.addChildren([route__lang__products__slug__page, route__lang__products__slug__page__localised_produkty_slug, route__lang__optional__slug$__page__localised_volitelne_slug]);',
120
+ );
121
+ expect(routerGenTs).toContain(
122
+ 'export const routeTree = rootRoute.addChildren([route__lang__layout]);',
123
+ );
124
+ expect(routerGenTs).not.toContain('route__lang__layout.addChildren([');
125
+ });
62
126
  });