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