@bleedingdev/modern-js-plugin-tanstack 3.5.0-ultramodern.30 → 3.5.0-ultramodern.31
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 +6 -103
- package/dist/cjs/cli/tanstackTypes/canonicalRoutes.js +113 -0
- package/dist/cjs/cli/tanstackTypes/shared.js +130 -0
- package/dist/cjs/cli/tanstackTypes/source.js +251 -0
- package/dist/cjs/cli/tanstackTypes.js +4 -350
- package/dist/cjs/runtime/blockingSubscribe.js +64 -0
- package/dist/cjs/runtime/{pluginCore.js → clientBasepath.js} +12 -19
- package/dist/cjs/runtime/clientHydration.js +129 -0
- package/dist/cjs/runtime/dataMutation.js +11 -176
- package/dist/cjs/runtime/formData.js +116 -0
- package/dist/cjs/runtime/loaderBridge.js +4 -1
- package/dist/cjs/runtime/plugin.js +21 -125
- package/dist/cjs/runtime/plugin.node.js +38 -119
- package/dist/cjs/runtime/pluginShared.js +90 -0
- 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/rsc/CompositeComponent.js +18 -13
- 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 +117 -0
- package/dist/cjs/runtime/rsc/payloadRouter.js +21 -142
- package/dist/cjs/runtime/rsc/payloadRoutes.js +106 -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 +71 -0
- package/dist/cjs/runtime/rsc/treeGetter.js +72 -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/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 +4 -101
- package/dist/esm/cli/tanstackTypes/canonicalRoutes.mjs +75 -0
- package/dist/esm/cli/tanstackTypes/shared.mjs +68 -0
- package/dist/esm/cli/tanstackTypes/source.mjs +203 -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 +70 -0
- package/dist/esm/runtime/dataMutation.mjs +2 -167
- package/dist/esm/runtime/formData.mjs +63 -0
- package/dist/esm/runtime/loaderBridge.mjs +4 -1
- package/dist/esm/runtime/plugin.mjs +14 -118
- package/dist/esm/runtime/plugin.node.mjs +33 -114
- package/dist/esm/runtime/pluginShared.mjs +40 -0
- 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/rsc/CompositeComponent.mjs +18 -13
- 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 +61 -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/treeGetter.mjs +34 -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/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 +4 -101
- package/dist/esm-node/cli/tanstackTypes/canonicalRoutes.mjs +76 -0
- package/dist/esm-node/cli/tanstackTypes/shared.mjs +69 -0
- package/dist/esm-node/cli/tanstackTypes/source.mjs +204 -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 +71 -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 +4 -1
- package/dist/esm-node/runtime/plugin.mjs +14 -118
- package/dist/esm-node/runtime/plugin.node.mjs +33 -114
- package/dist/esm-node/runtime/pluginShared.mjs +41 -0
- 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/rsc/CompositeComponent.mjs +18 -13
- 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 +62 -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/treeGetter.mjs +35 -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/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 -33
- 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 +10 -0
- package/dist/types/cli/tanstackTypes.d.ts +3 -31
- package/dist/types/runtime/blockingSubscribe.d.ts +3 -0
- package/dist/types/runtime/clientBasepath.d.ts +1 -0
- package/dist/types/runtime/clientHydration.d.ts +19 -0
- package/dist/types/runtime/dataMutation.d.ts +3 -12
- package/dist/types/runtime/formData.d.ts +23 -0
- package/dist/types/runtime/plugin.d.ts +1 -1
- package/dist/types/runtime/plugin.node.d.ts +1 -1
- package/dist/types/runtime/{pluginCore.d.ts → pluginShared.d.ts} +14 -0
- 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 +75 -0
- package/dist/types/runtime/routeTree.d.ts +1 -9
- package/dist/types/runtime/rsc/CompositeComponent.d.ts +1 -2
- package/dist/types/runtime/rsc/RscNodeRenderer.d.ts +2 -3
- 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 +10 -0
- package/dist/types/runtime/rsc/payloadRouter.d.ts +2 -10
- package/dist/types/runtime/rsc/payloadRoutes.d.ts +43 -0
- package/dist/types/runtime/rsc/payloadStorage.d.ts +5 -0
- package/dist/types/runtime/rsc/shared.d.ts +19 -0
- package/dist/types/runtime/rsc/treeGetter.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 +43 -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 +3 -46
- package/dist/types/runtime/utils.d.ts +1 -22
- package/package.json +30 -9
- package/rstest.config.mts +1 -0
- package/src/cli/artifacts.ts +255 -0
- package/src/cli/index.ts +6 -246
- package/src/cli/tanstackTypes/canonicalRoutes.ts +157 -0
- package/src/cli/tanstackTypes/shared.ts +119 -0
- package/src/cli/tanstackTypes/source.ts +405 -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 +151 -0
- package/src/runtime/dataMutation.tsx +9 -306
- package/src/runtime/formData.ts +153 -0
- package/src/runtime/loaderBridge.ts +8 -3
- package/src/runtime/plugin.node.tsx +60 -284
- package/src/runtime/plugin.tsx +21 -257
- package/src/runtime/pluginShared.ts +112 -0
- 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/rsc/CompositeComponent.tsx +29 -20
- package/src/runtime/rsc/RscNodeRenderer.tsx +9 -27
- 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 +97 -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/treeGetter.tsx +52 -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 +4 -2
- package/src/runtime/submitAction.ts +194 -0
- package/src/runtime/types.ts +14 -51
- package/src/runtime/utils.tsx +72 -108
- package/src/types/react-server-dom-rspack.d.ts +56 -0
- package/tests/castRatchet.test.ts +85 -0
- package/tests/router/dataMutation.test.tsx +59 -0
- package/tests/router/fixtures/router-gen.golden.txt +72 -0
- package/tests/router/loaderBridge.test.ts +21 -0
- package/tests/router/routeTree.test.ts +46 -11
- package/tests/router/rsc.test.tsx +189 -0
- package/tests/router/ssrPreload.test.ts +30 -0
- package/tests/router/tanstackTypes.test.ts +254 -1
- package/dist/esm/runtime/pluginCore.mjs +0 -14
- package/dist/esm-node/runtime/pluginCore.mjs +0 -15
- package/src/runtime/pluginCore.ts +0 -56
|
@@ -3,22 +3,27 @@ import "node:module";
|
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
import { Suspense } from "react";
|
|
5
5
|
import { SlotProvider } from "./SlotContext.mjs";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
import { EmptyFallback, renderSelectedTree } from "./shared.mjs";
|
|
7
|
+
import { RSC_PROXY_GET_TREE, SERVER_COMPONENT_STREAM } from "./symbols.mjs";
|
|
8
|
+
import { createTreeGetterFromFlightStream } from "./treeGetter.mjs";
|
|
9
|
+
const rawServerValueGetters = new WeakMap();
|
|
10
|
+
function getRawServerTreeGetter(src) {
|
|
11
|
+
if (!src || 'object' != typeof src && 'function' != typeof src) return;
|
|
12
|
+
const source = src;
|
|
13
|
+
const stream = source[SERVER_COMPONENT_STREAM];
|
|
14
|
+
if ('function' != typeof stream?.createReplayStream) return;
|
|
15
|
+
let getTree = rawServerValueGetters.get(src);
|
|
16
|
+
if (!getTree) {
|
|
17
|
+
getTree = createTreeGetterFromFlightStream(stream.createReplayStream());
|
|
18
|
+
rawServerValueGetters.set(src, getTree);
|
|
15
19
|
}
|
|
16
|
-
return
|
|
20
|
+
return getTree;
|
|
17
21
|
}
|
|
18
22
|
function CompositeInner({ slotProps, src, strict }) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
const tree = renderSelectedTree(src, {
|
|
24
|
+
getTree: src[RSC_PROXY_GET_TREE] || getRawServerTreeGetter(src),
|
|
25
|
+
missingTreeError: 'CompositeComponent src must come from createCompositeComponent().'
|
|
26
|
+
});
|
|
22
27
|
return /*#__PURE__*/ jsx(SlotProvider, {
|
|
23
28
|
implementations: slotProps,
|
|
24
29
|
strict: strict,
|
|
@@ -2,23 +2,12 @@ import "node:module";
|
|
|
2
2
|
"use client";
|
|
3
3
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
4
4
|
import { Suspense } from "react";
|
|
5
|
-
import {
|
|
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
|
-
}
|
|
5
|
+
import { EmptyFallback, renderSelectedTree } from "./shared.mjs";
|
|
17
6
|
function RscNodeRenderInner({ data }) {
|
|
18
|
-
const getTree = data[RSC_PROXY_GET_TREE];
|
|
19
|
-
if (!getTree) throw new Error('Renderable RSC is missing its decoded tree getter.');
|
|
20
7
|
return /*#__PURE__*/ jsx(Fragment, {
|
|
21
|
-
children:
|
|
8
|
+
children: renderSelectedTree(data, {
|
|
9
|
+
missingTreeError: 'Renderable RSC is missing its decoded tree getter.'
|
|
10
|
+
})
|
|
22
11
|
});
|
|
23
12
|
}
|
|
24
13
|
function RscNodeRenderer({ data }) {
|
|
@@ -1,41 +1,21 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
"use client";
|
|
3
3
|
import { createSerializationAdapter } from "@tanstack/react-router";
|
|
4
|
-
import {
|
|
4
|
+
import { createTreeGetterFromFlightStream } from "./treeGetter.mjs";
|
|
5
5
|
import { createRscProxy } from "./createRscProxy.mjs";
|
|
6
|
-
let modernRscClientRuntimePromise;
|
|
7
|
-
function loadModernRscClientRuntime() {
|
|
8
|
-
modernRscClientRuntimePromise ??= import("@modern-js/runtime/rsc/client").then((runtime)=>{
|
|
9
|
-
runtime.setServerCallback(runtime.callServer);
|
|
10
|
-
return runtime;
|
|
11
|
-
});
|
|
12
|
-
return modernRscClientRuntimePromise;
|
|
13
|
-
}
|
|
14
|
-
function createTreeGetter(stream) {
|
|
15
|
-
let ready = false;
|
|
16
|
-
let tree;
|
|
17
|
-
const treePromise = loadModernRscClientRuntime().then((runtime)=>runtime.createFromReadableStream(stream, {
|
|
18
|
-
callServer: runtime.callServer
|
|
19
|
-
})).then((value)=>{
|
|
20
|
-
tree = value;
|
|
21
|
-
ready = true;
|
|
22
|
-
return value;
|
|
23
|
-
});
|
|
24
|
-
return ()=>{
|
|
25
|
-
if (ready) return tree;
|
|
26
|
-
return use(treePromise);
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
6
|
function createFromFlightStream(serialized) {
|
|
30
7
|
const streamWrapper = {
|
|
31
8
|
createReplayStream: ()=>serialized.stream
|
|
32
9
|
};
|
|
33
|
-
return createRscProxy(
|
|
10
|
+
return createRscProxy(createTreeGetterFromFlightStream(serialized.stream), {
|
|
34
11
|
renderable: 'renderable' === serialized.kind,
|
|
35
12
|
slotUsagesStream: serialized.slotUsagesStream,
|
|
36
13
|
stream: streamWrapper
|
|
37
14
|
});
|
|
38
15
|
}
|
|
16
|
+
function createTanstackRscValueFromFlight(serialized) {
|
|
17
|
+
return createFromFlightStream(serialized);
|
|
18
|
+
}
|
|
39
19
|
const adapter = createSerializationAdapter({
|
|
40
20
|
key: '$MODERN_TANSTACK_RSC',
|
|
41
21
|
test: (_value)=>false,
|
|
@@ -51,4 +31,4 @@ function getTanstackRscSerializationAdapters() {
|
|
|
51
31
|
}
|
|
52
32
|
const rscSerializationAdapter = getTanstackRscSerializationAdapters;
|
|
53
33
|
export { CompositeComponent } from "./CompositeComponent.mjs";
|
|
54
|
-
export { getTanstackRscSerializationAdapters, rscSerializationAdapter };
|
|
34
|
+
export { createTanstackRscValueFromFlight, getTanstackRscSerializationAdapters, rscSerializationAdapter };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { TANSTACK_RSC_FLIGHT_VALUE, isSerializedTanstackRscFlightValue } from "./shared.mjs";
|
|
3
|
+
import { RSC_SLOT_USAGES_STREAM, SERVER_COMPONENT_STREAM, isRenderableServerComponent, isServerComponent } from "./symbols.mjs";
|
|
4
|
+
function isPlainObject(value) {
|
|
5
|
+
if (!value || 'object' != typeof value) return false;
|
|
6
|
+
const prototype = Object.getPrototypeOf(value);
|
|
7
|
+
return prototype === Object.prototype || null === prototype;
|
|
8
|
+
}
|
|
9
|
+
function serializeTanstackRscFlightValues(value, seen = new WeakMap()) {
|
|
10
|
+
if (isServerComponent(value)) {
|
|
11
|
+
const streamWrapper = value[SERVER_COMPONENT_STREAM];
|
|
12
|
+
if (!streamWrapper) throw new Error('Cannot serialize TanStack RSC without a Flight stream.');
|
|
13
|
+
const kind = isRenderableServerComponent(value) ? 'renderable' : 'composite';
|
|
14
|
+
const slotUsagesStream = 'development' === process.env.NODE_ENV && 'composite' === kind ? value[RSC_SLOT_USAGES_STREAM] : void 0;
|
|
15
|
+
return {
|
|
16
|
+
[TANSTACK_RSC_FLIGHT_VALUE]: true,
|
|
17
|
+
kind,
|
|
18
|
+
stream: streamWrapper.createReplayStream(),
|
|
19
|
+
...slotUsagesStream ? {
|
|
20
|
+
slotUsagesStream
|
|
21
|
+
} : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (!value || 'object' != typeof value) return value;
|
|
25
|
+
if (seen.has(value)) return seen.get(value);
|
|
26
|
+
if (value instanceof Map) {
|
|
27
|
+
const result = new Map();
|
|
28
|
+
seen.set(value, result);
|
|
29
|
+
for (const [key, item] of value)result.set(serializeTanstackRscFlightValues(key, seen), serializeTanstackRscFlightValues(item, seen));
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
if (value instanceof Set) {
|
|
33
|
+
const result = new Set();
|
|
34
|
+
seen.set(value, result);
|
|
35
|
+
for (const item of value)result.add(serializeTanstackRscFlightValues(item, seen));
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
const result = [];
|
|
40
|
+
seen.set(value, result);
|
|
41
|
+
for (const item of value)result.push(serializeTanstackRscFlightValues(item, seen));
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
if (!isPlainObject(value)) return value;
|
|
45
|
+
const result = {};
|
|
46
|
+
seen.set(value, result);
|
|
47
|
+
for (const [key, item] of Object.entries(value))result[key] = serializeTanstackRscFlightValues(item, seen);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
async function reviveTanstackRscFlightValues(value, seen = new WeakMap()) {
|
|
51
|
+
let reviver;
|
|
52
|
+
const getReviver = async ()=>{
|
|
53
|
+
if (!reviver) {
|
|
54
|
+
const client = await import("./client.mjs");
|
|
55
|
+
reviver = client.createTanstackRscValueFromFlight;
|
|
56
|
+
}
|
|
57
|
+
return reviver;
|
|
58
|
+
};
|
|
59
|
+
const visit = async (current)=>{
|
|
60
|
+
if (isSerializedTanstackRscFlightValue(current)) return (await getReviver())(current);
|
|
61
|
+
if (!current || 'object' != typeof current) return current;
|
|
62
|
+
if (seen.has(current)) return seen.get(current);
|
|
63
|
+
if (current instanceof Map) {
|
|
64
|
+
const result = new Map();
|
|
65
|
+
seen.set(current, result);
|
|
66
|
+
for (const [key, item] of current)result.set(await visit(key), await visit(item));
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
if (current instanceof Set) {
|
|
70
|
+
const result = new Set();
|
|
71
|
+
seen.set(current, result);
|
|
72
|
+
for (const item of current)result.add(await visit(item));
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(current)) {
|
|
76
|
+
const result = [];
|
|
77
|
+
seen.set(current, result);
|
|
78
|
+
for (const item of current)result.push(await visit(item));
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
if (!isPlainObject(current)) return current;
|
|
82
|
+
const result = {};
|
|
83
|
+
seen.set(current, result);
|
|
84
|
+
for (const [key, item] of Object.entries(current))result[key] = await visit(item);
|
|
85
|
+
return result;
|
|
86
|
+
};
|
|
87
|
+
return visit(value);
|
|
88
|
+
}
|
|
89
|
+
export { isPlainObject, reviveTanstackRscFlightValues, serializeTanstackRscFlightValues };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { isRouteErrorResponse } from "@modern-js/runtime-utils/router";
|
|
3
|
+
function shouldRedactServerError(status = 500) {
|
|
4
|
+
return status >= 500 && 'development' !== process.env.NODE_ENV && 'test' !== process.env.NODE_ENV;
|
|
5
|
+
}
|
|
6
|
+
function serializePayloadError(error) {
|
|
7
|
+
if (isRouteErrorResponse(error)) {
|
|
8
|
+
if (shouldRedactServerError(error.status)) return {
|
|
9
|
+
status: error.status,
|
|
10
|
+
statusText: 'Internal Server Error',
|
|
11
|
+
data: 'Unexpected Server Error',
|
|
12
|
+
__type: 'RouteErrorResponse'
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
...error,
|
|
16
|
+
__type: 'RouteErrorResponse'
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (error instanceof Error) {
|
|
20
|
+
if (shouldRedactServerError()) return {
|
|
21
|
+
message: 'Unexpected Server Error',
|
|
22
|
+
stack: void 0,
|
|
23
|
+
__type: 'Error'
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
message: error.message,
|
|
27
|
+
stack: error.stack,
|
|
28
|
+
__type: 'Error',
|
|
29
|
+
...'Error' !== error.name ? {
|
|
30
|
+
__subType: error.name
|
|
31
|
+
} : {}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (shouldRedactServerError()) return {
|
|
35
|
+
message: 'Unexpected Server Error',
|
|
36
|
+
stack: void 0,
|
|
37
|
+
__type: 'Error'
|
|
38
|
+
};
|
|
39
|
+
return error;
|
|
40
|
+
}
|
|
41
|
+
function isSerializedNotFound(value) {
|
|
42
|
+
return Boolean(value) && 'object' == typeof value && true === value.isNotFound;
|
|
43
|
+
}
|
|
44
|
+
function toRouteErrors(payload) {
|
|
45
|
+
return payload.errors && 'object' == typeof payload.errors ? payload.errors : {};
|
|
46
|
+
}
|
|
47
|
+
function toRouteLoaderData(payload) {
|
|
48
|
+
return payload.loaderData && 'object' == typeof payload.loaderData ? payload.loaderData : {};
|
|
49
|
+
}
|
|
50
|
+
export { isSerializedNotFound, serializePayloadError, shouldRedactServerError, toRouteErrors, toRouteLoaderData };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { notFound, redirect } from "@tanstack/react-router";
|
|
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
|
+
[
|
|
18
|
+
...request.headers.entries()
|
|
19
|
+
].sort(([left], [right])=>left.localeCompare(right))
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
function isAbsoluteUrl(value) {
|
|
23
|
+
try {
|
|
24
|
+
new URL(value);
|
|
25
|
+
return true;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function fetchTanstackRscPayload(request) {
|
|
31
|
+
const headers = new Headers(request.headers);
|
|
32
|
+
headers.set('x-rsc-tree', 'true');
|
|
33
|
+
const response = await fetch(request.url, {
|
|
34
|
+
credentials: 'same-origin',
|
|
35
|
+
headers,
|
|
36
|
+
method: 'GET',
|
|
37
|
+
signal: request.signal
|
|
38
|
+
});
|
|
39
|
+
const redirectLocation = response.headers.get('X-Modernjs-Redirect');
|
|
40
|
+
if (redirectLocation) {
|
|
41
|
+
if (isAbsoluteUrl(redirectLocation)) throw redirect({
|
|
42
|
+
headers: response.headers,
|
|
43
|
+
href: redirectLocation,
|
|
44
|
+
statusCode: response.status
|
|
45
|
+
});
|
|
46
|
+
throw redirect({
|
|
47
|
+
headers: response.headers,
|
|
48
|
+
statusCode: response.status,
|
|
49
|
+
to: redirectLocation || '/'
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (404 === response.status && !response.body) throw notFound();
|
|
53
|
+
if (!response.body) throw new Error('TanStack RSC payload response body is null.');
|
|
54
|
+
const payload = await decodePayload(response.body);
|
|
55
|
+
if (!isServerPayload(payload)) throw new Error('Unexpected TanStack RSC payload type.');
|
|
56
|
+
return payload;
|
|
57
|
+
}
|
|
58
|
+
function __setTanstackRscPayloadDecoderForTests(decoder) {
|
|
59
|
+
payloadDecoder = decoder;
|
|
60
|
+
payloadFetchCache.clear();
|
|
61
|
+
}
|
|
62
|
+
export { __setTanstackRscPayloadDecoderForTests, createPayloadFetchKey, decodePayload, fetchTanstackRscPayload, isAbsoluteUrl, isServerPayload, 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, getRouteParentId, getRouteStaticData, toPayloadRoute, toPlainLocation, toPlainRecord, toRoutePath };
|
|
@@ -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
|