@bleedingdev/modern-js-plugin-tanstack 3.5.0-ultramodern.3 → 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 +8 -79
- 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 +45 -125
- package/dist/cjs/runtime/pluginShared.js +90 -0
- package/dist/cjs/runtime/prefetchLink.js +15 -2
- 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 -78
- 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 +41 -121
- package/dist/esm/runtime/pluginShared.mjs +40 -0
- package/dist/esm/runtime/prefetchLink.mjs +18 -5
- 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 -78
- 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 +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/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 -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 +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/pluginShared.d.ts +39 -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 +4 -9
- package/dist/types/runtime/utils.d.ts +4 -24
- package/package.json +30 -8
- package/rstest.config.mts +3 -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 +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 +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/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 +6 -13
- 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/router/cli.test.ts +7 -0
- package/tests/router/dataMutation.test.tsx +59 -0
- package/tests/router/fixtures/router-gen.golden.txt +72 -0
- package/tests/router/generateRouteArtifacts.test.ts +106 -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/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/dist/types/runtime/pluginCore.d.ts +0 -21
- package/src/runtime/pluginCore.ts +0 -48
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { notFound } from "@tanstack/react-router";
|
|
2
|
+
import { isRedirectResponse, isResponse, isTanstackRedirect, throwTanstackRedirect } from "../loaderBridge.mjs";
|
|
3
|
+
import { isTanstackRscPayloadNavigationEnabled, loadTanstackRscRouteData } from "../rsc/payloadRouter.mjs";
|
|
4
|
+
function isModernDeferredData(value) {
|
|
5
|
+
if (!value || 'object' != typeof value) return false;
|
|
6
|
+
const deferred = value;
|
|
7
|
+
return true === deferred.__modern_deferred && Boolean(deferred.data) && 'object' == typeof deferred.data && !Array.isArray(deferred.data);
|
|
8
|
+
}
|
|
9
|
+
function normalizeModernLoaderResult(result) {
|
|
10
|
+
return isModernDeferredData(result) ? result.data : result;
|
|
11
|
+
}
|
|
12
|
+
function normalizeModernLoaderResponse(result) {
|
|
13
|
+
if (isResponse(result)) {
|
|
14
|
+
if (isRedirectResponse(result)) {
|
|
15
|
+
const location = result.headers.get('Location') || '/';
|
|
16
|
+
throwTanstackRedirect(location);
|
|
17
|
+
}
|
|
18
|
+
if (404 === result.status) throw notFound();
|
|
19
|
+
}
|
|
20
|
+
return normalizeModernLoaderResult(result);
|
|
21
|
+
}
|
|
22
|
+
function createModernRequest(input, signal) {
|
|
23
|
+
return new Request(input, {
|
|
24
|
+
signal
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function getModernUrlFromLoaderContext(ctx) {
|
|
28
|
+
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '/';
|
|
29
|
+
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
30
|
+
const baseUrl = baseRequest?.url || ("u" > typeof window ? window.origin : 'http://localhost');
|
|
31
|
+
return new URL(href || '/', baseUrl);
|
|
32
|
+
}
|
|
33
|
+
function rememberRouteLocation(state, ctx) {
|
|
34
|
+
state.currentUrl = getModernUrlFromLoaderContext(ctx);
|
|
35
|
+
state.currentParams = ctx?.params || {};
|
|
36
|
+
}
|
|
37
|
+
function createModernShouldReload(shouldRevalidate, state) {
|
|
38
|
+
if ('function' != typeof shouldRevalidate) return;
|
|
39
|
+
const revalidate = shouldRevalidate;
|
|
40
|
+
return (ctx)=>{
|
|
41
|
+
const nextUrl = getModernUrlFromLoaderContext(ctx);
|
|
42
|
+
const nextParams = ctx?.params || {};
|
|
43
|
+
const result = revalidate({
|
|
44
|
+
currentUrl: state.currentUrl || nextUrl,
|
|
45
|
+
currentParams: state.currentParams || nextParams,
|
|
46
|
+
nextUrl,
|
|
47
|
+
nextParams,
|
|
48
|
+
defaultShouldRevalidate: void 0
|
|
49
|
+
});
|
|
50
|
+
state.currentUrl = nextUrl;
|
|
51
|
+
state.currentParams = nextParams;
|
|
52
|
+
return 'boolean' == typeof result ? result : void 0;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function isRouteObjectSplatRoute(route) {
|
|
56
|
+
return 'string' == typeof route.path && route.path.includes('*');
|
|
57
|
+
}
|
|
58
|
+
function mapParamsForRouteObjectLoader({ route, params }) {
|
|
59
|
+
if (isRouteObjectSplatRoute(route)) {
|
|
60
|
+
const { _splat, ...rest } = params;
|
|
61
|
+
if (void 0 !== _splat) return {
|
|
62
|
+
...rest,
|
|
63
|
+
'*': _splat
|
|
64
|
+
};
|
|
65
|
+
return rest;
|
|
66
|
+
}
|
|
67
|
+
return params;
|
|
68
|
+
}
|
|
69
|
+
function wrapRouteObjectLoader(route, revalidationState, options = {}) {
|
|
70
|
+
const modernRoute = route;
|
|
71
|
+
const routeLoader = modernRoute.loader;
|
|
72
|
+
if ('function' != typeof routeLoader) return;
|
|
73
|
+
return async (ctx)=>{
|
|
74
|
+
try {
|
|
75
|
+
if (revalidationState) rememberRouteLocation(revalidationState, ctx);
|
|
76
|
+
if ('function' == typeof modernRoute.lazyImport) try {
|
|
77
|
+
await modernRoute.lazyImport();
|
|
78
|
+
} catch {}
|
|
79
|
+
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
80
|
+
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
81
|
+
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
82
|
+
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
83
|
+
signal
|
|
84
|
+
}) : createModernRequest(href, signal);
|
|
85
|
+
const params = mapParamsForRouteObjectLoader({
|
|
86
|
+
route,
|
|
87
|
+
params: ctx.params || {}
|
|
88
|
+
});
|
|
89
|
+
const loadModernData = async ()=>{
|
|
90
|
+
const result = await routeLoader({
|
|
91
|
+
request,
|
|
92
|
+
params,
|
|
93
|
+
context: ctx?.context?.requestContext
|
|
94
|
+
});
|
|
95
|
+
return normalizeModernLoaderResponse(result);
|
|
96
|
+
};
|
|
97
|
+
if (options.rscPayloadRouter && isTanstackRscPayloadNavigationEnabled()) return loadTanstackRscRouteData({
|
|
98
|
+
hasClientLoader: modernRoute.hasClientLoader || void 0 !== modernRoute.clientData,
|
|
99
|
+
loadClientData: loadModernData,
|
|
100
|
+
request,
|
|
101
|
+
routeId: ctx.route?.id
|
|
102
|
+
});
|
|
103
|
+
return loadModernData();
|
|
104
|
+
} catch (err) {
|
|
105
|
+
if (isResponse(err)) {
|
|
106
|
+
if (isTanstackRedirect(err)) throw err;
|
|
107
|
+
if (isRedirectResponse(err)) {
|
|
108
|
+
const location = err.headers.get('Location') || '/';
|
|
109
|
+
throwTanstackRedirect(location);
|
|
110
|
+
}
|
|
111
|
+
if (404 === err.status) throw notFound();
|
|
112
|
+
}
|
|
113
|
+
throw err;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export { createModernShouldReload, wrapRouteObjectLoader };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function toTanstackPath(pathname) {
|
|
2
|
+
return pathname.split('/').map((segment)=>{
|
|
3
|
+
if (!segment) return segment;
|
|
4
|
+
if ('*' === segment) return '$';
|
|
5
|
+
if (segment.startsWith(':')) {
|
|
6
|
+
const name = segment.slice(1);
|
|
7
|
+
if (name.endsWith('?')) return `{-$${name.slice(0, -1)}}`;
|
|
8
|
+
return `$${name}`;
|
|
9
|
+
}
|
|
10
|
+
return segment;
|
|
11
|
+
}).join('/');
|
|
12
|
+
}
|
|
13
|
+
function isRouteObjectPathlessLayout(route) {
|
|
14
|
+
return !route.path && !route.index;
|
|
15
|
+
}
|
|
16
|
+
export { isRouteObjectPathlessLayout, toTanstackPath };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function mergeModernRouteHandle(route) {
|
|
2
|
+
const config = route.config;
|
|
3
|
+
const handle = {
|
|
4
|
+
...route.handle,
|
|
5
|
+
...config && 'object' == typeof config ? config.handle : {}
|
|
6
|
+
};
|
|
7
|
+
return Object.keys(handle).length > 0 ? handle : void 0;
|
|
8
|
+
}
|
|
9
|
+
function createRouteStaticData(opts) {
|
|
10
|
+
const staticData = {};
|
|
11
|
+
if (opts.modernRouteId) staticData.modernRouteId = opts.modernRouteId;
|
|
12
|
+
if (opts.modernRouteAction) staticData.modernRouteAction = opts.modernRouteAction;
|
|
13
|
+
if (opts.modernRouteHandle) staticData.modernRouteHandle = opts.modernRouteHandle;
|
|
14
|
+
if (opts.modernRouteHasAction) staticData.modernRouteHasAction = true;
|
|
15
|
+
if (opts.modernRouteHasClientLoader) staticData.modernRouteHasClientLoader = true;
|
|
16
|
+
if (opts.modernRouteHasLoader) staticData.modernRouteHasLoader = true;
|
|
17
|
+
if (opts.modernRouteIsClientComponent) staticData.modernRouteIsClientComponent = true;
|
|
18
|
+
if (opts.modernRouteLoader) staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
19
|
+
if (opts.modernRouteShouldRevalidate) staticData.modernRouteShouldRevalidate = opts.modernRouteShouldRevalidate;
|
|
20
|
+
return Object.keys(staticData).length > 0 ? staticData : void 0;
|
|
21
|
+
}
|
|
22
|
+
export { createRouteStaticData, mergeModernRouteHandle };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createRootRoute, createRoute } from "@tanstack/react-router";
|
|
2
|
+
import { withModernRouteMatchContext } from "../outlet.mjs";
|
|
3
|
+
function createTanstackRoute(options) {
|
|
4
|
+
return createRoute(options);
|
|
5
|
+
}
|
|
6
|
+
function createTanstackRootRoute(options) {
|
|
7
|
+
return createRootRoute(options);
|
|
8
|
+
}
|
|
9
|
+
function wrapRouteComponentWithModernContext(route, component, routeId) {
|
|
10
|
+
const routeMatchId = routeId || route.id;
|
|
11
|
+
if (component && routeMatchId) route.options.component = withModernRouteMatchContext(component, routeMatchId);
|
|
12
|
+
}
|
|
13
|
+
export { createTanstackRootRoute, createTanstackRoute, wrapRouteComponentWithModernContext };
|
|
File without changes
|
|
@@ -1,318 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { createRootRoute, createRoute, notFound, rootRouteId } from "@tanstack/react-router";
|
|
3
|
-
import { createElement } from "react";
|
|
4
|
-
import { isRedirectResponse, isResponse, isTanstackRedirect, throwTanstackRedirect } from "./loaderBridge.mjs";
|
|
5
|
-
import { withModernRouteMatchContext } from "./outlet.mjs";
|
|
6
|
-
import { isTanstackRscPayloadNavigationEnabled, loadTanstackRscRouteData } from "./rsc/payloadRouter.mjs";
|
|
7
|
-
function createTanstackRoute(options) {
|
|
8
|
-
return createRoute(options);
|
|
9
|
-
}
|
|
10
|
-
function createTanstackRootRoute(options) {
|
|
11
|
-
return createRootRoute(options);
|
|
12
|
-
}
|
|
13
|
-
function wrapRouteComponentWithModernContext(route, component, routeId) {
|
|
14
|
-
const routeMatchId = routeId || route.id;
|
|
15
|
-
if (component && routeMatchId) route.options.component = withModernRouteMatchContext(component, routeMatchId);
|
|
16
|
-
}
|
|
17
|
-
function toTanstackPath(pathname) {
|
|
18
|
-
return pathname.split('/').map((segment)=>{
|
|
19
|
-
if (!segment) return segment;
|
|
20
|
-
if ('*' === segment) return '$';
|
|
21
|
-
if (segment.startsWith(':')) {
|
|
22
|
-
const name = segment.slice(1);
|
|
23
|
-
if (name.endsWith('?')) return `{-$${name.slice(0, -1)}}`;
|
|
24
|
-
return `$${name}`;
|
|
25
|
-
}
|
|
26
|
-
return segment;
|
|
27
|
-
}).join('/');
|
|
28
|
-
}
|
|
29
|
-
function isModernDeferredData(value) {
|
|
30
|
-
if (!value || 'object' != typeof value) return false;
|
|
31
|
-
const deferred = value;
|
|
32
|
-
return true === deferred.__modern_deferred && Boolean(deferred.data) && 'object' == typeof deferred.data && !Array.isArray(deferred.data);
|
|
33
|
-
}
|
|
34
|
-
function normalizeModernLoaderResult(result) {
|
|
35
|
-
return isModernDeferredData(result) ? result.data : result;
|
|
36
|
-
}
|
|
37
|
-
function normalizeModernLoaderResponse(result) {
|
|
38
|
-
if (isResponse(result)) {
|
|
39
|
-
if (isRedirectResponse(result)) {
|
|
40
|
-
const location = result.headers.get('Location') || '/';
|
|
41
|
-
throwTanstackRedirect(location);
|
|
42
|
-
}
|
|
43
|
-
if (404 === result.status) throw notFound();
|
|
44
|
-
}
|
|
45
|
-
return normalizeModernLoaderResult(result);
|
|
46
|
-
}
|
|
47
|
-
function pickRouteModuleComponent(routeModule, seen = new Set()) {
|
|
48
|
-
if ('function' == typeof routeModule || routeModule && 'object' == typeof routeModule && '$$typeof' in routeModule) return routeModule;
|
|
49
|
-
if (!routeModule || 'object' != typeof routeModule) return;
|
|
50
|
-
if (seen.has(routeModule)) return;
|
|
51
|
-
seen.add(routeModule);
|
|
52
|
-
const module = routeModule;
|
|
53
|
-
for (const candidate of [
|
|
54
|
-
module.default,
|
|
55
|
-
module.Component
|
|
56
|
-
]){
|
|
57
|
-
const component = pickRouteModuleComponent(candidate, seen);
|
|
58
|
-
if (component) return component;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function createServerLazyImportComponent(lazyImport, fallbackComponent) {
|
|
62
|
-
if ("u" > typeof document) return fallbackComponent;
|
|
63
|
-
let resolvedComponent;
|
|
64
|
-
let pendingLoad;
|
|
65
|
-
const load = async ()=>{
|
|
66
|
-
if (resolvedComponent) return resolvedComponent;
|
|
67
|
-
const routeModule = await lazyImport();
|
|
68
|
-
const component = pickRouteModuleComponent(routeModule);
|
|
69
|
-
if (component) resolvedComponent = component;
|
|
70
|
-
return resolvedComponent;
|
|
71
|
-
};
|
|
72
|
-
const Component = (props)=>{
|
|
73
|
-
if (resolvedComponent) return createElement(resolvedComponent, props);
|
|
74
|
-
pendingLoad ||= load();
|
|
75
|
-
throw pendingLoad;
|
|
76
|
-
};
|
|
77
|
-
Component.load = load;
|
|
78
|
-
Component.preload = load;
|
|
79
|
-
return Component;
|
|
80
|
-
}
|
|
81
|
-
function createModernRequest(input, signal) {
|
|
82
|
-
return new Request(input, {
|
|
83
|
-
signal
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
function getModernUrlFromLoaderContext(ctx) {
|
|
87
|
-
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '/';
|
|
88
|
-
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
89
|
-
const baseUrl = baseRequest?.url || ("u" > typeof window ? window.origin : 'http://localhost');
|
|
90
|
-
return new URL(href || '/', baseUrl);
|
|
91
|
-
}
|
|
92
|
-
function rememberRouteLocation(state, ctx) {
|
|
93
|
-
state.currentUrl = getModernUrlFromLoaderContext(ctx);
|
|
94
|
-
state.currentParams = ctx?.params || {};
|
|
95
|
-
}
|
|
96
|
-
function createModernShouldReload(shouldRevalidate, state) {
|
|
97
|
-
if ('function' != typeof shouldRevalidate) return;
|
|
98
|
-
const revalidate = shouldRevalidate;
|
|
99
|
-
return (ctx)=>{
|
|
100
|
-
const nextUrl = getModernUrlFromLoaderContext(ctx);
|
|
101
|
-
const nextParams = ctx?.params || {};
|
|
102
|
-
const result = revalidate({
|
|
103
|
-
currentUrl: state.currentUrl || nextUrl,
|
|
104
|
-
currentParams: state.currentParams || nextParams,
|
|
105
|
-
nextUrl,
|
|
106
|
-
nextParams,
|
|
107
|
-
defaultShouldRevalidate: void 0
|
|
108
|
-
});
|
|
109
|
-
state.currentUrl = nextUrl;
|
|
110
|
-
state.currentParams = nextParams;
|
|
111
|
-
return 'boolean' == typeof result ? result : void 0;
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
function isRouteObjectPathlessLayout(route) {
|
|
115
|
-
return !route.path && !route.index;
|
|
116
|
-
}
|
|
117
|
-
function isRouteObjectSplatRoute(route) {
|
|
118
|
-
return 'string' == typeof route.path && route.path.includes('*');
|
|
119
|
-
}
|
|
120
|
-
function mapParamsForRouteObjectLoader({ route, params }) {
|
|
121
|
-
if (isRouteObjectSplatRoute(route)) {
|
|
122
|
-
const { _splat, ...rest } = params;
|
|
123
|
-
if (void 0 !== _splat) return {
|
|
124
|
-
...rest,
|
|
125
|
-
'*': _splat
|
|
126
|
-
};
|
|
127
|
-
return rest;
|
|
128
|
-
}
|
|
129
|
-
return params;
|
|
130
|
-
}
|
|
131
|
-
function wrapRouteObjectLoader(route, revalidationState, options = {}) {
|
|
132
|
-
const modernRoute = route;
|
|
133
|
-
const routeLoader = modernRoute.loader;
|
|
134
|
-
if ('function' != typeof routeLoader) return;
|
|
135
|
-
return async (ctx)=>{
|
|
136
|
-
try {
|
|
137
|
-
if (revalidationState) rememberRouteLocation(revalidationState, ctx);
|
|
138
|
-
if ('function' == typeof modernRoute.lazyImport) try {
|
|
139
|
-
await modernRoute.lazyImport();
|
|
140
|
-
} catch {}
|
|
141
|
-
const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
|
|
142
|
-
const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
|
|
143
|
-
const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
|
|
144
|
-
const request = void 0 !== baseRequest ? new Request(baseRequest, {
|
|
145
|
-
signal
|
|
146
|
-
}) : createModernRequest(href, signal);
|
|
147
|
-
const params = mapParamsForRouteObjectLoader({
|
|
148
|
-
route,
|
|
149
|
-
params: ctx.params || {}
|
|
150
|
-
});
|
|
151
|
-
const loadModernData = async ()=>{
|
|
152
|
-
const result = await routeLoader({
|
|
153
|
-
request,
|
|
154
|
-
params,
|
|
155
|
-
context: ctx?.context?.requestContext
|
|
156
|
-
});
|
|
157
|
-
return normalizeModernLoaderResponse(result);
|
|
158
|
-
};
|
|
159
|
-
if (options.rscPayloadRouter && isTanstackRscPayloadNavigationEnabled()) return loadTanstackRscRouteData({
|
|
160
|
-
hasClientLoader: modernRoute.hasClientLoader || void 0 !== modernRoute.clientData,
|
|
161
|
-
loadClientData: loadModernData,
|
|
162
|
-
request,
|
|
163
|
-
routeId: ctx.route?.id
|
|
164
|
-
});
|
|
165
|
-
return loadModernData();
|
|
166
|
-
} catch (err) {
|
|
167
|
-
if (isResponse(err)) {
|
|
168
|
-
if (isTanstackRedirect(err)) throw err;
|
|
169
|
-
if (isRedirectResponse(err)) {
|
|
170
|
-
const location = err.headers.get('Location') || '/';
|
|
171
|
-
throwTanstackRedirect(location);
|
|
172
|
-
}
|
|
173
|
-
if (404 === err.status) throw notFound();
|
|
174
|
-
}
|
|
175
|
-
throw err;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function toRouteComponent(routeObject) {
|
|
180
|
-
const route = routeObject;
|
|
181
|
-
const lazyImport = 'function' == typeof route.lazyImport ? route.lazyImport : void 0;
|
|
182
|
-
const fallbackComponent = route.Component ? route.Component : route.element ? ()=>route.element : void 0;
|
|
183
|
-
if (lazyImport && fallbackComponent) return createServerLazyImportComponent(lazyImport, fallbackComponent);
|
|
184
|
-
if (route.Component) return route.Component;
|
|
185
|
-
const element = route.element;
|
|
186
|
-
if (element) return ()=>element;
|
|
187
|
-
}
|
|
188
|
-
function toErrorComponent(routeObject) {
|
|
189
|
-
const route = routeObject;
|
|
190
|
-
if (route.ErrorBoundary) return route.ErrorBoundary;
|
|
191
|
-
if (route.errorElement) return ()=>route.errorElement;
|
|
192
|
-
}
|
|
193
|
-
function toPendingComponent(routeObject) {
|
|
194
|
-
const route = routeObject;
|
|
195
|
-
return route.HydrateFallback || route.pendingComponent || void 0;
|
|
196
|
-
}
|
|
197
|
-
function mergeModernRouteHandle(route) {
|
|
198
|
-
const config = route.config;
|
|
199
|
-
const handle = {
|
|
200
|
-
...route.handle,
|
|
201
|
-
...config && 'object' == typeof config ? config.handle : {}
|
|
202
|
-
};
|
|
203
|
-
return Object.keys(handle).length > 0 ? handle : void 0;
|
|
204
|
-
}
|
|
205
|
-
function createRouteStaticData(opts) {
|
|
206
|
-
const staticData = {};
|
|
207
|
-
if (opts.modernRouteId) staticData.modernRouteId = opts.modernRouteId;
|
|
208
|
-
if (opts.modernRouteAction) staticData.modernRouteAction = opts.modernRouteAction;
|
|
209
|
-
if (opts.modernRouteHandle) staticData.modernRouteHandle = opts.modernRouteHandle;
|
|
210
|
-
if (opts.modernRouteHasAction) staticData.modernRouteHasAction = true;
|
|
211
|
-
if (opts.modernRouteHasClientLoader) staticData.modernRouteHasClientLoader = true;
|
|
212
|
-
if (opts.modernRouteHasLoader) staticData.modernRouteHasLoader = true;
|
|
213
|
-
if (opts.modernRouteIsClientComponent) staticData.modernRouteIsClientComponent = true;
|
|
214
|
-
if (opts.modernRouteLoader) staticData.modernRouteLoader = opts.modernRouteLoader;
|
|
215
|
-
if (opts.modernRouteShouldRevalidate) staticData.modernRouteShouldRevalidate = opts.modernRouteShouldRevalidate;
|
|
216
|
-
return Object.keys(staticData).length > 0 ? staticData : void 0;
|
|
217
|
-
}
|
|
218
|
-
function createRouteFromRouteObject(opts) {
|
|
219
|
-
const { options = {}, parent, routeObject } = opts;
|
|
220
|
-
const modernRouteObject = routeObject;
|
|
221
|
-
const revalidationState = {};
|
|
222
|
-
const shouldRevalidate = modernRouteObject.shouldRevalidate;
|
|
223
|
-
const shouldReload = createModernShouldReload(shouldRevalidate, revalidationState);
|
|
224
|
-
const stableFallbackId = routeObject.id || modernRouteObject.file || routeObject.path || 'pathless';
|
|
225
|
-
const component = toRouteComponent(routeObject);
|
|
226
|
-
const base = {
|
|
227
|
-
getParentRoute: ()=>parent,
|
|
228
|
-
component,
|
|
229
|
-
pendingComponent: toPendingComponent(routeObject),
|
|
230
|
-
errorComponent: toErrorComponent(routeObject),
|
|
231
|
-
validateSearch: modernRouteObject.validateSearch,
|
|
232
|
-
loaderDeps: modernRouteObject.loaderDeps,
|
|
233
|
-
staticData: createRouteStaticData({
|
|
234
|
-
modernRouteId: routeObject.id,
|
|
235
|
-
modernRouteAction: modernRouteObject.action,
|
|
236
|
-
modernRouteHandle: mergeModernRouteHandle(modernRouteObject),
|
|
237
|
-
modernRouteHasAction: modernRouteObject.hasAction || Boolean(modernRouteObject.action),
|
|
238
|
-
modernRouteHasClientLoader: modernRouteObject.hasClientLoader || void 0 !== modernRouteObject.clientData,
|
|
239
|
-
modernRouteHasLoader: modernRouteObject.hasLoader || 'function' == typeof modernRouteObject.loader,
|
|
240
|
-
modernRouteIsClientComponent: modernRouteObject.isClientComponent,
|
|
241
|
-
modernRouteLoader: modernRouteObject.loader,
|
|
242
|
-
modernRouteShouldRevalidate: shouldRevalidate
|
|
243
|
-
}),
|
|
244
|
-
loader: wrapRouteObjectLoader(routeObject, revalidationState, options)
|
|
245
|
-
};
|
|
246
|
-
if (modernRouteObject.inValidSSRRoute) base.ssr = false;
|
|
247
|
-
if (shouldReload) base.shouldReload = shouldReload;
|
|
248
|
-
if (isRouteObjectPathlessLayout(routeObject)) base.id = stableFallbackId;
|
|
249
|
-
else base.path = routeObject.index ? '/' : toTanstackPath(routeObject.path || '');
|
|
250
|
-
const route = createTanstackRoute(base);
|
|
251
|
-
wrapRouteComponentWithModernContext(route, component, routeObject.id);
|
|
252
|
-
const children = routeObject.children;
|
|
253
|
-
if (children && children.length > 0) {
|
|
254
|
-
const childRoutes = children.map((child)=>createRouteFromRouteObject({
|
|
255
|
-
options,
|
|
256
|
-
parent: route,
|
|
257
|
-
routeObject: child
|
|
258
|
-
}));
|
|
259
|
-
route.addChildren(childRoutes);
|
|
260
|
-
}
|
|
261
|
-
return route;
|
|
262
|
-
}
|
|
263
|
-
function getRootLikeRouteObject(routes) {
|
|
264
|
-
return routes.find((route)=>'/' === route.path && !route.index);
|
|
265
|
-
}
|
|
266
|
-
function createRouteTreeFromRouteObjects(routes, options = {}) {
|
|
267
|
-
const rootLikeRoute = getRootLikeRouteObject(routes);
|
|
268
|
-
const rootRevalidationState = {};
|
|
269
|
-
const rootShouldRevalidate = rootLikeRoute?.shouldRevalidate;
|
|
270
|
-
const rootShouldReload = createModernShouldReload(rootShouldRevalidate, rootRevalidationState);
|
|
271
|
-
const rootComponent = rootLikeRoute ? toRouteComponent(rootLikeRoute) : void 0;
|
|
272
|
-
const rootRouteOptions = {
|
|
273
|
-
component: rootComponent,
|
|
274
|
-
pendingComponent: rootLikeRoute ? toPendingComponent(rootLikeRoute) : void 0,
|
|
275
|
-
errorComponent: rootLikeRoute ? toErrorComponent(rootLikeRoute) : void 0,
|
|
276
|
-
validateSearch: rootLikeRoute?.validateSearch,
|
|
277
|
-
loaderDeps: rootLikeRoute?.loaderDeps,
|
|
278
|
-
notFoundComponent: DefaultNotFound,
|
|
279
|
-
staticData: createRouteStaticData({
|
|
280
|
-
modernRouteId: rootLikeRoute?.id,
|
|
281
|
-
modernRouteAction: rootLikeRoute?.action,
|
|
282
|
-
modernRouteHandle: rootLikeRoute ? mergeModernRouteHandle(rootLikeRoute) : void 0,
|
|
283
|
-
modernRouteHasAction: rootLikeRoute?.hasAction || Boolean(rootLikeRoute?.action),
|
|
284
|
-
modernRouteHasClientLoader: rootLikeRoute?.hasClientLoader || void 0 !== rootLikeRoute?.clientData,
|
|
285
|
-
modernRouteHasLoader: rootLikeRoute?.hasLoader || 'function' == typeof rootLikeRoute?.loader,
|
|
286
|
-
modernRouteIsClientComponent: rootLikeRoute?.isClientComponent,
|
|
287
|
-
modernRouteLoader: rootLikeRoute?.loader,
|
|
288
|
-
modernRouteShouldRevalidate: rootShouldRevalidate
|
|
289
|
-
}),
|
|
290
|
-
loader: rootLikeRoute ? wrapRouteObjectLoader(rootLikeRoute, rootRevalidationState, options) : void 0
|
|
291
|
-
};
|
|
292
|
-
if (rootShouldReload) rootRouteOptions.shouldReload = rootShouldReload;
|
|
293
|
-
if (rootLikeRoute?.inValidSSRRoute) rootRouteOptions.ssr = false;
|
|
294
|
-
const rootRoute = createTanstackRootRoute(rootRouteOptions);
|
|
295
|
-
if (rootComponent) rootRoute.options.component = withModernRouteMatchContext(rootComponent, rootRouteId);
|
|
296
|
-
const topLevel = rootLikeRoute ? [
|
|
297
|
-
...rootLikeRoute.children || [],
|
|
298
|
-
...routes.filter((route)=>route !== rootLikeRoute)
|
|
299
|
-
] : routes;
|
|
300
|
-
const childRoutes = topLevel.map((routeObject)=>createRouteFromRouteObject({
|
|
301
|
-
options,
|
|
302
|
-
parent: rootRoute,
|
|
303
|
-
routeObject
|
|
304
|
-
}));
|
|
305
|
-
rootRoute.addChildren(childRoutes);
|
|
306
|
-
return rootRoute;
|
|
307
|
-
}
|
|
308
|
-
function getModernRouteIdsFromMatches(router) {
|
|
309
|
-
const matches = router.state.matches || [];
|
|
310
|
-
const routesById = router.routesById;
|
|
311
|
-
const ids = matches.map((match)=>{
|
|
312
|
-
const normalizedMatch = match;
|
|
313
|
-
const routeId = 'string' == typeof normalizedMatch.routeId ? normalizedMatch.routeId : void 0;
|
|
314
|
-
return normalizedMatch.route?.options?.staticData?.modernRouteId ?? (routeId ? routesById?.[routeId]?.options?.staticData?.modernRouteId : void 0);
|
|
315
|
-
}).filter((id)=>'string' == typeof id);
|
|
316
|
-
return Array.from(new Set(ids));
|
|
317
|
-
}
|
|
318
|
-
export { createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches };
|
|
1
|
+
export { createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches, pickRouteModuleComponent } from "./routeTree/index.mjs";
|
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Suspense } from "react";
|
|
4
4
|
import { SlotProvider } from "./SlotContext.mjs";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
import { EmptyFallback, renderSelectedTree } from "./shared.mjs";
|
|
6
|
+
import { RSC_PROXY_GET_TREE, SERVER_COMPONENT_STREAM } from "./symbols.mjs";
|
|
7
|
+
import { createTreeGetterFromFlightStream } from "./treeGetter.mjs";
|
|
8
|
+
const rawServerValueGetters = new WeakMap();
|
|
9
|
+
function getRawServerTreeGetter(src) {
|
|
10
|
+
if (!src || 'object' != typeof src && 'function' != typeof src) return;
|
|
11
|
+
const source = src;
|
|
12
|
+
const stream = source[SERVER_COMPONENT_STREAM];
|
|
13
|
+
if ('function' != typeof stream?.createReplayStream) return;
|
|
14
|
+
let getTree = rawServerValueGetters.get(src);
|
|
15
|
+
if (!getTree) {
|
|
16
|
+
getTree = createTreeGetterFromFlightStream(stream.createReplayStream());
|
|
17
|
+
rawServerValueGetters.set(src, getTree);
|
|
14
18
|
}
|
|
15
|
-
return
|
|
19
|
+
return getTree;
|
|
16
20
|
}
|
|
17
21
|
function CompositeInner({ slotProps, src, strict }) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
const tree = renderSelectedTree(src, {
|
|
23
|
+
getTree: src[RSC_PROXY_GET_TREE] || getRawServerTreeGetter(src),
|
|
24
|
+
missingTreeError: 'CompositeComponent src must come from createCompositeComponent().'
|
|
25
|
+
});
|
|
21
26
|
return /*#__PURE__*/ jsx(SlotProvider, {
|
|
22
27
|
implementations: slotProps,
|
|
23
28
|
strict: strict,
|
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Suspense } from "react";
|
|
4
|
-
import {
|
|
5
|
-
function EmptyFallback() {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
function selectTreePath(tree, path) {
|
|
9
|
-
let current = tree;
|
|
10
|
-
for (const key of path){
|
|
11
|
-
if (null === current || 'object' != typeof current) return null;
|
|
12
|
-
current = current[key];
|
|
13
|
-
}
|
|
14
|
-
return current;
|
|
15
|
-
}
|
|
4
|
+
import { EmptyFallback, renderSelectedTree } from "./shared.mjs";
|
|
16
5
|
function RscNodeRenderInner({ data }) {
|
|
17
|
-
const getTree = data[RSC_PROXY_GET_TREE];
|
|
18
|
-
if (!getTree) throw new Error('Renderable RSC is missing its decoded tree getter.');
|
|
19
6
|
return /*#__PURE__*/ jsx(Fragment, {
|
|
20
|
-
children:
|
|
7
|
+
children: renderSelectedTree(data, {
|
|
8
|
+
missingTreeError: 'Renderable RSC is missing its decoded tree getter.'
|
|
9
|
+
})
|
|
21
10
|
});
|
|
22
11
|
}
|
|
23
12
|
function RscNodeRenderer({ data }) {
|
|
@@ -1,40 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { createSerializationAdapter } from "@tanstack/react-router";
|
|
3
|
-
import {
|
|
3
|
+
import { createTreeGetterFromFlightStream } from "./treeGetter.mjs";
|
|
4
4
|
import { createRscProxy } from "./createRscProxy.mjs";
|
|
5
|
-
let modernRscClientRuntimePromise;
|
|
6
|
-
function loadModernRscClientRuntime() {
|
|
7
|
-
modernRscClientRuntimePromise ??= import("@modern-js/runtime/rsc/client").then((runtime)=>{
|
|
8
|
-
runtime.setServerCallback(runtime.callServer);
|
|
9
|
-
return runtime;
|
|
10
|
-
});
|
|
11
|
-
return modernRscClientRuntimePromise;
|
|
12
|
-
}
|
|
13
|
-
function createTreeGetter(stream) {
|
|
14
|
-
let ready = false;
|
|
15
|
-
let tree;
|
|
16
|
-
const treePromise = loadModernRscClientRuntime().then((runtime)=>runtime.createFromReadableStream(stream, {
|
|
17
|
-
callServer: runtime.callServer
|
|
18
|
-
})).then((value)=>{
|
|
19
|
-
tree = value;
|
|
20
|
-
ready = true;
|
|
21
|
-
return value;
|
|
22
|
-
});
|
|
23
|
-
return ()=>{
|
|
24
|
-
if (ready) return tree;
|
|
25
|
-
return use(treePromise);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
5
|
function createFromFlightStream(serialized) {
|
|
29
6
|
const streamWrapper = {
|
|
30
7
|
createReplayStream: ()=>serialized.stream
|
|
31
8
|
};
|
|
32
|
-
return createRscProxy(
|
|
9
|
+
return createRscProxy(createTreeGetterFromFlightStream(serialized.stream), {
|
|
33
10
|
renderable: 'renderable' === serialized.kind,
|
|
34
11
|
slotUsagesStream: serialized.slotUsagesStream,
|
|
35
12
|
stream: streamWrapper
|
|
36
13
|
});
|
|
37
14
|
}
|
|
15
|
+
function createTanstackRscValueFromFlight(serialized) {
|
|
16
|
+
return createFromFlightStream(serialized);
|
|
17
|
+
}
|
|
38
18
|
const adapter = createSerializationAdapter({
|
|
39
19
|
key: '$MODERN_TANSTACK_RSC',
|
|
40
20
|
test: (_value)=>false,
|
|
@@ -50,4 +30,4 @@ function getTanstackRscSerializationAdapters() {
|
|
|
50
30
|
}
|
|
51
31
|
const rscSerializationAdapter = getTanstackRscSerializationAdapters;
|
|
52
32
|
export { CompositeComponent } from "./CompositeComponent.mjs";
|
|
53
|
-
export { getTanstackRscSerializationAdapters, rscSerializationAdapter };
|
|
33
|
+
export { createTanstackRscValueFromFlight, getTanstackRscSerializationAdapters, rscSerializationAdapter };
|