@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.0
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/LICENSE +21 -0
- package/dist/cjs/cli/index.js +268 -0
- package/dist/cjs/cli/tanstackTypes.js +388 -0
- package/dist/cjs/cli.js +65 -0
- package/dist/cjs/runtime/DefaultNotFound.js +47 -0
- package/dist/cjs/runtime/basepathRewrite.js +62 -0
- package/dist/cjs/runtime/dataMutation.js +345 -0
- package/dist/cjs/runtime/hooks.js +57 -0
- package/dist/cjs/runtime/index.js +114 -0
- package/dist/cjs/runtime/lifecycle.js +125 -0
- package/dist/cjs/runtime/plugin.js +250 -0
- package/dist/cjs/runtime/plugin.node.js +304 -0
- package/dist/cjs/runtime/prefetchLink.js +55 -0
- package/dist/cjs/runtime/routeTree.js +492 -0
- package/dist/cjs/runtime/rsc/ClientSlot.js +53 -0
- package/dist/cjs/runtime/rsc/CompositeComponent.js +75 -0
- package/dist/cjs/runtime/rsc/ReplayableStream.js +141 -0
- package/dist/cjs/runtime/rsc/RscNodeRenderer.js +65 -0
- package/dist/cjs/runtime/rsc/SlotContext.js +54 -0
- package/dist/cjs/runtime/rsc/client.js +93 -0
- package/dist/cjs/runtime/rsc/createRscProxy.js +141 -0
- package/dist/cjs/runtime/rsc/index.js +42 -0
- package/dist/cjs/runtime/rsc/payloadRouter.js +211 -0
- package/dist/cjs/runtime/rsc/server.js +246 -0
- package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +65 -0
- package/dist/cjs/runtime/rsc/symbols.js +72 -0
- package/dist/cjs/runtime/types.js +18 -0
- package/dist/cjs/runtime/utils.js +142 -0
- package/dist/cjs/runtime.js +58 -0
- package/dist/esm/cli/index.mjs +201 -0
- package/dist/esm/cli/tanstackTypes.mjs +341 -0
- package/dist/esm/cli.mjs +2 -0
- package/dist/esm/rslib-runtime.mjs +18 -0
- package/dist/esm/runtime/DefaultNotFound.mjs +13 -0
- package/dist/esm/runtime/basepathRewrite.mjs +28 -0
- package/dist/esm/runtime/dataMutation.mjs +305 -0
- package/dist/esm/runtime/hooks.mjs +8 -0
- package/dist/esm/runtime/index.mjs +6 -0
- package/dist/esm/runtime/lifecycle.mjs +82 -0
- package/dist/esm/runtime/plugin.mjs +214 -0
- package/dist/esm/runtime/plugin.node.mjs +268 -0
- package/dist/esm/runtime/prefetchLink.mjs +18 -0
- package/dist/esm/runtime/routeTree.mjs +452 -0
- package/dist/esm/runtime/rsc/ClientSlot.mjs +19 -0
- package/dist/esm/runtime/rsc/CompositeComponent.mjs +41 -0
- package/dist/esm/runtime/rsc/ReplayableStream.mjs +104 -0
- package/dist/esm/runtime/rsc/RscNodeRenderer.mjs +31 -0
- package/dist/esm/runtime/rsc/SlotContext.mjs +17 -0
- package/dist/esm/runtime/rsc/client.mjs +53 -0
- package/dist/esm/runtime/rsc/createRscProxy.mjs +107 -0
- package/dist/esm/runtime/rsc/index.mjs +1 -0
- package/dist/esm/runtime/rsc/payloadRouter.mjs +162 -0
- package/dist/esm/runtime/rsc/server.mjs +200 -0
- package/dist/esm/runtime/rsc/slotUsageSanitizer.mjs +31 -0
- package/dist/esm/runtime/rsc/symbols.mjs +17 -0
- package/dist/esm/runtime/types.mjs +0 -0
- package/dist/esm/runtime/utils.mjs +89 -0
- package/dist/esm/runtime.mjs +1 -0
- package/dist/esm-node/cli/index.mjs +205 -0
- package/dist/esm-node/cli/tanstackTypes.mjs +342 -0
- package/dist/esm-node/cli.mjs +3 -0
- package/dist/esm-node/rslib-runtime.mjs +19 -0
- package/dist/esm-node/runtime/DefaultNotFound.mjs +14 -0
- package/dist/esm-node/runtime/basepathRewrite.mjs +29 -0
- package/dist/esm-node/runtime/dataMutation.mjs +306 -0
- package/dist/esm-node/runtime/hooks.mjs +9 -0
- package/dist/esm-node/runtime/index.mjs +7 -0
- package/dist/esm-node/runtime/lifecycle.mjs +83 -0
- package/dist/esm-node/runtime/plugin.mjs +215 -0
- package/dist/esm-node/runtime/plugin.node.mjs +269 -0
- package/dist/esm-node/runtime/prefetchLink.mjs +19 -0
- package/dist/esm-node/runtime/routeTree.mjs +453 -0
- package/dist/esm-node/runtime/rsc/ClientSlot.mjs +20 -0
- package/dist/esm-node/runtime/rsc/CompositeComponent.mjs +42 -0
- package/dist/esm-node/runtime/rsc/ReplayableStream.mjs +105 -0
- package/dist/esm-node/runtime/rsc/RscNodeRenderer.mjs +32 -0
- package/dist/esm-node/runtime/rsc/SlotContext.mjs +18 -0
- package/dist/esm-node/runtime/rsc/client.mjs +54 -0
- package/dist/esm-node/runtime/rsc/createRscProxy.mjs +108 -0
- package/dist/esm-node/runtime/rsc/index.mjs +2 -0
- package/dist/esm-node/runtime/rsc/payloadRouter.mjs +163 -0
- package/dist/esm-node/runtime/rsc/server.mjs +201 -0
- package/dist/esm-node/runtime/rsc/slotUsageSanitizer.mjs +32 -0
- package/dist/esm-node/runtime/rsc/symbols.mjs +18 -0
- package/dist/esm-node/runtime/types.mjs +1 -0
- package/dist/esm-node/runtime/utils.mjs +90 -0
- package/dist/esm-node/runtime.mjs +2 -0
- package/dist/types/cli/index.d.ts +20 -0
- package/dist/types/cli/tanstackTypes.d.ts +11 -0
- package/dist/types/cli.d.ts +2 -0
- package/dist/types/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types/runtime/basepathRewrite.d.ts +8 -0
- package/dist/types/runtime/dataMutation.d.ts +29 -0
- package/dist/types/runtime/hooks.d.ts +18 -0
- package/dist/types/runtime/index.d.ts +9 -0
- package/dist/types/runtime/lifecycle.d.ts +22 -0
- package/dist/types/runtime/plugin.d.ts +17 -0
- package/dist/types/runtime/plugin.node.d.ts +17 -0
- package/dist/types/runtime/prefetchLink.d.ts +11 -0
- package/dist/types/runtime/routeTree.d.ts +11 -0
- package/dist/types/runtime/rsc/ClientSlot.d.ts +5 -0
- package/dist/types/runtime/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types/runtime/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types/runtime/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types/runtime/rsc/SlotContext.d.ts +11 -0
- package/dist/types/runtime/rsc/client.d.ts +11 -0
- package/dist/types/runtime/rsc/createRscProxy.d.ts +7 -0
- package/dist/types/runtime/rsc/index.d.ts +2 -0
- package/dist/types/runtime/rsc/payloadRouter.d.ts +24 -0
- package/dist/types/runtime/rsc/server.d.ts +14 -0
- package/dist/types/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types/runtime/rsc/symbols.d.ts +46 -0
- package/dist/types/runtime/types.d.ts +68 -0
- package/dist/types/runtime/utils.d.ts +36 -0
- package/dist/types/runtime.d.ts +1 -0
- package/dist/types-direct/cli/index.d.ts +20 -0
- package/dist/types-direct/cli/tanstackTypes.d.ts +11 -0
- package/dist/types-direct/cli.d.ts +2 -0
- package/dist/types-direct/runtime/DefaultNotFound.d.ts +2 -0
- package/dist/types-direct/runtime/basepathRewrite.d.ts +8 -0
- package/dist/types-direct/runtime/dataMutation.d.ts +29 -0
- package/dist/types-direct/runtime/hooks.d.ts +18 -0
- package/dist/types-direct/runtime/index.d.ts +9 -0
- package/dist/types-direct/runtime/lifecycle.d.ts +22 -0
- package/dist/types-direct/runtime/plugin.d.ts +17 -0
- package/dist/types-direct/runtime/plugin.node.d.ts +17 -0
- package/dist/types-direct/runtime/prefetchLink.d.ts +11 -0
- package/dist/types-direct/runtime/routeTree.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/ClientSlot.d.ts +5 -0
- package/dist/types-direct/runtime/rsc/CompositeComponent.d.ts +3 -0
- package/dist/types-direct/runtime/rsc/ReplayableStream.d.ts +24 -0
- package/dist/types-direct/runtime/rsc/RscNodeRenderer.d.ts +5 -0
- package/dist/types-direct/runtime/rsc/SlotContext.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/client.d.ts +11 -0
- package/dist/types-direct/runtime/rsc/createRscProxy.d.ts +7 -0
- package/dist/types-direct/runtime/rsc/index.d.ts +2 -0
- package/dist/types-direct/runtime/rsc/payloadRouter.d.ts +24 -0
- package/dist/types-direct/runtime/rsc/server.d.ts +14 -0
- package/dist/types-direct/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
- package/dist/types-direct/runtime/rsc/symbols.d.ts +46 -0
- package/dist/types-direct/runtime/types.d.ts +68 -0
- package/dist/types-direct/runtime/utils.d.ts +36 -0
- package/dist/types-direct/runtime.d.ts +1 -0
- package/package.json +126 -0
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +43 -0
- package/src/cli/index.ts +388 -0
- package/src/cli/tanstackTypes.ts +503 -0
- package/src/cli.ts +2 -0
- package/src/runtime/DefaultNotFound.tsx +15 -0
- package/src/runtime/basepathRewrite.ts +59 -0
- package/src/runtime/dataMutation.tsx +517 -0
- package/src/runtime/hooks.ts +34 -0
- package/src/runtime/index.tsx +30 -0
- package/src/runtime/lifecycle.ts +150 -0
- package/src/runtime/plugin.node.tsx +534 -0
- package/src/runtime/plugin.tsx +395 -0
- package/src/runtime/prefetchLink.tsx +87 -0
- package/src/runtime/routeTree.ts +942 -0
- package/src/runtime/rsc/ClientSlot.tsx +25 -0
- package/src/runtime/rsc/CompositeComponent.tsx +65 -0
- package/src/runtime/rsc/ReplayableStream.ts +155 -0
- package/src/runtime/rsc/RscNodeRenderer.tsx +45 -0
- package/src/runtime/rsc/SlotContext.tsx +31 -0
- package/src/runtime/rsc/client.tsx +90 -0
- package/src/runtime/rsc/createRscProxy.tsx +189 -0
- package/src/runtime/rsc/index.ts +10 -0
- package/src/runtime/rsc/payloadRouter.ts +318 -0
- package/src/runtime/rsc/server.tsx +303 -0
- package/src/runtime/rsc/slotUsageSanitizer.ts +76 -0
- package/src/runtime/rsc/symbols.ts +106 -0
- package/src/runtime/ssr-shim.d.ts +12 -0
- package/src/runtime/types.ts +83 -0
- package/src/runtime/utils.tsx +161 -0
- package/src/runtime.ts +1 -0
- package/tests/router/cli.test.ts +386 -0
- package/tests/router/dataMutation.test.tsx +396 -0
- package/tests/router/prefetchLink.test.tsx +43 -0
- package/tests/router/routeTree.test.ts +502 -0
- package/tests/router/rsc.test.tsx +256 -0
- package/tests/router/tanstackTypes.test.ts +62 -0
- package/tsconfig.json +12 -0
- package/tsconfig.tsgo.json +6 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { InternalRuntimeContext, getGlobalEnableRsc, getGlobalLayoutApp, getGlobalRoutes } from "@modern-js/runtime/context";
|
|
4
|
+
import { merge } from "@modern-js/runtime-utils/merge";
|
|
5
|
+
import { createRequestContext, storage } from "@modern-js/runtime-utils/node";
|
|
6
|
+
import { time } from "@modern-js/runtime-utils/time";
|
|
7
|
+
import { LOADER_REPORTER_NAME } from "@modern-js/utils/universal/constants";
|
|
8
|
+
import { RouterProvider, createMemoryHistory, createRouter } from "@tanstack/react-router";
|
|
9
|
+
import { attachRouterServerSsrUtils } from "@tanstack/react-router/ssr/server";
|
|
10
|
+
import { Suspense, useContext } from "react";
|
|
11
|
+
import { createModernBasepathRewrite } from "./basepathRewrite.mjs";
|
|
12
|
+
import { modifyRoutes, onAfterCreateRouter, onAfterHydrateRouter, onBeforeCreateRouter, onBeforeCreateRoutes, onBeforeHydrateRouter } from "./hooks.mjs";
|
|
13
|
+
import { applyRouterServerPrepareResult, createRouterServerSnapshot } from "./lifecycle.mjs";
|
|
14
|
+
import { createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches } from "./routeTree.mjs";
|
|
15
|
+
import { createTanstackRscServerPayload, handleTanstackRscRedirect } from "./rsc/payloadRouter.mjs";
|
|
16
|
+
import { createRouteObjectsFromConfig, urlJoin } from "./utils.mjs";
|
|
17
|
+
const setTanstackRscServerPayload = (payload)=>{
|
|
18
|
+
const storageContext = storage.useContext?.();
|
|
19
|
+
if (storageContext) storageContext.serverPayload = payload;
|
|
20
|
+
};
|
|
21
|
+
function isPreloadableRouteComponent(component) {
|
|
22
|
+
if (!component || 'function' != typeof component) return false;
|
|
23
|
+
const preloadable = component;
|
|
24
|
+
return 'function' == typeof preloadable.load || 'function' == typeof preloadable.preload;
|
|
25
|
+
}
|
|
26
|
+
async function preloadRouteComponent(component) {
|
|
27
|
+
if (!isPreloadableRouteComponent(component)) return;
|
|
28
|
+
if ('function' == typeof component.load) return void await component.load({});
|
|
29
|
+
await component.preload?.({});
|
|
30
|
+
}
|
|
31
|
+
async function preloadMatchedRouteComponents(tanstackRouter) {
|
|
32
|
+
const matches = Array.isArray(tanstackRouter.state.matches) ? tanstackRouter.state.matches : [];
|
|
33
|
+
const routesById = tanstackRouter.routesById || {};
|
|
34
|
+
await Promise.all(matches.map(async (match)=>{
|
|
35
|
+
const routeId = 'string' == typeof match.routeId ? match.routeId : 'string' == typeof match.route?.id ? match.route.id : void 0;
|
|
36
|
+
const route = routeId ? routesById[routeId] : match.route;
|
|
37
|
+
const options = route?.options;
|
|
38
|
+
if (!options) return;
|
|
39
|
+
await Promise.all([
|
|
40
|
+
preloadRouteComponent(options.component),
|
|
41
|
+
preloadRouteComponent(options.pendingComponent),
|
|
42
|
+
preloadRouteComponent(options.errorComponent),
|
|
43
|
+
preloadRouteComponent(options.notFoundComponent)
|
|
44
|
+
]);
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
async function waitForRouterSerialization(tanstackRouter) {
|
|
48
|
+
const serverSsr = tanstackRouter.serverSsr;
|
|
49
|
+
if (!serverSsr || 'function' != typeof serverSsr.onSerializationFinished || serverSsr.isSerializationFinished?.()) return;
|
|
50
|
+
await new Promise((resolve)=>{
|
|
51
|
+
serverSsr.onSerializationFinished?.(resolve);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function htmlEscapeAttr(value) {
|
|
55
|
+
return value.replace(/&/g, '&').replace(/"/g, '"');
|
|
56
|
+
}
|
|
57
|
+
function routerManagedTagToHtml(tag) {
|
|
58
|
+
if (!tag || 'object' != typeof tag) return '';
|
|
59
|
+
const managedTag = tag;
|
|
60
|
+
if (!managedTag || "script" !== managedTag.tag) return '';
|
|
61
|
+
const attrs = managedTag.attrs || {};
|
|
62
|
+
const attrsStr = Object.entries(attrs).filter(([, v])=>null != v && false !== v).map(([k, v])=>{
|
|
63
|
+
const name = 'className' === k ? 'class' : k;
|
|
64
|
+
if (true === v) return name;
|
|
65
|
+
return `${name}="${htmlEscapeAttr(String(v))}"`;
|
|
66
|
+
}).join(' ');
|
|
67
|
+
const open = attrsStr.length ? `<script ${attrsStr}>` : "<script>";
|
|
68
|
+
const children = 'string' == typeof managedTag.children ? managedTag.children : '';
|
|
69
|
+
return `${open}${children}</script>`;
|
|
70
|
+
}
|
|
71
|
+
function routerManagedTagsToHtml(tags) {
|
|
72
|
+
const normalizedTags = Array.isArray(tags) ? tags : [
|
|
73
|
+
tags
|
|
74
|
+
];
|
|
75
|
+
return normalizedTags.map(routerManagedTagToHtml).filter(Boolean);
|
|
76
|
+
}
|
|
77
|
+
function createGetSsrHref(request) {
|
|
78
|
+
const url = new URL(request.url);
|
|
79
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
80
|
+
}
|
|
81
|
+
function stripSyntheticNotFoundRoute(routes) {
|
|
82
|
+
return routes.filter((route)=>!('*' === route.path && !route.id && !route.loader)).map((route)=>{
|
|
83
|
+
if (!route.children?.length) return route;
|
|
84
|
+
return {
|
|
85
|
+
...route,
|
|
86
|
+
children: stripSyntheticNotFoundRoute(route.children)
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function collectRouterErrors(tanstackRouter) {
|
|
91
|
+
const state = tanstackRouter.state;
|
|
92
|
+
const matches = Array.isArray(state.matches) ? state.matches : [];
|
|
93
|
+
const errors = matches.reduce((acc, match)=>{
|
|
94
|
+
if (!match.error) return acc;
|
|
95
|
+
const routeId = 'string' == typeof match.routeId ? match.routeId : 'string' == typeof match.route?.id ? match.route.id : `match-${Object.keys(acc).length}`;
|
|
96
|
+
acc[routeId] = match.error;
|
|
97
|
+
return acc;
|
|
98
|
+
}, {});
|
|
99
|
+
return Object.keys(errors).length > 0 ? errors : void 0;
|
|
100
|
+
}
|
|
101
|
+
const tanstackRouterPlugin = (userConfig = {})=>{
|
|
102
|
+
const plugin = {
|
|
103
|
+
name: '@modern-js/plugin-router-tanstack',
|
|
104
|
+
registryHooks: {
|
|
105
|
+
modifyRoutes: modifyRoutes,
|
|
106
|
+
onAfterCreateRouter: onAfterCreateRouter,
|
|
107
|
+
onAfterHydrateRouter: onAfterHydrateRouter,
|
|
108
|
+
onBeforeCreateRouter: onBeforeCreateRouter,
|
|
109
|
+
onBeforeCreateRoutes: onBeforeCreateRoutes,
|
|
110
|
+
onBeforeHydrateRouter: onBeforeHydrateRouter
|
|
111
|
+
},
|
|
112
|
+
setup: (api)=>{
|
|
113
|
+
api.onBeforeRender(async (context, interrupt)=>{
|
|
114
|
+
const pluginConfig = api.getRuntimeConfig();
|
|
115
|
+
const mergedConfig = merge(pluginConfig.router || {}, userConfig);
|
|
116
|
+
const serializationAdapters = getGlobalEnableRsc() ? (await import("./rsc/server.mjs")).getTanstackRscSerializationAdapters() : void 0;
|
|
117
|
+
const enableRsc = getGlobalEnableRsc();
|
|
118
|
+
const { basename = '', routesConfig, createRoutes } = mergedConfig;
|
|
119
|
+
const finalRouteConfig = {
|
|
120
|
+
routes: getGlobalRoutes(),
|
|
121
|
+
globalApp: getGlobalLayoutApp(),
|
|
122
|
+
...routesConfig
|
|
123
|
+
};
|
|
124
|
+
if (!finalRouteConfig.routes && !createRoutes) return;
|
|
125
|
+
const hooks = api.getHooks();
|
|
126
|
+
await hooks.onBeforeCreateRoutes.call(context);
|
|
127
|
+
const routeObjects = createRoutes ? createRoutes() : createRouteObjectsFromConfig({
|
|
128
|
+
routesConfig: finalRouteConfig,
|
|
129
|
+
ssrMode: context.ssrContext?.mode
|
|
130
|
+
}) || [];
|
|
131
|
+
const normalizedRouteObjects = createRoutes ? routeObjects : stripSyntheticNotFoundRoute(routeObjects);
|
|
132
|
+
const modifiedRouteObjects = hooks.modifyRoutes.call(normalizedRouteObjects);
|
|
133
|
+
if (!modifiedRouteObjects.length) return;
|
|
134
|
+
const { request, nonce, baseUrl, loaderFailureMode = 'errorBoundary' } = context.ssrContext;
|
|
135
|
+
const _basename = '/' === baseUrl ? urlJoin(baseUrl, basename || '') : baseUrl;
|
|
136
|
+
const initialHref = createGetSsrHref(request.raw);
|
|
137
|
+
const isRSCNavigation = enableRsc && 'true' === request.raw.headers.get('x-rsc-tree');
|
|
138
|
+
const requestContext = createRequestContext(context.ssrContext?.loaderContext);
|
|
139
|
+
const controller = new AbortController();
|
|
140
|
+
const ssrRequest = new Request(request.raw.url, {
|
|
141
|
+
method: 'GET',
|
|
142
|
+
headers: request.raw.headers,
|
|
143
|
+
signal: controller.signal
|
|
144
|
+
});
|
|
145
|
+
const routerContext = {
|
|
146
|
+
request: ssrRequest,
|
|
147
|
+
requestContext
|
|
148
|
+
};
|
|
149
|
+
const routeTree = createRouteTreeFromRouteObjects(modifiedRouteObjects);
|
|
150
|
+
const history = createMemoryHistory({
|
|
151
|
+
initialEntries: [
|
|
152
|
+
initialHref
|
|
153
|
+
]
|
|
154
|
+
});
|
|
155
|
+
const rewrite = createModernBasepathRewrite(_basename);
|
|
156
|
+
const routerLifecycleContext = {
|
|
157
|
+
framework: 'tanstack',
|
|
158
|
+
phase: 'ssr-prepare',
|
|
159
|
+
routes: modifiedRouteObjects,
|
|
160
|
+
runtimeContext: context,
|
|
161
|
+
basename: _basename
|
|
162
|
+
};
|
|
163
|
+
hooks.onBeforeCreateRouter.call(routerLifecycleContext);
|
|
164
|
+
const tanstackRouter = createRouter({
|
|
165
|
+
routeTree,
|
|
166
|
+
history,
|
|
167
|
+
basepath: '/',
|
|
168
|
+
rewrite,
|
|
169
|
+
origin: new URL(request.raw.url).origin,
|
|
170
|
+
ssr: {
|
|
171
|
+
nonce
|
|
172
|
+
},
|
|
173
|
+
context: routerContext,
|
|
174
|
+
...serializationAdapters ? {
|
|
175
|
+
serializationAdapters
|
|
176
|
+
} : {}
|
|
177
|
+
});
|
|
178
|
+
const serverRouter = tanstackRouter;
|
|
179
|
+
attachRouterServerSsrUtils({
|
|
180
|
+
router: serverRouter,
|
|
181
|
+
manifest: void 0
|
|
182
|
+
});
|
|
183
|
+
const end = time();
|
|
184
|
+
try {
|
|
185
|
+
await tanstackRouter.load({
|
|
186
|
+
sync: true
|
|
187
|
+
});
|
|
188
|
+
} finally{
|
|
189
|
+
const cost = end();
|
|
190
|
+
context.ssrContext?.onTiming?.(LOADER_REPORTER_NAME, cost);
|
|
191
|
+
}
|
|
192
|
+
if (serverRouter.state.redirect) {
|
|
193
|
+
const resolved = serverRouter.resolveRedirect ? serverRouter.resolveRedirect(serverRouter.state.redirect) : serverRouter.state.redirect;
|
|
194
|
+
try {
|
|
195
|
+
serverRouter.serverSsr?.cleanup?.();
|
|
196
|
+
} catch {}
|
|
197
|
+
return interrupt(isRSCNavigation ? handleTanstackRscRedirect(resolved.headers, _basename, resolved.status) : resolved);
|
|
198
|
+
}
|
|
199
|
+
const routerErrors = collectRouterErrors(tanstackRouter);
|
|
200
|
+
if (routerErrors && 'clientRender' === loaderFailureMode) {
|
|
201
|
+
context.ssrContext?.response.status(200);
|
|
202
|
+
try {
|
|
203
|
+
serverRouter.serverSsr?.cleanup?.();
|
|
204
|
+
} catch {}
|
|
205
|
+
throw Object.values(routerErrors)[0];
|
|
206
|
+
}
|
|
207
|
+
await preloadMatchedRouteComponents(serverRouter);
|
|
208
|
+
context.ssrContext?.response.status(tanstackRouter.state.statusCode);
|
|
209
|
+
await serverRouter.serverSsr?.dehydrate?.();
|
|
210
|
+
await waitForRouterSerialization(serverRouter);
|
|
211
|
+
if (isRSCNavigation) setTanstackRscServerPayload(createTanstackRscServerPayload(serverRouter, {
|
|
212
|
+
omitClientLoaderData: true
|
|
213
|
+
}));
|
|
214
|
+
const ssrScriptTags = serverRouter.serverSsr?.takeBufferedScripts?.();
|
|
215
|
+
const hydrationScripts = routerManagedTagsToHtml(ssrScriptTags);
|
|
216
|
+
const matchedRouteIds = getModernRouteIdsFromMatches(serverRouter);
|
|
217
|
+
const routerServerSnapshot = createRouterServerSnapshot({
|
|
218
|
+
framework: 'tanstack',
|
|
219
|
+
basename: _basename,
|
|
220
|
+
statusCode: tanstackRouter.state.statusCode,
|
|
221
|
+
errors: routerErrors,
|
|
222
|
+
matchedRouteIds,
|
|
223
|
+
hydrationScripts
|
|
224
|
+
});
|
|
225
|
+
const runtimeContext = applyRouterServerPrepareResult(context, {
|
|
226
|
+
snapshot: routerServerSnapshot,
|
|
227
|
+
cleanup: ()=>serverRouter.serverSsr?.cleanup?.(),
|
|
228
|
+
state: {
|
|
229
|
+
framework: 'tanstack',
|
|
230
|
+
basename: _basename,
|
|
231
|
+
instance: serverRouter,
|
|
232
|
+
hydrationScripts,
|
|
233
|
+
matchedRouteIds,
|
|
234
|
+
serverSnapshot: routerServerSnapshot
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
hooks.onAfterCreateRouter.call({
|
|
238
|
+
...routerLifecycleContext,
|
|
239
|
+
router: serverRouter,
|
|
240
|
+
serverSnapshot: routerServerSnapshot,
|
|
241
|
+
runtimeContext
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
api.wrapRoot((App)=>{
|
|
245
|
+
const getRouteApp = ()=>(props)=>{
|
|
246
|
+
const context = useContext(InternalRuntimeContext);
|
|
247
|
+
const router = context.routerInstance ?? context.routerRuntime?.instance;
|
|
248
|
+
if (!router) return App ? /*#__PURE__*/ jsx(App, {
|
|
249
|
+
...props
|
|
250
|
+
}) : null;
|
|
251
|
+
const routerWrapper = /*#__PURE__*/ jsx(Suspense, {
|
|
252
|
+
fallback: null,
|
|
253
|
+
children: /*#__PURE__*/ jsx(RouterProvider, {
|
|
254
|
+
router: router
|
|
255
|
+
})
|
|
256
|
+
});
|
|
257
|
+
return App ? /*#__PURE__*/ jsx(App, {
|
|
258
|
+
children: routerWrapper
|
|
259
|
+
}) : routerWrapper;
|
|
260
|
+
};
|
|
261
|
+
return getRouteApp();
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
return plugin;
|
|
266
|
+
};
|
|
267
|
+
const plugin_node = tanstackRouterPlugin;
|
|
268
|
+
export default plugin_node;
|
|
269
|
+
export { tanstackRouterPlugin };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Link } from "@tanstack/react-router";
|
|
4
|
+
function resolvePreloadFromPrefetch(prefetch, preload) {
|
|
5
|
+
if (void 0 !== preload) return preload;
|
|
6
|
+
if ('none' === prefetch) return false;
|
|
7
|
+
if ('intent' === prefetch || 'render' === prefetch || 'viewport' === prefetch) return prefetch;
|
|
8
|
+
return preload;
|
|
9
|
+
}
|
|
10
|
+
const LinkComponentImpl = (props)=>{
|
|
11
|
+
const { prefetch, preload, ...rest } = props;
|
|
12
|
+
return /*#__PURE__*/ jsx(Link, {
|
|
13
|
+
...rest,
|
|
14
|
+
preload: resolvePreloadFromPrefetch(prefetch, preload)
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
const prefetchLink_Link = LinkComponentImpl;
|
|
18
|
+
const NavLink = LinkComponentImpl;
|
|
19
|
+
export { NavLink, prefetchLink_Link as Link };
|