@bleedingdev/modern-js-plugin-tanstack 3.5.0-ultramodern.9 → 3.5.0-ultramodern.90
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/artifacts.js +157 -0
- package/dist/cjs/cli/index.js +8 -79
- package/dist/cjs/cli/tanstackTypes/canonicalRoutes.js +113 -0
- package/dist/cjs/cli/tanstackTypes/shared.js +123 -0
- package/dist/cjs/cli/tanstackTypes/source.js +255 -0
- package/dist/cjs/cli/tanstackTypes.js +4 -350
- package/dist/cjs/runtime/blockingSubscribe.js +57 -0
- package/dist/cjs/runtime/{pluginCore.js → clientBasepath.js} +12 -19
- package/dist/cjs/runtime/clientHydration.js +118 -0
- package/dist/cjs/runtime/dataMutation.js +11 -176
- package/dist/cjs/runtime/formData.js +116 -0
- package/dist/cjs/runtime/loaderBridge.js +7 -11
- package/dist/cjs/runtime/plugin.js +21 -125
- package/dist/cjs/runtime/plugin.node.js +45 -125
- package/dist/cjs/runtime/pluginShared.js +87 -0
- package/dist/cjs/runtime/prefetchLink.js +15 -2
- package/dist/cjs/runtime/register.js +3 -16
- package/dist/cjs/runtime/routeTree/components.js +102 -0
- package/dist/cjs/runtime/routeTree/construction.js +152 -0
- package/dist/cjs/runtime/routeTree/index.js +47 -0
- package/dist/cjs/runtime/routeTree/loaders.js +158 -0
- package/dist/cjs/runtime/routeTree/paths.js +57 -0
- package/dist/cjs/runtime/routeTree/staticData.js +63 -0
- package/dist/cjs/runtime/routeTree/tanstackRoutes.js +57 -0
- package/dist/cjs/runtime/routeTree/types.js +18 -0
- package/dist/cjs/runtime/routeTree.js +7 -320
- package/dist/cjs/runtime/router.js +15 -2
- package/dist/cjs/runtime/rsc/CompositeComponent.js +18 -13
- package/dist/cjs/runtime/rsc/ReplayableStream.js +0 -4
- package/dist/cjs/runtime/rsc/RscNodeRenderer.js +5 -16
- package/dist/cjs/runtime/rsc/client.js +8 -25
- package/dist/cjs/runtime/rsc/flightSerialization.js +132 -0
- package/dist/cjs/runtime/rsc/payloadErrors.js +99 -0
- package/dist/cjs/runtime/rsc/payloadFetch.js +105 -0
- package/dist/cjs/runtime/rsc/payloadRouter.js +21 -142
- package/dist/cjs/runtime/rsc/payloadRoutes.js +94 -0
- package/dist/cjs/runtime/rsc/payloadStorage.js +58 -0
- package/dist/cjs/runtime/rsc/server.js +14 -18
- package/dist/cjs/runtime/rsc/shared.js +68 -0
- package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +1 -0
- package/dist/cjs/runtime/rsc/treeGetter.js +72 -0
- package/dist/cjs/runtime/shared/isAbsoluteUrl.js +47 -0
- package/dist/cjs/runtime/ssrManagedTags.js +103 -0
- package/dist/cjs/runtime/ssrPreload.js +89 -0
- package/dist/cjs/runtime/ssrTypes.js +18 -0
- package/dist/cjs/runtime/state.js +1 -1
- package/dist/cjs/runtime/submitAction.js +161 -0
- package/dist/cjs/runtime/utils.js +49 -86
- package/dist/esm/cli/artifacts.mjs +103 -0
- package/dist/esm/cli/index.mjs +8 -82
- package/dist/esm/cli/tanstackTypes/canonicalRoutes.mjs +75 -0
- package/dist/esm/cli/tanstackTypes/shared.mjs +61 -0
- package/dist/esm/cli/tanstackTypes/source.mjs +207 -0
- package/dist/esm/cli/tanstackTypes.mjs +2 -339
- package/dist/esm/runtime/blockingSubscribe.mjs +19 -0
- package/dist/esm/runtime/clientBasepath.mjs +10 -0
- package/dist/esm/runtime/clientHydration.mjs +71 -0
- package/dist/esm/runtime/dataMutation.mjs +2 -167
- package/dist/esm/runtime/formData.mjs +63 -0
- package/dist/esm/runtime/loaderBridge.mjs +5 -9
- package/dist/esm/runtime/plugin.mjs +14 -118
- package/dist/esm/runtime/plugin.node.mjs +41 -121
- package/dist/esm/runtime/pluginShared.mjs +40 -0
- package/dist/esm/runtime/prefetchLink.mjs +18 -5
- package/dist/esm/runtime/register.mjs +1 -14
- package/dist/esm/runtime/routeTree/components.mjs +55 -0
- package/dist/esm/runtime/routeTree/construction.mjs +111 -0
- package/dist/esm/runtime/routeTree/index.mjs +2 -0
- package/dist/esm/runtime/routeTree/loaders.mjs +117 -0
- package/dist/esm/runtime/routeTree/paths.mjs +16 -0
- package/dist/esm/runtime/routeTree/staticData.mjs +22 -0
- package/dist/esm/runtime/routeTree/tanstackRoutes.mjs +13 -0
- package/dist/esm/runtime/routeTree/types.mjs +0 -0
- package/dist/esm/runtime/routeTree.mjs +1 -318
- package/dist/esm/runtime/router.mjs +16 -2
- package/dist/esm/runtime/rsc/CompositeComponent.mjs +18 -13
- package/dist/esm/runtime/rsc/ReplayableStream.mjs +1 -1
- package/dist/esm/runtime/rsc/RscNodeRenderer.mjs +4 -15
- package/dist/esm/runtime/rsc/client.mjs +6 -26
- package/dist/esm/runtime/rsc/flightSerialization.mjs +88 -0
- package/dist/esm/runtime/rsc/payloadErrors.mjs +49 -0
- package/dist/esm/runtime/rsc/payloadFetch.mjs +55 -0
- package/dist/esm/runtime/rsc/payloadRouter.mjs +12 -133
- package/dist/esm/runtime/rsc/payloadRoutes.mjs +50 -0
- package/dist/esm/runtime/rsc/payloadStorage.mjs +14 -0
- package/dist/esm/runtime/rsc/server.mjs +17 -21
- package/dist/esm/runtime/rsc/shared.mjs +21 -0
- package/dist/esm/runtime/rsc/slotUsageSanitizer.mjs +1 -0
- package/dist/esm/runtime/rsc/treeGetter.mjs +34 -0
- package/dist/esm/runtime/shared/isAbsoluteUrl.mjs +9 -0
- package/dist/esm/runtime/ssrManagedTags.mjs +53 -0
- package/dist/esm/runtime/ssrPreload.mjs +51 -0
- package/dist/esm/runtime/ssrTypes.mjs +0 -0
- package/dist/esm/runtime/state.mjs +1 -1
- package/dist/esm/runtime/submitAction.mjs +120 -0
- package/dist/esm/runtime/utils.mjs +47 -75
- package/dist/esm-node/cli/artifacts.mjs +104 -0
- package/dist/esm-node/cli/index.mjs +8 -82
- package/dist/esm-node/cli/tanstackTypes/canonicalRoutes.mjs +76 -0
- package/dist/esm-node/cli/tanstackTypes/shared.mjs +62 -0
- package/dist/esm-node/cli/tanstackTypes/source.mjs +208 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +2 -339
- package/dist/esm-node/runtime/blockingSubscribe.mjs +20 -0
- package/dist/esm-node/runtime/clientBasepath.mjs +11 -0
- package/dist/esm-node/runtime/clientHydration.mjs +72 -0
- package/dist/esm-node/runtime/dataMutation.mjs +2 -167
- package/dist/esm-node/runtime/formData.mjs +64 -0
- package/dist/esm-node/runtime/loaderBridge.mjs +5 -9
- package/dist/esm-node/runtime/plugin.mjs +14 -118
- package/dist/esm-node/runtime/plugin.node.mjs +41 -121
- package/dist/esm-node/runtime/pluginShared.mjs +41 -0
- package/dist/esm-node/runtime/prefetchLink.mjs +18 -5
- package/dist/esm-node/runtime/register.mjs +1 -14
- package/dist/esm-node/runtime/routeTree/components.mjs +56 -0
- package/dist/esm-node/runtime/routeTree/construction.mjs +112 -0
- package/dist/esm-node/runtime/routeTree/index.mjs +3 -0
- package/dist/esm-node/runtime/routeTree/loaders.mjs +118 -0
- package/dist/esm-node/runtime/routeTree/paths.mjs +17 -0
- package/dist/esm-node/runtime/routeTree/staticData.mjs +23 -0
- package/dist/esm-node/runtime/routeTree/tanstackRoutes.mjs +14 -0
- package/dist/esm-node/runtime/routeTree/types.mjs +1 -0
- package/dist/esm-node/runtime/routeTree.mjs +1 -318
- package/dist/esm-node/runtime/router.mjs +16 -2
- package/dist/esm-node/runtime/rsc/CompositeComponent.mjs +18 -13
- package/dist/esm-node/runtime/rsc/ReplayableStream.mjs +1 -1
- package/dist/esm-node/runtime/rsc/RscNodeRenderer.mjs +4 -15
- package/dist/esm-node/runtime/rsc/client.mjs +6 -26
- package/dist/esm-node/runtime/rsc/flightSerialization.mjs +89 -0
- package/dist/esm-node/runtime/rsc/payloadErrors.mjs +50 -0
- package/dist/esm-node/runtime/rsc/payloadFetch.mjs +56 -0
- package/dist/esm-node/runtime/rsc/payloadRouter.mjs +12 -133
- package/dist/esm-node/runtime/rsc/payloadRoutes.mjs +51 -0
- package/dist/esm-node/runtime/rsc/payloadStorage.mjs +15 -0
- package/dist/esm-node/runtime/rsc/server.mjs +17 -21
- package/dist/esm-node/runtime/rsc/shared.mjs +22 -0
- package/dist/esm-node/runtime/rsc/slotUsageSanitizer.mjs +1 -0
- package/dist/esm-node/runtime/rsc/treeGetter.mjs +35 -0
- package/dist/esm-node/runtime/shared/isAbsoluteUrl.mjs +10 -0
- package/dist/esm-node/runtime/ssrManagedTags.mjs +54 -0
- package/dist/esm-node/runtime/ssrPreload.mjs +52 -0
- package/dist/esm-node/runtime/ssrTypes.mjs +1 -0
- package/dist/esm-node/runtime/state.mjs +1 -1
- package/dist/esm-node/runtime/submitAction.mjs +121 -0
- package/dist/esm-node/runtime/utils.mjs +47 -75
- package/dist/types/cli/artifacts.d.ts +33 -0
- package/dist/types/cli/index.d.ts +2 -22
- package/dist/types/cli/tanstackTypes/canonicalRoutes.d.ts +22 -0
- package/dist/types/cli/tanstackTypes/shared.d.ts +20 -0
- package/dist/types/cli/tanstackTypes/source.d.ts +12 -0
- package/dist/types/cli/tanstackTypes.d.ts +3 -31
- package/dist/types/runtime/blockingSubscribe.d.ts +1 -0
- package/dist/types/runtime/clientBasepath.d.ts +1 -0
- package/dist/types/runtime/clientHydration.d.ts +10 -0
- package/dist/types/runtime/dataMutation.d.ts +3 -12
- package/dist/types/runtime/formData.d.ts +24 -0
- package/dist/types/runtime/loaderBridge.d.ts +2 -1
- package/dist/types/runtime/plugin.d.ts +1 -1
- package/dist/types/runtime/plugin.node.d.ts +1 -1
- package/dist/types/runtime/pluginShared.d.ts +38 -0
- package/dist/types/runtime/register.d.ts +10 -9
- package/dist/types/runtime/routeTree/components.d.ts +7 -0
- package/dist/types/runtime/routeTree/construction.d.ts +5 -0
- package/dist/types/runtime/routeTree/index.d.ts +2 -0
- package/dist/types/runtime/routeTree/loaders.d.ts +4 -0
- package/dist/types/runtime/routeTree/paths.d.ts +3 -0
- package/dist/types/runtime/routeTree/staticData.d.ts +19 -0
- package/dist/types/runtime/routeTree/tanstackRoutes.d.ts +4 -0
- package/dist/types/runtime/routeTree/types.d.ts +76 -0
- package/dist/types/runtime/routeTree.d.ts +1 -9
- package/dist/types/runtime/router.d.ts +6 -7
- package/dist/types/runtime/rsc/CompositeComponent.d.ts +1 -2
- package/dist/types/runtime/rsc/ReplayableStream.d.ts +3 -2
- package/dist/types/runtime/rsc/RscNodeRenderer.d.ts +2 -3
- package/dist/types/runtime/rsc/SlotContext.d.ts +2 -1
- package/dist/types/runtime/rsc/client.d.ts +2 -0
- package/dist/types/runtime/rsc/flightSerialization.d.ts +3 -0
- package/dist/types/runtime/rsc/payloadErrors.d.ts +6 -0
- package/dist/types/runtime/rsc/payloadFetch.d.ts +8 -0
- package/dist/types/runtime/rsc/payloadRouter.d.ts +2 -10
- package/dist/types/runtime/rsc/payloadRoutes.d.ts +40 -0
- package/dist/types/runtime/rsc/payloadStorage.d.ts +5 -0
- package/dist/types/runtime/rsc/shared.d.ts +18 -0
- package/dist/types/runtime/rsc/treeGetter.d.ts +1 -0
- package/dist/types/runtime/shared/isAbsoluteUrl.d.ts +1 -0
- package/dist/types/runtime/ssrManagedTags.d.ts +7 -0
- package/dist/types/runtime/ssrPreload.d.ts +2 -0
- package/dist/types/runtime/ssrTypes.d.ts +44 -0
- package/dist/types/runtime/state.d.ts +1 -1
- package/dist/types/runtime/submitAction.d.ts +14 -0
- package/dist/types/runtime/types.d.ts +4 -10
- package/dist/types/runtime/utils.d.ts +4 -24
- package/package.json +37 -17
- package/rstest.config.mts +23 -0
- package/src/cli/artifacts.ts +255 -0
- package/src/cli/index.ts +7 -185
- package/src/cli/tanstackTypes/canonicalRoutes.ts +157 -0
- package/src/cli/tanstackTypes/shared.ts +113 -0
- package/src/cli/tanstackTypes/source.ts +414 -0
- package/src/cli/tanstackTypes.ts +4 -647
- package/src/runtime/blockingSubscribe.ts +48 -0
- package/src/runtime/clientBasepath.ts +12 -0
- package/src/runtime/clientHydration.ts +149 -0
- package/src/runtime/dataMutation.tsx +9 -306
- package/src/runtime/formData.ts +153 -0
- package/src/runtime/loaderBridge.ts +11 -12
- package/src/runtime/plugin.node.tsx +76 -291
- package/src/runtime/plugin.tsx +21 -257
- package/src/runtime/pluginShared.ts +112 -0
- package/src/runtime/prefetchLink.tsx +78 -15
- package/src/runtime/register.ts +10 -42
- package/src/runtime/routeTree/components.ts +130 -0
- package/src/runtime/routeTree/construction.ts +238 -0
- package/src/runtime/routeTree/index.ts +7 -0
- package/src/runtime/routeTree/loaders.ts +232 -0
- package/src/runtime/routeTree/paths.ts +36 -0
- package/src/runtime/routeTree/staticData.ts +66 -0
- package/src/runtime/routeTree/tanstackRoutes.ts +36 -0
- package/src/runtime/routeTree/types.ts +87 -0
- package/src/runtime/routeTree.ts +5 -750
- package/src/runtime/router.ts +35 -7
- package/src/runtime/rsc/CompositeComponent.tsx +29 -20
- package/src/runtime/rsc/ReplayableStream.ts +2 -2
- package/src/runtime/rsc/RscNodeRenderer.tsx +9 -27
- package/src/runtime/rsc/SlotContext.tsx +1 -1
- package/src/runtime/rsc/client.tsx +12 -40
- package/src/runtime/rsc/flightSerialization.ts +158 -0
- package/src/runtime/rsc/payloadErrors.ts +73 -0
- package/src/runtime/rsc/payloadFetch.ts +92 -0
- package/src/runtime/rsc/payloadRouter.ts +29 -234
- package/src/runtime/rsc/payloadRoutes.ts +122 -0
- package/src/runtime/rsc/payloadStorage.ts +35 -0
- package/src/runtime/rsc/server.tsx +20 -29
- package/src/runtime/rsc/shared.ts +70 -0
- package/src/runtime/rsc/slotUsageSanitizer.ts +4 -0
- package/src/runtime/rsc/treeGetter.tsx +52 -0
- package/src/runtime/shared/isAbsoluteUrl.ts +8 -0
- package/src/runtime/ssrManagedTags.ts +107 -0
- package/src/runtime/ssrPreload.ts +125 -0
- package/src/runtime/ssrTypes.ts +51 -0
- package/src/runtime/state.ts +9 -3
- package/src/runtime/submitAction.ts +201 -0
- package/src/runtime/types.ts +4 -18
- package/src/runtime/utils.tsx +76 -110
- package/src/types/react-server-dom-rspack.d.ts +56 -0
- package/tests/castRatchet.test.ts +85 -0
- package/tests/realm-isolation.test.ts +114 -0
- package/tests/router/cli.test.ts +7 -0
- package/tests/router/clientHydration.test.tsx +61 -0
- package/tests/router/dataMutation.test.tsx +59 -0
- package/tests/router/fixtures/legacyRuntimeRouter.ts +10 -0
- package/tests/router/fixtures/router-gen.golden.txt +71 -0
- package/tests/router/fixtures/router-gen.oxlint.json +5 -0
- package/tests/router/flightSerialization.roundtrip.test.tsx +137 -0
- package/tests/router/generateRouteArtifacts.test.ts +106 -0
- package/tests/router/hooks.test.ts +14 -0
- package/tests/router/loaderBridge.test.ts +21 -0
- package/tests/router/prefetchLink.test.tsx +106 -59
- package/tests/router/prefetchLinkPreload.test.tsx +85 -0
- package/tests/router/register.test.ts +1 -39
- package/tests/router/routeTree.test.ts +51 -11
- package/tests/router/routerCompatibility.test.ts +245 -0
- package/tests/router/rsc.test.tsx +189 -0
- package/tests/router/rscPayloadRouterMatrix.test.ts +197 -0
- package/tests/router/slotUsageSanitizer.test.ts +23 -0
- package/tests/router/ssrPreload.test.ts +30 -0
- package/tests/router/tanstackTypes.test.ts +298 -1
- package/dist/esm/runtime/pluginCore.mjs +0 -14
- package/dist/esm-node/runtime/pluginCore.mjs +0 -15
- package/dist/types/runtime/pluginCore.d.ts +0 -21
- package/src/runtime/pluginCore.ts +0 -48
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
getGlobalEnableRsc,
|
|
6
|
+
type InternalRouterServerSnapshot,
|
|
6
7
|
InternalRuntimeContext,
|
|
7
|
-
type ServerPayload,
|
|
8
8
|
type TInternalRuntimeContext,
|
|
9
9
|
} from '@modern-js/runtime/context';
|
|
10
10
|
import {
|
|
11
11
|
createRequestContext,
|
|
12
12
|
type RequestContext,
|
|
13
|
-
storage,
|
|
14
13
|
} from '@modern-js/runtime-utils/node';
|
|
15
14
|
import { time } from '@modern-js/runtime-utils/time';
|
|
16
15
|
import { LOADER_REPORTER_NAME } from '@modern-js/utils/universal/constants';
|
|
@@ -32,11 +31,12 @@ import {
|
|
|
32
31
|
type RouterLifecycleContext,
|
|
33
32
|
} from './lifecycle';
|
|
34
33
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
createTanstackRouteObjects,
|
|
35
|
+
getTanstackRouteConfig,
|
|
36
|
+
joinBasename,
|
|
37
37
|
type TanstackRouterPluginAPI,
|
|
38
38
|
type TanstackRouterRuntimePlugin,
|
|
39
|
-
} from './
|
|
39
|
+
} from './pluginShared';
|
|
40
40
|
import {
|
|
41
41
|
createRouteTreeFromRouteObjects,
|
|
42
42
|
getModernRouteIdsFromMatches,
|
|
@@ -45,270 +45,27 @@ import {
|
|
|
45
45
|
createTanstackRscServerPayload,
|
|
46
46
|
handleTanstackRscRedirect,
|
|
47
47
|
} from './rsc/payloadRouter';
|
|
48
|
+
import {
|
|
49
|
+
getTanstackRscRouter,
|
|
50
|
+
setTanstackRscRouter,
|
|
51
|
+
setTanstackRscServerPayload,
|
|
52
|
+
} from './rsc/payloadStorage';
|
|
53
|
+
import {
|
|
54
|
+
attachServerSsrUtils,
|
|
55
|
+
collectRouterErrors,
|
|
56
|
+
createGetSsrHref,
|
|
57
|
+
routerManagedTagsToHtml,
|
|
58
|
+
waitForRouterSerialization,
|
|
59
|
+
} from './ssrManagedTags';
|
|
60
|
+
import { preloadMatchedRouteComponents } from './ssrPreload';
|
|
61
|
+
import type {
|
|
62
|
+
ModernTanstackRouterContext,
|
|
63
|
+
TanstackRouterWithServerSsr,
|
|
64
|
+
} from './ssrTypes';
|
|
48
65
|
import {
|
|
49
66
|
getModernTanstackRouterFastDefaults,
|
|
50
|
-
type InternalRouterServerSnapshot,
|
|
51
67
|
type RouterConfig,
|
|
52
68
|
} from './types';
|
|
53
|
-
import { createRouteObjectsFromConfig, urlJoin } from './utils';
|
|
54
|
-
|
|
55
|
-
type ModernTanstackRouterContext = {
|
|
56
|
-
request: Request;
|
|
57
|
-
requestContext: RequestContext<Record<string, unknown>>;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const setTanstackRscServerPayload = (payload: ServerPayload) => {
|
|
61
|
-
const storageContext = storage.useContext?.() as
|
|
62
|
-
| { serverPayload?: ServerPayload }
|
|
63
|
-
| undefined;
|
|
64
|
-
if (storageContext) {
|
|
65
|
-
storageContext.serverPayload = payload;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
type RouterManagedTag = {
|
|
70
|
-
attrs?: Record<string, unknown>;
|
|
71
|
-
children?: unknown;
|
|
72
|
-
tag?: unknown;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
type RouterMatchWithError = {
|
|
76
|
-
error?: unknown;
|
|
77
|
-
route?: {
|
|
78
|
-
id?: unknown;
|
|
79
|
-
options?: RouterRouteOptions;
|
|
80
|
-
};
|
|
81
|
-
routeId?: unknown;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
type RouterRouteOptions = {
|
|
85
|
-
component?: unknown;
|
|
86
|
-
errorComponent?: unknown;
|
|
87
|
-
notFoundComponent?: unknown;
|
|
88
|
-
pendingComponent?: unknown;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
type RouterRouteWithOptions = {
|
|
92
|
-
options?: RouterRouteOptions;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
type PreloadableRouteComponent = {
|
|
96
|
-
load?: (props?: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
97
|
-
preload?: (props?: Record<string, unknown>) => Promise<unknown> | unknown;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
type ReactLazyRouteComponent = {
|
|
101
|
-
_init?: (payload: unknown) => unknown;
|
|
102
|
-
_payload?: unknown;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
function isPromiseLike(value: unknown): value is PromiseLike<unknown> {
|
|
106
|
-
return Boolean(
|
|
107
|
-
value && typeof (value as PromiseLike<unknown>).then === 'function',
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
type TanstackRouterWithServerSsr = AnyRouter & {
|
|
112
|
-
resolveRedirect?: (redirect: Response) => Response;
|
|
113
|
-
routesById?: Record<string, RouterRouteWithOptions>;
|
|
114
|
-
serverSsr?: {
|
|
115
|
-
cleanup?: () => void;
|
|
116
|
-
dehydrate?: () => Promise<void> | void;
|
|
117
|
-
isSerializationFinished?: () => boolean;
|
|
118
|
-
onSerializationFinished?: (listener: () => void) => void;
|
|
119
|
-
takeBufferedScripts?: () => unknown;
|
|
120
|
-
};
|
|
121
|
-
state: AnyRouter['state'] & {
|
|
122
|
-
matches?: unknown;
|
|
123
|
-
redirect?: Response;
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
function isPreloadableRouteComponent(
|
|
128
|
-
component: unknown,
|
|
129
|
-
): component is PreloadableRouteComponent {
|
|
130
|
-
if (!component || typeof component !== 'function') {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const preloadable = component as PreloadableRouteComponent;
|
|
135
|
-
return (
|
|
136
|
-
typeof preloadable.load === 'function' ||
|
|
137
|
-
typeof preloadable.preload === 'function'
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function isReactLazyRouteComponent(
|
|
142
|
-
component: unknown,
|
|
143
|
-
): component is ReactLazyRouteComponent {
|
|
144
|
-
return (
|
|
145
|
-
component !== null &&
|
|
146
|
-
component !== undefined &&
|
|
147
|
-
typeof component === 'object' &&
|
|
148
|
-
typeof (component as ReactLazyRouteComponent)._init === 'function' &&
|
|
149
|
-
'_payload' in component
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async function preloadReactLazyRouteComponent(
|
|
154
|
-
component: ReactLazyRouteComponent,
|
|
155
|
-
) {
|
|
156
|
-
try {
|
|
157
|
-
component._init?.(component._payload);
|
|
158
|
-
} catch (thrown) {
|
|
159
|
-
if (!isPromiseLike(thrown)) {
|
|
160
|
-
throw thrown;
|
|
161
|
-
}
|
|
162
|
-
await thrown;
|
|
163
|
-
component._init?.(component._payload);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async function preloadRouteComponent(component: unknown) {
|
|
168
|
-
if (isReactLazyRouteComponent(component)) {
|
|
169
|
-
await preloadReactLazyRouteComponent(component);
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (!isPreloadableRouteComponent(component)) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (typeof component.load === 'function') {
|
|
178
|
-
await component.load({});
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
await component.preload?.({});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async function preloadMatchedRouteComponents(
|
|
186
|
-
tanstackRouter: TanstackRouterWithServerSsr,
|
|
187
|
-
) {
|
|
188
|
-
const matches = Array.isArray(tanstackRouter.state.matches)
|
|
189
|
-
? (tanstackRouter.state.matches as RouterMatchWithError[])
|
|
190
|
-
: [];
|
|
191
|
-
const routesById = tanstackRouter.routesById || {};
|
|
192
|
-
|
|
193
|
-
await Promise.all(
|
|
194
|
-
matches.map(async match => {
|
|
195
|
-
const routeId =
|
|
196
|
-
typeof match.routeId === 'string'
|
|
197
|
-
? match.routeId
|
|
198
|
-
: typeof match.route?.id === 'string'
|
|
199
|
-
? match.route.id
|
|
200
|
-
: undefined;
|
|
201
|
-
const route = routeId ? routesById[routeId] : match.route;
|
|
202
|
-
const options = route?.options;
|
|
203
|
-
if (!options) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
await Promise.all([
|
|
208
|
-
preloadRouteComponent(options.component),
|
|
209
|
-
preloadRouteComponent(options.pendingComponent),
|
|
210
|
-
preloadRouteComponent(options.errorComponent),
|
|
211
|
-
preloadRouteComponent(options.notFoundComponent),
|
|
212
|
-
]);
|
|
213
|
-
}),
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
async function waitForRouterSerialization(
|
|
218
|
-
tanstackRouter: TanstackRouterWithServerSsr,
|
|
219
|
-
) {
|
|
220
|
-
const serverSsr = tanstackRouter.serverSsr;
|
|
221
|
-
if (
|
|
222
|
-
!serverSsr ||
|
|
223
|
-
typeof serverSsr.onSerializationFinished !== 'function' ||
|
|
224
|
-
serverSsr.isSerializationFinished?.()
|
|
225
|
-
) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
await new Promise<void>(resolve => {
|
|
230
|
-
serverSsr.onSerializationFinished?.(resolve);
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function htmlEscapeAttr(value: string) {
|
|
235
|
-
return value.replace(/&/g, '&').replace(/"/g, '"');
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function routerManagedTagToHtml(tag: unknown): string {
|
|
239
|
-
if (!tag || typeof tag !== 'object') {
|
|
240
|
-
return '';
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const managedTag = tag as RouterManagedTag;
|
|
244
|
-
if (!managedTag || managedTag.tag !== 'script') {
|
|
245
|
-
return '';
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const attrs: Record<string, unknown> = managedTag.attrs || {};
|
|
249
|
-
const attrsStr = Object.entries(attrs)
|
|
250
|
-
.filter(([, v]) => v != null && v !== false)
|
|
251
|
-
.map(([k, v]) => {
|
|
252
|
-
const name = k === 'className' ? 'class' : k;
|
|
253
|
-
if (v === true) {
|
|
254
|
-
return name;
|
|
255
|
-
}
|
|
256
|
-
return `${name}="${htmlEscapeAttr(String(v))}"`;
|
|
257
|
-
})
|
|
258
|
-
.join(' ');
|
|
259
|
-
|
|
260
|
-
const open = attrsStr.length ? `<script ${attrsStr}>` : '<script>';
|
|
261
|
-
const children =
|
|
262
|
-
typeof managedTag.children === 'string' ? managedTag.children : '';
|
|
263
|
-
return `${open}${children}</script>`;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function routerManagedTagsToHtml(tags: unknown): string[] {
|
|
267
|
-
const normalizedTags = Array.isArray(tags) ? tags : [tags];
|
|
268
|
-
return normalizedTags.map(routerManagedTagToHtml).filter(Boolean);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function createGetSsrHref(request: Request): string {
|
|
272
|
-
const url = new URL(request.url);
|
|
273
|
-
return `${url.pathname}${url.search}${url.hash}`;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function collectRouterErrors(
|
|
277
|
-
tanstackRouter: AnyRouter,
|
|
278
|
-
): Record<string, unknown> | undefined {
|
|
279
|
-
const state = tanstackRouter.state as { matches?: unknown };
|
|
280
|
-
const matches = Array.isArray(state.matches)
|
|
281
|
-
? (state.matches as RouterMatchWithError[])
|
|
282
|
-
: [];
|
|
283
|
-
const errors = matches.reduce((acc: Record<string, unknown>, match) => {
|
|
284
|
-
if (!match.error) {
|
|
285
|
-
return acc;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
const routeId =
|
|
289
|
-
typeof match.routeId === 'string'
|
|
290
|
-
? match.routeId
|
|
291
|
-
: typeof match.route?.id === 'string'
|
|
292
|
-
? match.route.id
|
|
293
|
-
: `match-${Object.keys(acc).length}`;
|
|
294
|
-
|
|
295
|
-
acc[routeId] = match.error;
|
|
296
|
-
return acc;
|
|
297
|
-
}, {});
|
|
298
|
-
|
|
299
|
-
return Object.keys(errors).length > 0 ? errors : undefined;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
async function attachServerSsrUtils(router: TanstackRouterWithServerSsr) {
|
|
303
|
-
const { attachRouterServerSsrUtils } = await import(
|
|
304
|
-
'@tanstack/router-core/ssr/server'
|
|
305
|
-
);
|
|
306
|
-
|
|
307
|
-
attachRouterServerSsrUtils({
|
|
308
|
-
router,
|
|
309
|
-
manifest: undefined,
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
69
|
|
|
313
70
|
export const tanstackRouterPlugin = (
|
|
314
71
|
userConfig: Partial<RouterConfig> = {},
|
|
@@ -318,30 +75,27 @@ export const tanstackRouterPlugin = (
|
|
|
318
75
|
registryHooks: routerProviderRegistryHooks,
|
|
319
76
|
setup: (api: TanstackRouterPluginAPI) => {
|
|
320
77
|
api.onBeforeRender(async (context, interrupt) => {
|
|
321
|
-
const
|
|
78
|
+
const routeConfig = getTanstackRouteConfig(api, userConfig);
|
|
79
|
+
const { mergedConfig } = routeConfig;
|
|
322
80
|
const serializationAdapters = getGlobalEnableRsc()
|
|
323
81
|
? (await import('./rsc/server')).getTanstackRscSerializationAdapters()
|
|
324
82
|
: undefined;
|
|
325
83
|
const enableRsc = getGlobalEnableRsc();
|
|
326
84
|
|
|
327
|
-
const { basename = ''
|
|
85
|
+
const { basename = '' } = mergedConfig;
|
|
328
86
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (!finalRouteConfig.routes && !createRoutes) {
|
|
87
|
+
if (!routeConfig.hasConfiguredRoutes) {
|
|
332
88
|
return;
|
|
333
89
|
}
|
|
334
90
|
|
|
335
91
|
const hooks = api.getHooks();
|
|
336
92
|
await hooks.onBeforeCreateRoutes.call(context);
|
|
337
93
|
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}) || [];
|
|
344
|
-
const modifiedRouteObjects = hooks.modifyRoutes.call(routeObjects);
|
|
94
|
+
const modifiedRouteObjects = createTanstackRouteObjects({
|
|
95
|
+
hooks,
|
|
96
|
+
routeConfig,
|
|
97
|
+
ssrMode: context.ssrContext?.mode,
|
|
98
|
+
});
|
|
345
99
|
|
|
346
100
|
if (!modifiedRouteObjects.length) {
|
|
347
101
|
return;
|
|
@@ -355,20 +109,21 @@ export const tanstackRouterPlugin = (
|
|
|
355
109
|
} = context.ssrContext!;
|
|
356
110
|
|
|
357
111
|
const _basename =
|
|
358
|
-
baseUrl === '/' ?
|
|
112
|
+
baseUrl === '/' ? joinBasename(baseUrl, basename || '') : baseUrl;
|
|
359
113
|
|
|
360
|
-
const
|
|
114
|
+
const rawRequest = request.raw as Request;
|
|
115
|
+
const initialHref = createGetSsrHref(rawRequest);
|
|
361
116
|
const isRSCNavigation =
|
|
362
|
-
enableRsc &&
|
|
117
|
+
enableRsc && rawRequest.headers.get('x-rsc-tree') === 'true';
|
|
363
118
|
|
|
364
119
|
const requestContext = createRequestContext(
|
|
365
120
|
context.ssrContext?.loaderContext,
|
|
366
121
|
) as RequestContext<Record<string, unknown>>;
|
|
367
122
|
|
|
368
123
|
const controller = new AbortController();
|
|
369
|
-
const ssrRequest = new Request(
|
|
124
|
+
const ssrRequest = new Request(rawRequest.url, {
|
|
370
125
|
method: 'GET',
|
|
371
|
-
headers:
|
|
126
|
+
headers: rawRequest.headers,
|
|
372
127
|
signal: controller.signal,
|
|
373
128
|
});
|
|
374
129
|
|
|
@@ -398,13 +153,16 @@ export const tanstackRouterPlugin = (
|
|
|
398
153
|
history,
|
|
399
154
|
basepath: '/',
|
|
400
155
|
rewrite,
|
|
401
|
-
origin: new URL(
|
|
156
|
+
origin: new URL(rawRequest.url).origin,
|
|
402
157
|
ssr: { nonce },
|
|
403
158
|
context: routerContext as never,
|
|
404
159
|
...(serializationAdapters ? { serializationAdapters } : {}),
|
|
405
160
|
});
|
|
406
161
|
const serverRouter =
|
|
407
162
|
tanstackRouter as unknown as TanstackRouterWithServerSsr;
|
|
163
|
+
if (enableRsc) {
|
|
164
|
+
setTanstackRscRouter(serverRouter);
|
|
165
|
+
}
|
|
408
166
|
|
|
409
167
|
await attachServerSsrUtils(serverRouter);
|
|
410
168
|
|
|
@@ -439,7 +197,11 @@ export const tanstackRouterPlugin = (
|
|
|
439
197
|
|
|
440
198
|
const routerErrors = collectRouterErrors(tanstackRouter);
|
|
441
199
|
if (routerErrors && loaderFailureMode === 'clientRender') {
|
|
442
|
-
|
|
200
|
+
(
|
|
201
|
+
context.ssrContext?.response as
|
|
202
|
+
| { status: (code: number) => void }
|
|
203
|
+
| undefined
|
|
204
|
+
)?.status(200);
|
|
443
205
|
try {
|
|
444
206
|
serverRouter.serverSsr?.cleanup?.();
|
|
445
207
|
} catch {}
|
|
@@ -448,18 +210,25 @@ export const tanstackRouterPlugin = (
|
|
|
448
210
|
|
|
449
211
|
await preloadMatchedRouteComponents(serverRouter);
|
|
450
212
|
|
|
451
|
-
|
|
213
|
+
(
|
|
214
|
+
context.ssrContext?.response as
|
|
215
|
+
| { status: (code: number) => void }
|
|
216
|
+
| undefined
|
|
217
|
+
)?.status(tanstackRouter.state.statusCode);
|
|
452
218
|
|
|
453
219
|
await serverRouter.serverSsr?.dehydrate?.();
|
|
454
220
|
|
|
455
|
-
if (
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
221
|
+
if (enableRsc) {
|
|
222
|
+
if (isRSCNavigation) {
|
|
223
|
+
// RSC navigations consume the server payload directly. Normal HTML SSR
|
|
224
|
+
// emits the buffered bootstrap script below and must not wait here
|
|
225
|
+
// because Modern's non-streaming hook has not rendered the app yet.
|
|
226
|
+
await waitForRouterSerialization(serverRouter);
|
|
227
|
+
}
|
|
228
|
+
|
|
460
229
|
setTanstackRscServerPayload(
|
|
461
230
|
createTanstackRscServerPayload(serverRouter, {
|
|
462
|
-
omitClientLoaderData:
|
|
231
|
+
omitClientLoaderData: isRSCNavigation,
|
|
463
232
|
}),
|
|
464
233
|
);
|
|
465
234
|
}
|
|
@@ -501,6 +270,22 @@ export const tanstackRouterPlugin = (
|
|
|
501
270
|
|
|
502
271
|
api.wrapRoot(App => {
|
|
503
272
|
const getRouteApp = () => {
|
|
273
|
+
if (getGlobalEnableRsc()) {
|
|
274
|
+
return (props => {
|
|
275
|
+
const router = getTanstackRscRouter();
|
|
276
|
+
if (!router) {
|
|
277
|
+
return App ? <App {...props} /> : null;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const routerWrapper = wrapTanstackSsrHydrationBoundary(
|
|
281
|
+
<RouterProvider router={router as AnyRouter} />,
|
|
282
|
+
true,
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
return App ? <App>{routerWrapper}</App> : routerWrapper;
|
|
286
|
+
}) as React.FC<Record<string, unknown>>;
|
|
287
|
+
}
|
|
288
|
+
|
|
504
289
|
return (props => {
|
|
505
290
|
const context = useContext(
|
|
506
291
|
InternalRuntimeContext,
|