@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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { notFound, redirect } from "@tanstack/react-router";
|
|
3
|
+
import { isAbsoluteUrl } from "../shared/isAbsoluteUrl.mjs";
|
|
4
|
+
import { reviveTanstackRscFlightValues } from "./flightSerialization.mjs";
|
|
5
|
+
const payloadFetchCache = new Map();
|
|
6
|
+
let payloadDecoder;
|
|
7
|
+
async function decodePayload(stream) {
|
|
8
|
+
if (payloadDecoder) return reviveTanstackRscFlightValues(await payloadDecoder(stream));
|
|
9
|
+
const runtime = await import("@modern-js/runtime/rsc/client");
|
|
10
|
+
return reviveTanstackRscFlightValues(await runtime.createFromReadableStream(stream));
|
|
11
|
+
}
|
|
12
|
+
function isServerPayload(value) {
|
|
13
|
+
return Boolean(value) && 'object' == typeof value && 'render' === value.type && Array.isArray(value.routes);
|
|
14
|
+
}
|
|
15
|
+
function createPayloadFetchKey(request) {
|
|
16
|
+
return JSON.stringify([
|
|
17
|
+
request.url,
|
|
18
|
+
request.method,
|
|
19
|
+
[
|
|
20
|
+
...request.headers.entries()
|
|
21
|
+
].sort(([left], [right])=>left.localeCompare(right))
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
async function fetchTanstackRscPayload(request) {
|
|
25
|
+
const headers = new Headers(request.headers);
|
|
26
|
+
headers.set('x-rsc-tree', 'true');
|
|
27
|
+
const response = await fetch(request.url, {
|
|
28
|
+
credentials: 'same-origin',
|
|
29
|
+
headers,
|
|
30
|
+
method: 'GET',
|
|
31
|
+
signal: request.signal
|
|
32
|
+
});
|
|
33
|
+
const redirectLocation = response.headers.get('X-Modernjs-Redirect');
|
|
34
|
+
if (redirectLocation) {
|
|
35
|
+
if (isAbsoluteUrl(redirectLocation)) throw redirect({
|
|
36
|
+
headers: response.headers,
|
|
37
|
+
href: redirectLocation,
|
|
38
|
+
statusCode: response.status
|
|
39
|
+
});
|
|
40
|
+
throw redirect({
|
|
41
|
+
headers: response.headers,
|
|
42
|
+
statusCode: response.status,
|
|
43
|
+
to: redirectLocation || '/'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (404 === response.status && !response.body) throw notFound();
|
|
47
|
+
if (!response.body) throw new Error('TanStack RSC payload response body is null.');
|
|
48
|
+
const payload = await decodePayload(response.body);
|
|
49
|
+
if (!isServerPayload(payload)) throw new Error('Unexpected TanStack RSC payload type.');
|
|
50
|
+
return payload;
|
|
51
|
+
}
|
|
52
|
+
function __setTanstackRscPayloadDecoderForTests(decoder) {
|
|
53
|
+
payloadDecoder = decoder;
|
|
54
|
+
payloadFetchCache.clear();
|
|
55
|
+
}
|
|
56
|
+
export { __setTanstackRscPayloadDecoderForTests, createPayloadFetchKey, fetchTanstackRscPayload, isAbsoluteUrl, payloadFetchCache };
|
|
@@ -1,77 +1,9 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const routeId = match.routeId ?? match.route?.id ?? match.id;
|
|
8
|
-
return 'string' == typeof routeId ? routeId : void 0;
|
|
9
|
-
}
|
|
10
|
-
function getRouteStaticData(match) {
|
|
11
|
-
return match.route?.options?.staticData || {};
|
|
12
|
-
}
|
|
13
|
-
function getRouteParentId(match) {
|
|
14
|
-
const parentId = match.route?.parentRoute?.id;
|
|
15
|
-
return 'string' == typeof parentId ? parentId : void 0;
|
|
16
|
-
}
|
|
17
|
-
function toRoutePath(match) {
|
|
18
|
-
const path = match.route?.options?.path;
|
|
19
|
-
return 'string' == typeof path ? path : void 0;
|
|
20
|
-
}
|
|
21
|
-
function toPayloadRoute(match) {
|
|
22
|
-
const routeId = getRouteId(match);
|
|
23
|
-
if (!routeId) return;
|
|
24
|
-
const staticData = getRouteStaticData(match);
|
|
25
|
-
const params = match.params && 'object' == typeof match.params ? match.params : {};
|
|
26
|
-
const pathname = 'string' == typeof match.pathname ? match.pathname : '';
|
|
27
|
-
return {
|
|
28
|
-
handle: staticData.modernRouteHandle,
|
|
29
|
-
hasAction: Boolean(staticData.modernRouteHasAction || staticData.modernRouteAction),
|
|
30
|
-
hasErrorBoundary: false,
|
|
31
|
-
hasLoader: Boolean(staticData.modernRouteHasLoader),
|
|
32
|
-
hasClientLoader: Boolean(staticData.modernRouteHasClientLoader),
|
|
33
|
-
id: routeId,
|
|
34
|
-
index: Boolean(match.route?.options?.index) || void 0,
|
|
35
|
-
params,
|
|
36
|
-
parentId: getRouteParentId(match),
|
|
37
|
-
path: toRoutePath(match),
|
|
38
|
-
pathname,
|
|
39
|
-
pathnameBase: 'string' == typeof match.pathnameBase ? match.pathnameBase : pathname
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function shouldRedactServerError(status = 500) {
|
|
43
|
-
return status >= 500 && 'development' !== process.env.NODE_ENV && 'test' !== process.env.NODE_ENV;
|
|
44
|
-
}
|
|
45
|
-
function serializePayloadError(error) {
|
|
46
|
-
if (isRouteErrorResponse(error)) {
|
|
47
|
-
if (shouldRedactServerError(error.status)) return {
|
|
48
|
-
status: error.status,
|
|
49
|
-
statusText: 'Internal Server Error',
|
|
50
|
-
data: 'Unexpected Server Error',
|
|
51
|
-
__type: 'RouteErrorResponse'
|
|
52
|
-
};
|
|
53
|
-
return {
|
|
54
|
-
...error,
|
|
55
|
-
__type: 'RouteErrorResponse'
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
if (error instanceof Error) {
|
|
59
|
-
if (shouldRedactServerError()) return {
|
|
60
|
-
message: 'Unexpected Server Error',
|
|
61
|
-
stack: void 0,
|
|
62
|
-
__type: 'Error'
|
|
63
|
-
};
|
|
64
|
-
return {
|
|
65
|
-
message: error.message,
|
|
66
|
-
stack: error.stack,
|
|
67
|
-
__type: 'Error',
|
|
68
|
-
...'Error' !== error.name ? {
|
|
69
|
-
__subType: error.name
|
|
70
|
-
} : {}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return error;
|
|
74
|
-
}
|
|
2
|
+
import { notFound } from "@tanstack/react-router";
|
|
3
|
+
import { serializeTanstackRscFlightValues } from "./flightSerialization.mjs";
|
|
4
|
+
import { isSerializedNotFound, serializePayloadError, toRouteErrors, toRouteLoaderData } from "./payloadErrors.mjs";
|
|
5
|
+
import { __setTanstackRscPayloadDecoderForTests, createPayloadFetchKey, fetchTanstackRscPayload, payloadFetchCache } from "./payloadFetch.mjs";
|
|
6
|
+
import { toPayloadRoute, toPlainLocation } from "./payloadRoutes.mjs";
|
|
75
7
|
function createTanstackRscServerPayload(router, options = {}) {
|
|
76
8
|
const matches = Array.isArray(router.state?.matches) ? router.state.matches : [];
|
|
77
9
|
const routes = [];
|
|
@@ -81,7 +13,7 @@ function createTanstackRscServerPayload(router, options = {}) {
|
|
|
81
13
|
const payloadRoute = toPayloadRoute(match);
|
|
82
14
|
if (payloadRoute) {
|
|
83
15
|
routes.push(payloadRoute);
|
|
84
|
-
if ('loaderData' in match && void 0 !== match.loaderData && !(options.omitClientLoaderData && payloadRoute.hasClientLoader)) loaderData[payloadRoute.id] = match.loaderData;
|
|
16
|
+
if ('loaderData' in match && void 0 !== match.loaderData && !(options.omitClientLoaderData && payloadRoute.hasClientLoader)) loaderData[payloadRoute.id] = serializeTanstackRscFlightValues(match.loaderData);
|
|
85
17
|
if (void 0 !== match.error) errors[payloadRoute.id] = serializePayloadError(match.error);
|
|
86
18
|
}
|
|
87
19
|
}
|
|
@@ -90,14 +22,17 @@ function createTanstackRscServerPayload(router, options = {}) {
|
|
|
90
22
|
actionData: null,
|
|
91
23
|
errors: Object.keys(errors).length > 0 ? errors : null,
|
|
92
24
|
loaderData,
|
|
93
|
-
location: router.state?.location,
|
|
25
|
+
location: toPlainLocation(router.state?.location),
|
|
94
26
|
routes
|
|
95
27
|
};
|
|
96
28
|
}
|
|
97
29
|
function handleTanstackRscRedirect(headers, basename, status) {
|
|
98
30
|
const newHeaders = new Headers(headers);
|
|
99
31
|
let redirectUrl = headers.get('Location') || '/';
|
|
100
|
-
if ('/' !== basename)
|
|
32
|
+
if ('/' !== basename) {
|
|
33
|
+
if (redirectUrl === basename) redirectUrl = '/';
|
|
34
|
+
else if (redirectUrl.startsWith(`${basename}/`)) redirectUrl = redirectUrl.slice(basename.length);
|
|
35
|
+
}
|
|
101
36
|
newHeaders.set('X-Modernjs-Redirect', redirectUrl);
|
|
102
37
|
newHeaders.set('X-Modernjs-BaseUrl', basename);
|
|
103
38
|
newHeaders.delete('Location');
|
|
@@ -109,69 +44,17 @@ function handleTanstackRscRedirect(headers, basename, status) {
|
|
|
109
44
|
function isTanstackRscPayloadNavigationEnabled() {
|
|
110
45
|
return "u" > typeof window;
|
|
111
46
|
}
|
|
112
|
-
async function decodePayload(stream) {
|
|
113
|
-
if (payloadDecoder) return payloadDecoder(stream);
|
|
114
|
-
const runtime = await import("@modern-js/runtime/rsc/client");
|
|
115
|
-
return runtime.createFromReadableStream(stream);
|
|
116
|
-
}
|
|
117
|
-
function isServerPayload(value) {
|
|
118
|
-
return Boolean(value) && 'object' == typeof value && 'render' === value.type && Array.isArray(value.routes);
|
|
119
|
-
}
|
|
120
|
-
function createPayloadFetchKey(request) {
|
|
121
|
-
return request.url;
|
|
122
|
-
}
|
|
123
|
-
function isAbsoluteUrl(value) {
|
|
124
|
-
try {
|
|
125
|
-
new URL(value);
|
|
126
|
-
return true;
|
|
127
|
-
} catch {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
async function fetchTanstackRscPayload(request) {
|
|
132
|
-
const headers = new Headers(request.headers);
|
|
133
|
-
headers.set('x-rsc-tree', 'true');
|
|
134
|
-
const response = await fetch(request.url, {
|
|
135
|
-
credentials: 'same-origin',
|
|
136
|
-
headers,
|
|
137
|
-
method: 'GET',
|
|
138
|
-
signal: request.signal
|
|
139
|
-
});
|
|
140
|
-
const redirectLocation = response.headers.get('X-Modernjs-Redirect');
|
|
141
|
-
if (redirectLocation) {
|
|
142
|
-
if (isAbsoluteUrl(redirectLocation)) throw redirect({
|
|
143
|
-
href: redirectLocation
|
|
144
|
-
});
|
|
145
|
-
throw redirect({
|
|
146
|
-
to: redirectLocation || '/'
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
if (404 === response.status && !response.body) throw notFound();
|
|
150
|
-
if (!response.body) throw new Error('TanStack RSC payload response body is null.');
|
|
151
|
-
const payload = await decodePayload(response.body);
|
|
152
|
-
if (!isServerPayload(payload)) throw new Error('Unexpected TanStack RSC payload type.');
|
|
153
|
-
return payload;
|
|
154
|
-
}
|
|
155
47
|
function loadTanstackRscPayload(request) {
|
|
156
48
|
const key = createPayloadFetchKey(request);
|
|
157
49
|
let payloadPromise = payloadFetchCache.get(key);
|
|
158
50
|
if (!payloadPromise) {
|
|
159
51
|
payloadPromise = fetchTanstackRscPayload(request).finally(()=>{
|
|
160
|
-
payloadFetchCache
|
|
52
|
+
payloadFetchCache["delete"](key);
|
|
161
53
|
});
|
|
162
54
|
payloadFetchCache.set(key, payloadPromise);
|
|
163
55
|
}
|
|
164
56
|
return payloadPromise;
|
|
165
57
|
}
|
|
166
|
-
function isSerializedNotFound(value) {
|
|
167
|
-
return Boolean(value) && 'object' == typeof value && true === value.isNotFound;
|
|
168
|
-
}
|
|
169
|
-
function toRouteErrors(payload) {
|
|
170
|
-
return payload.errors && 'object' == typeof payload.errors ? payload.errors : {};
|
|
171
|
-
}
|
|
172
|
-
function toRouteLoaderData(payload) {
|
|
173
|
-
return payload.loaderData && 'object' == typeof payload.loaderData ? payload.loaderData : {};
|
|
174
|
-
}
|
|
175
58
|
async function loadTanstackRscRouteData({ hasClientLoader, loadClientData, request, routeId }) {
|
|
176
59
|
if (hasClientLoader) return loadClientData();
|
|
177
60
|
if (!routeId) return loadClientData();
|
|
@@ -190,8 +73,4 @@ async function loadTanstackRscRouteData({ hasClientLoader, loadClientData, reque
|
|
|
190
73
|
const payloadRoute = payload.routes.find((route)=>route.id === routeId);
|
|
191
74
|
if (payloadRoute && payloadRoute.hasClientLoader) return loadClientData();
|
|
192
75
|
}
|
|
193
|
-
function __setTanstackRscPayloadDecoderForTests(decoder) {
|
|
194
|
-
payloadDecoder = decoder;
|
|
195
|
-
payloadFetchCache.clear();
|
|
196
|
-
}
|
|
197
76
|
export { __setTanstackRscPayloadDecoderForTests, createTanstackRscServerPayload, handleTanstackRscRedirect, isTanstackRscPayloadNavigationEnabled, loadTanstackRscPayload, loadTanstackRscRouteData };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
function toPlainRecord(value) {
|
|
3
|
+
if (!value || 'object' != typeof value) return {};
|
|
4
|
+
return Object.fromEntries(Object.entries(value));
|
|
5
|
+
}
|
|
6
|
+
function toPlainLocation(location) {
|
|
7
|
+
if (!location || 'object' != typeof location) return location;
|
|
8
|
+
const plainLocation = toPlainRecord(location);
|
|
9
|
+
for (const key of [
|
|
10
|
+
'search',
|
|
11
|
+
'state'
|
|
12
|
+
])if (plainLocation[key] && 'object' == typeof plainLocation[key] && !Array.isArray(plainLocation[key])) plainLocation[key] = toPlainRecord(plainLocation[key]);
|
|
13
|
+
return plainLocation;
|
|
14
|
+
}
|
|
15
|
+
function getRouteId(match) {
|
|
16
|
+
const routeId = match.routeId ?? match.route?.id ?? match.id;
|
|
17
|
+
return 'string' == typeof routeId ? routeId : void 0;
|
|
18
|
+
}
|
|
19
|
+
function getRouteStaticData(match) {
|
|
20
|
+
return match.route?.options?.staticData || {};
|
|
21
|
+
}
|
|
22
|
+
function getRouteParentId(match) {
|
|
23
|
+
const parentId = match.route?.parentRoute?.id;
|
|
24
|
+
return 'string' == typeof parentId ? parentId : void 0;
|
|
25
|
+
}
|
|
26
|
+
function toRoutePath(match) {
|
|
27
|
+
const path = match.route?.options?.path;
|
|
28
|
+
return 'string' == typeof path ? path : void 0;
|
|
29
|
+
}
|
|
30
|
+
function toPayloadRoute(match) {
|
|
31
|
+
const routeId = getRouteId(match);
|
|
32
|
+
if (!routeId) return;
|
|
33
|
+
const staticData = getRouteStaticData(match);
|
|
34
|
+
const params = match.params && 'object' == typeof match.params ? toPlainRecord(match.params) : {};
|
|
35
|
+
const pathname = 'string' == typeof match.pathname ? match.pathname : '';
|
|
36
|
+
return {
|
|
37
|
+
handle: staticData.modernRouteHandle,
|
|
38
|
+
hasAction: Boolean(staticData.modernRouteHasAction || staticData.modernRouteAction),
|
|
39
|
+
hasErrorBoundary: false,
|
|
40
|
+
hasLoader: Boolean(staticData.modernRouteHasLoader),
|
|
41
|
+
hasClientLoader: Boolean(staticData.modernRouteHasClientLoader),
|
|
42
|
+
id: routeId,
|
|
43
|
+
index: Boolean(match.route?.options?.index) || void 0,
|
|
44
|
+
params,
|
|
45
|
+
parentId: getRouteParentId(match),
|
|
46
|
+
path: toRoutePath(match),
|
|
47
|
+
pathname,
|
|
48
|
+
pathnameBase: 'string' == typeof match.pathnameBase ? match.pathnameBase : pathname
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export { getRouteId, toPayloadRoute, toPlainLocation };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { storage } from "@modern-js/runtime-utils/node";
|
|
3
|
+
const setTanstackRscServerPayload = (payload)=>{
|
|
4
|
+
const storageContext = storage.useContext?.();
|
|
5
|
+
if (storageContext) storageContext.serverPayload = payload;
|
|
6
|
+
};
|
|
7
|
+
const setTanstackRscRouter = (router)=>{
|
|
8
|
+
const storageContext = storage.useContext?.();
|
|
9
|
+
if (storageContext) storageContext.tanstackRscRouter = router;
|
|
10
|
+
};
|
|
11
|
+
const getTanstackRscRouter = ()=>{
|
|
12
|
+
const storageContext = storage.useContext?.();
|
|
13
|
+
return storageContext?.tanstackRscRouter;
|
|
14
|
+
};
|
|
15
|
+
export { getTanstackRscRouter, setTanstackRscRouter, setTanstackRscServerPayload };
|
|
@@ -1,27 +1,12 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
-
import {
|
|
4
|
-
import { createSerializationAdapter } from "@tanstack/
|
|
5
|
-
import {
|
|
6
|
-
import { createElement, use } from "react";
|
|
3
|
+
import { renderRsc } from "@modern-js/runtime/rsc/server";
|
|
4
|
+
import { RawStream, createSerializationAdapter } from "@tanstack/router-core";
|
|
5
|
+
import { createElement } from "react";
|
|
7
6
|
import { ClientSlot } from "./ClientSlot.mjs";
|
|
8
|
-
import { createRscProxy } from "./createRscProxy.mjs";
|
|
9
7
|
import { ReplayableStream } from "./ReplayableStream.mjs";
|
|
10
8
|
import { sanitizeSlotArgs } from "./slotUsageSanitizer.mjs";
|
|
11
|
-
import { RSC_SLOT_USAGES_STREAM, SERVER_COMPONENT_STREAM, isRenderableServerComponent, isServerComponent } from "./symbols.mjs";
|
|
12
|
-
function createTreeGetter(stream) {
|
|
13
|
-
let ready = false;
|
|
14
|
-
let tree;
|
|
15
|
-
const treePromise = Promise.resolve(createFromReadableStream(stream.createReplayStream())).then((value)=>{
|
|
16
|
-
tree = value;
|
|
17
|
-
ready = true;
|
|
18
|
-
return value;
|
|
19
|
-
});
|
|
20
|
-
return ()=>{
|
|
21
|
-
if (ready) return tree;
|
|
22
|
-
return use(treePromise);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
9
|
+
import { RENDERABLE_RSC, RSC_SLOT_USAGES_STREAM, SERVER_COMPONENT_STREAM, isRenderableServerComponent, isServerComponent } from "./symbols.mjs";
|
|
25
10
|
function createSlotProxy(options) {
|
|
26
11
|
const cache = new Map();
|
|
27
12
|
return new Proxy({}, {
|
|
@@ -45,6 +30,17 @@ function createSlotProxy(options) {
|
|
|
45
30
|
}
|
|
46
31
|
});
|
|
47
32
|
}
|
|
33
|
+
function createServerRscValue(options) {
|
|
34
|
+
return {
|
|
35
|
+
[SERVER_COMPONENT_STREAM]: options.stream,
|
|
36
|
+
...options.renderable ? {
|
|
37
|
+
[RENDERABLE_RSC]: true
|
|
38
|
+
} : {},
|
|
39
|
+
...options.slotUsagesStream ? {
|
|
40
|
+
[RSC_SLOT_USAGES_STREAM]: options.slotUsagesStream
|
|
41
|
+
} : {}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
48
44
|
function toReplayableFlightStream(node, handlers) {
|
|
49
45
|
const flightStream = renderRsc({
|
|
50
46
|
element: node
|
|
@@ -58,7 +54,7 @@ async function renderServerComponent(node) {
|
|
|
58
54
|
const streamWrapper = {
|
|
59
55
|
createReplayStream: ()=>stream.createReplayStream()
|
|
60
56
|
};
|
|
61
|
-
return
|
|
57
|
+
return createServerRscValue({
|
|
62
58
|
renderable: true,
|
|
63
59
|
stream: streamWrapper
|
|
64
60
|
});
|
|
@@ -87,7 +83,7 @@ async function createCompositeComponent(component) {
|
|
|
87
83
|
const streamWrapper = {
|
|
88
84
|
createReplayStream: ()=>flightStream.createReplayStream()
|
|
89
85
|
};
|
|
90
|
-
return
|
|
86
|
+
return createServerRscValue({
|
|
91
87
|
renderable: false,
|
|
92
88
|
slotUsagesStream: slotUsagesEmitter?.stream,
|
|
93
89
|
stream: streamWrapper
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { RSC_PROXY_GET_TREE, RSC_PROXY_PATH } from "./symbols.mjs";
|
|
3
|
+
const TANSTACK_RSC_FLIGHT_VALUE = '__modernTanstackRsc';
|
|
4
|
+
function isSerializedTanstackRscFlightValue(value) {
|
|
5
|
+
return Boolean(value) && 'object' == typeof value && true === value[TANSTACK_RSC_FLIGHT_VALUE] && ('renderable' === value.kind || 'composite' === value.kind) && value.stream instanceof ReadableStream;
|
|
6
|
+
}
|
|
7
|
+
function EmptyFallback() {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
function selectTreePath(tree, path) {
|
|
11
|
+
let current = tree;
|
|
12
|
+
for (const key of path){
|
|
13
|
+
if (null === current || 'object' != typeof current) return null;
|
|
14
|
+
current = current[key];
|
|
15
|
+
}
|
|
16
|
+
return current;
|
|
17
|
+
}
|
|
18
|
+
function renderSelectedTree(src, { getTree = src[RSC_PROXY_GET_TREE], missingTreeError }) {
|
|
19
|
+
if (!getTree) throw new Error(missingTreeError);
|
|
20
|
+
return selectTreePath(getTree(), src[RSC_PROXY_PATH] || []);
|
|
21
|
+
}
|
|
22
|
+
export { EmptyFallback, TANSTACK_RSC_FLIGHT_VALUE, isSerializedTanstackRscFlightValue, renderSelectedTree };
|
|
@@ -14,6 +14,7 @@ function sanitizeSlotArg(value, seen) {
|
|
|
14
14
|
if (null == value) return value;
|
|
15
15
|
if ('string' == typeof value || 'number' == typeof value || 'boolean' == typeof value || 'bigint' == typeof value) return value;
|
|
16
16
|
if ('object' != typeof value && 'function' != typeof value) return String(value);
|
|
17
|
+
if ('function' == typeof value) return '[Function]';
|
|
17
18
|
if (seen.has(value)) return '[Circular]';
|
|
18
19
|
seen.add(value);
|
|
19
20
|
if (Array.isArray(value)) return value.map((item)=>sanitizeSlotArg(item, seen));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
"use client";
|
|
3
|
+
import { use } from "react";
|
|
4
|
+
let modernRscClientRuntimePromise;
|
|
5
|
+
function loadModernRscClientRuntime() {
|
|
6
|
+
modernRscClientRuntimePromise ??= import("@modern-js/runtime/rsc/client").then((runtime)=>{
|
|
7
|
+
runtime.setServerCallback(runtime.callServer);
|
|
8
|
+
return runtime;
|
|
9
|
+
});
|
|
10
|
+
return modernRscClientRuntimePromise;
|
|
11
|
+
}
|
|
12
|
+
async function createFromFlightStream(stream) {
|
|
13
|
+
if ("u" < typeof window) {
|
|
14
|
+
const runtime = await import("react-server-dom-rspack/client.edge");
|
|
15
|
+
return runtime.createFromReadableStream(stream);
|
|
16
|
+
}
|
|
17
|
+
const runtime = await loadModernRscClientRuntime();
|
|
18
|
+
return runtime.createFromReadableStream(stream, {
|
|
19
|
+
callServer: runtime.callServer
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function createTreeGetterFromFlightStream(stream) {
|
|
23
|
+
let ready = false;
|
|
24
|
+
let tree;
|
|
25
|
+
const treePromise = createFromFlightStream(stream).then((value)=>{
|
|
26
|
+
tree = value;
|
|
27
|
+
ready = true;
|
|
28
|
+
return value;
|
|
29
|
+
});
|
|
30
|
+
return ()=>{
|
|
31
|
+
if (ready) return tree;
|
|
32
|
+
return use(treePromise);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export { createTreeGetterFromFlightStream };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
async function waitForRouterSerialization(tanstackRouter) {
|
|
3
|
+
const serverSsr = tanstackRouter.serverSsr;
|
|
4
|
+
if (!serverSsr || 'function' != typeof serverSsr.onSerializationFinished || serverSsr.isSerializationFinished?.()) return;
|
|
5
|
+
await new Promise((resolve)=>{
|
|
6
|
+
serverSsr.onSerializationFinished?.(resolve);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function htmlEscapeAttr(value) {
|
|
10
|
+
return value.replace(/&/g, '&').replace(/"/g, '"');
|
|
11
|
+
}
|
|
12
|
+
function routerManagedTagToHtml(tag) {
|
|
13
|
+
if (!tag || 'object' != typeof tag) return '';
|
|
14
|
+
const managedTag = tag;
|
|
15
|
+
if (!managedTag || "script" !== managedTag.tag) return '';
|
|
16
|
+
const attrs = managedTag.attrs || {};
|
|
17
|
+
const attrsStr = Object.entries(attrs).filter(([, v])=>null != v && false !== v).map(([k, v])=>{
|
|
18
|
+
const name = 'className' === k ? 'class' : k;
|
|
19
|
+
if (true === v) return name;
|
|
20
|
+
return `${name}="${htmlEscapeAttr(String(v))}"`;
|
|
21
|
+
}).join(' ');
|
|
22
|
+
const open = attrsStr.length ? `<script ${attrsStr}>` : "<script>";
|
|
23
|
+
const children = 'string' == typeof managedTag.children ? managedTag.children : '';
|
|
24
|
+
return `${open}${children}</script>`;
|
|
25
|
+
}
|
|
26
|
+
function routerManagedTagsToHtml(tags) {
|
|
27
|
+
const normalizedTags = Array.isArray(tags) ? tags : [
|
|
28
|
+
tags
|
|
29
|
+
];
|
|
30
|
+
return normalizedTags.map(routerManagedTagToHtml).filter(Boolean);
|
|
31
|
+
}
|
|
32
|
+
function createGetSsrHref(request) {
|
|
33
|
+
const url = new URL(request.url);
|
|
34
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
35
|
+
}
|
|
36
|
+
function collectRouterErrors(tanstackRouter) {
|
|
37
|
+
const state = tanstackRouter.state;
|
|
38
|
+
const matches = Array.isArray(state.matches) ? state.matches : [];
|
|
39
|
+
const errors = matches.reduce((acc, match)=>{
|
|
40
|
+
if (!match.error) return acc;
|
|
41
|
+
const routeId = 'string' == typeof match.routeId ? match.routeId : 'string' == typeof match.route?.id ? match.route.id : `match-${Object.keys(acc).length}`;
|
|
42
|
+
acc[routeId] = match.error;
|
|
43
|
+
return acc;
|
|
44
|
+
}, {});
|
|
45
|
+
return Object.keys(errors).length > 0 ? errors : void 0;
|
|
46
|
+
}
|
|
47
|
+
async function attachServerSsrUtils(router) {
|
|
48
|
+
const { attachRouterServerSsrUtils } = await import("@tanstack/router-core/ssr/server");
|
|
49
|
+
attachRouterServerSsrUtils({
|
|
50
|
+
router,
|
|
51
|
+
manifest: void 0
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export { attachServerSsrUtils, collectRouterErrors, createGetSsrHref, routerManagedTagsToHtml, waitForRouterSerialization };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
function isPromiseLike(value) {
|
|
3
|
+
return Boolean(value && 'function' == typeof value.then);
|
|
4
|
+
}
|
|
5
|
+
function isPreloadableRouteComponent(component) {
|
|
6
|
+
if (!component || 'function' != typeof component) return false;
|
|
7
|
+
const preloadable = component;
|
|
8
|
+
return 'function' == typeof preloadable.load || 'function' == typeof preloadable.preload;
|
|
9
|
+
}
|
|
10
|
+
function isReactLazyRouteComponent(component) {
|
|
11
|
+
return null != component && 'object' == typeof component && 'function' == typeof component._init && '_payload' in component;
|
|
12
|
+
}
|
|
13
|
+
async function preloadReactLazyRouteComponent(component) {
|
|
14
|
+
try {
|
|
15
|
+
component._init?.(component._payload);
|
|
16
|
+
} catch (thrown) {
|
|
17
|
+
if (!isPromiseLike(thrown)) throw thrown;
|
|
18
|
+
await thrown;
|
|
19
|
+
component._init?.(component._payload);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function preloadRouteComponent(component, preloadedComponents) {
|
|
23
|
+
if (isReactLazyRouteComponent(component)) {
|
|
24
|
+
if (preloadedComponents.has(component)) return;
|
|
25
|
+
preloadedComponents.add(component);
|
|
26
|
+
await preloadReactLazyRouteComponent(component);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (!isPreloadableRouteComponent(component)) return;
|
|
30
|
+
if (preloadedComponents.has(component)) return;
|
|
31
|
+
preloadedComponents.add(component);
|
|
32
|
+
if ('function' == typeof component.load) return void await component.load({});
|
|
33
|
+
await component.preload?.({});
|
|
34
|
+
}
|
|
35
|
+
async function preloadMatchedRouteComponents(tanstackRouter) {
|
|
36
|
+
const matches = Array.isArray(tanstackRouter.state.matches) ? tanstackRouter.state.matches : [];
|
|
37
|
+
const routesById = tanstackRouter.routesById || {};
|
|
38
|
+
const preloadedComponents = new Set();
|
|
39
|
+
await Promise.all(matches.map(async (match)=>{
|
|
40
|
+
const routeId = 'string' == typeof match.routeId ? match.routeId : 'string' == typeof match.route?.id ? match.route.id : void 0;
|
|
41
|
+
const route = routeId ? routesById[routeId] : match.route;
|
|
42
|
+
const options = route?.options;
|
|
43
|
+
if (!options) return;
|
|
44
|
+
await Promise.all([
|
|
45
|
+
preloadRouteComponent(options.component, preloadedComponents),
|
|
46
|
+
preloadRouteComponent(options.pendingComponent, preloadedComponents),
|
|
47
|
+
preloadRouteComponent(options.errorComponent, preloadedComponents),
|
|
48
|
+
preloadRouteComponent(options.notFoundComponent, preloadedComponents)
|
|
49
|
+
]);
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
export { preloadMatchedRouteComponents };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "node:module";
|
|
@@ -2,7 +2,7 @@ import "node:module";
|
|
|
2
2
|
import { getRouterRuntimeState } from "@modern-js/runtime/context";
|
|
3
3
|
function getTanstackRouterState(context) {
|
|
4
4
|
const state = getRouterRuntimeState(context);
|
|
5
|
-
if (void 0 === state || 'tanstack' !== state.framework) return;
|
|
5
|
+
if (void 0 === state || 'tanstack' !== state.framework || void 0 === state.instance) return;
|
|
6
6
|
return state;
|
|
7
7
|
}
|
|
8
8
|
export { getTanstackRouterState };
|