@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.
- package/dist/cjs/cli/index.js +15 -6
- package/dist/cjs/cli/routeSplitting.js +83 -0
- package/dist/cjs/cli/tanstackTypes.js +146 -58
- package/dist/cjs/runtime/hydrationBoundary.js +44 -0
- package/dist/cjs/runtime/index.js +321 -69
- package/dist/cjs/runtime/outlet.js +54 -0
- package/dist/cjs/runtime/plugin.js +194 -90
- package/dist/cjs/runtime/plugin.node.js +29 -11
- package/dist/cjs/runtime/plugin.worker.js +49 -0
- package/dist/cjs/runtime/routeTree.js +72 -12
- package/dist/cjs/runtime/types.js +27 -1
- package/dist/esm/cli/index.mjs +7 -7
- package/dist/esm/cli/routeSplitting.mjs +43 -0
- package/dist/esm/cli/tanstackTypes.mjs +146 -58
- 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 -93
- package/dist/esm/runtime/plugin.node.mjs +30 -12
- package/dist/esm/runtime/plugin.worker.mjs +1 -0
- package/dist/esm/runtime/routeTree.mjs +73 -13
- package/dist/esm/runtime/types.mjs +7 -0
- package/dist/esm-node/cli/index.mjs +7 -7
- package/dist/esm-node/cli/routeSplitting.mjs +44 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +146 -58
- 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 -93
- 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/routeTree.mjs +73 -13
- package/dist/esm-node/runtime/types.mjs +7 -0
- package/dist/types/cli/index.d.ts +4 -0
- package/dist/types/cli/routeSplitting.d.ts +29 -0
- 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 +14 -14
- package/src/cli/index.ts +32 -18
- package/src/cli/routeSplitting.ts +81 -0
- package/src/cli/tanstackTypes.ts +217 -67
- package/src/runtime/basepathRewrite.ts +1 -0
- package/src/runtime/dataMutation.tsx +1 -0
- package/src/runtime/hydrationBoundary.tsx +12 -0
- package/src/runtime/index.tsx +107 -2
- package/src/runtime/lifecycle.ts +1 -0
- package/src/runtime/outlet.tsx +42 -0
- package/src/runtime/plugin.node.tsx +58 -8
- package/src/runtime/plugin.tsx +354 -149
- package/src/runtime/plugin.worker.tsx +4 -0
- package/src/runtime/routeTree.ts +195 -23
- package/src/runtime/rsc/ClientSlot.tsx +1 -0
- package/src/runtime/rsc/CompositeComponent.tsx +1 -0
- package/src/runtime/rsc/ReplayableStream.ts +1 -0
- package/src/runtime/rsc/RscNodeRenderer.tsx +1 -0
- package/src/runtime/rsc/client.tsx +2 -3
- package/src/runtime/rsc/createRscProxy.tsx +1 -0
- package/src/runtime/rsc/payloadRouter.ts +1 -0
- package/src/runtime/rsc/server.tsx +1 -0
- package/src/runtime/rsc/slotUsageSanitizer.ts +1 -0
- package/src/runtime/ssr-shim.d.ts +1 -3
- package/src/runtime/types.ts +13 -0
- package/src/runtime/utils.tsx +1 -0
- package/tests/router/cli.test.ts +239 -0
- package/tests/router/fastDefaults.test.ts +25 -0
- package/tests/router/hydrationBoundary.test.tsx +23 -0
- package/tests/router/routeTree.test.ts +416 -1
- package/tests/router/tanstackTypes.test.ts +184 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @effect-diagnostics asyncFunction:off newPromise:off strictBooleanExpressions:off unnecessaryArrowBlock:off
|
|
1
2
|
/// <reference path="./ssr-shim.d.ts" />
|
|
2
3
|
|
|
3
4
|
import type { Plugin, RuntimePluginExtends } from '@modern-js/plugin';
|
|
@@ -25,9 +26,9 @@ import {
|
|
|
25
26
|
createRouter,
|
|
26
27
|
RouterProvider,
|
|
27
28
|
} from '@tanstack/react-router';
|
|
28
|
-
import { attachRouterServerSsrUtils } from '@tanstack/
|
|
29
|
+
import { attachRouterServerSsrUtils } from '@tanstack/router-core/ssr/server';
|
|
29
30
|
import type React from 'react';
|
|
30
|
-
import {
|
|
31
|
+
import { useContext } from 'react';
|
|
31
32
|
import { createModernBasepathRewrite } from './basepathRewrite';
|
|
32
33
|
import {
|
|
33
34
|
modifyRoutes as modifyRoutesHook,
|
|
@@ -38,6 +39,7 @@ import {
|
|
|
38
39
|
onBeforeHydrateRouter as onBeforeHydrateRouterHook,
|
|
39
40
|
type RouterExtendsHooks,
|
|
40
41
|
} from './hooks';
|
|
42
|
+
import { wrapTanstackSsrHydrationBoundary } from './hydrationBoundary';
|
|
41
43
|
import {
|
|
42
44
|
applyRouterServerPrepareResult,
|
|
43
45
|
createRouterServerSnapshot,
|
|
@@ -51,7 +53,11 @@ import {
|
|
|
51
53
|
createTanstackRscServerPayload,
|
|
52
54
|
handleTanstackRscRedirect,
|
|
53
55
|
} from './rsc/payloadRouter';
|
|
54
|
-
import
|
|
56
|
+
import {
|
|
57
|
+
getModernTanstackRouterFastDefaults,
|
|
58
|
+
type InternalRouterServerSnapshot,
|
|
59
|
+
type RouterConfig,
|
|
60
|
+
} from './types';
|
|
55
61
|
import { createRouteObjectsFromConfig, urlJoin } from './utils';
|
|
56
62
|
|
|
57
63
|
type ModernTanstackRouterContext = {
|
|
@@ -118,6 +124,17 @@ type PreloadableRouteComponent = {
|
|
|
118
124
|
preload?: (props?: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
119
125
|
};
|
|
120
126
|
|
|
127
|
+
type ReactLazyRouteComponent = {
|
|
128
|
+
_init?: (payload: unknown) => unknown;
|
|
129
|
+
_payload?: unknown;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
function isPromiseLike(value: unknown): value is PromiseLike<unknown> {
|
|
133
|
+
return Boolean(
|
|
134
|
+
value && typeof (value as PromiseLike<unknown>).then === 'function',
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
121
138
|
type TanstackRouterWithServerSsr = AnyRouter & {
|
|
122
139
|
resolveRedirect?: (redirect: Response) => Response;
|
|
123
140
|
routesById?: Record<string, RouterRouteWithOptions>;
|
|
@@ -148,7 +165,37 @@ function isPreloadableRouteComponent(
|
|
|
148
165
|
);
|
|
149
166
|
}
|
|
150
167
|
|
|
168
|
+
function isReactLazyRouteComponent(
|
|
169
|
+
component: unknown,
|
|
170
|
+
): component is ReactLazyRouteComponent {
|
|
171
|
+
return (
|
|
172
|
+
Boolean(component) &&
|
|
173
|
+
typeof component === 'object' &&
|
|
174
|
+
typeof (component as ReactLazyRouteComponent)._init === 'function' &&
|
|
175
|
+
'_payload' in component
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async function preloadReactLazyRouteComponent(
|
|
180
|
+
component: ReactLazyRouteComponent,
|
|
181
|
+
) {
|
|
182
|
+
try {
|
|
183
|
+
component._init?.(component._payload);
|
|
184
|
+
} catch (thrown) {
|
|
185
|
+
if (!isPromiseLike(thrown)) {
|
|
186
|
+
throw thrown;
|
|
187
|
+
}
|
|
188
|
+
await thrown;
|
|
189
|
+
component._init?.(component._payload);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
151
193
|
async function preloadRouteComponent(component: unknown) {
|
|
194
|
+
if (isReactLazyRouteComponent(component)) {
|
|
195
|
+
await preloadReactLazyRouteComponent(component);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
152
199
|
if (!isPreloadableRouteComponent(component)) {
|
|
153
200
|
return;
|
|
154
201
|
}
|
|
@@ -397,6 +444,7 @@ export const tanstackRouterPlugin = (
|
|
|
397
444
|
hooks.onBeforeCreateRouter.call(routerLifecycleContext);
|
|
398
445
|
|
|
399
446
|
const tanstackRouter = createRouter({
|
|
447
|
+
...getModernTanstackRouterFastDefaults(mergedConfig),
|
|
400
448
|
routeTree,
|
|
401
449
|
history,
|
|
402
450
|
basepath: '/',
|
|
@@ -457,9 +505,12 @@ export const tanstackRouterPlugin = (
|
|
|
457
505
|
context.ssrContext?.response.status(tanstackRouter.state.statusCode);
|
|
458
506
|
|
|
459
507
|
await serverRouter.serverSsr?.dehydrate?.();
|
|
460
|
-
await waitForRouterSerialization(serverRouter);
|
|
461
508
|
|
|
462
509
|
if (isRSCNavigation) {
|
|
510
|
+
// RSC navigations consume the server payload directly. Normal HTML SSR
|
|
511
|
+
// emits the buffered bootstrap script below and must not wait here
|
|
512
|
+
// because Modern's non-streaming hook has not rendered the app yet.
|
|
513
|
+
await waitForRouterSerialization(serverRouter);
|
|
463
514
|
setTanstackRscServerPayload(
|
|
464
515
|
createTanstackRscServerPayload(serverRouter, {
|
|
465
516
|
omitClientLoaderData: true,
|
|
@@ -514,10 +565,9 @@ export const tanstackRouterPlugin = (
|
|
|
514
565
|
return App ? <App {...props} /> : null;
|
|
515
566
|
}
|
|
516
567
|
|
|
517
|
-
const routerWrapper = (
|
|
518
|
-
<
|
|
519
|
-
|
|
520
|
-
</Suspense>
|
|
568
|
+
const routerWrapper = wrapTanstackSsrHydrationBoundary(
|
|
569
|
+
<RouterProvider router={router as AnyRouter} />,
|
|
570
|
+
true,
|
|
521
571
|
);
|
|
522
572
|
|
|
523
573
|
return App ? <App>{routerWrapper}</App> : routerWrapper;
|