@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.
Files changed (183) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/cli/index.js +268 -0
  3. package/dist/cjs/cli/tanstackTypes.js +388 -0
  4. package/dist/cjs/cli.js +65 -0
  5. package/dist/cjs/runtime/DefaultNotFound.js +47 -0
  6. package/dist/cjs/runtime/basepathRewrite.js +62 -0
  7. package/dist/cjs/runtime/dataMutation.js +345 -0
  8. package/dist/cjs/runtime/hooks.js +57 -0
  9. package/dist/cjs/runtime/index.js +114 -0
  10. package/dist/cjs/runtime/lifecycle.js +125 -0
  11. package/dist/cjs/runtime/plugin.js +250 -0
  12. package/dist/cjs/runtime/plugin.node.js +304 -0
  13. package/dist/cjs/runtime/prefetchLink.js +55 -0
  14. package/dist/cjs/runtime/routeTree.js +492 -0
  15. package/dist/cjs/runtime/rsc/ClientSlot.js +53 -0
  16. package/dist/cjs/runtime/rsc/CompositeComponent.js +75 -0
  17. package/dist/cjs/runtime/rsc/ReplayableStream.js +141 -0
  18. package/dist/cjs/runtime/rsc/RscNodeRenderer.js +65 -0
  19. package/dist/cjs/runtime/rsc/SlotContext.js +54 -0
  20. package/dist/cjs/runtime/rsc/client.js +93 -0
  21. package/dist/cjs/runtime/rsc/createRscProxy.js +141 -0
  22. package/dist/cjs/runtime/rsc/index.js +42 -0
  23. package/dist/cjs/runtime/rsc/payloadRouter.js +211 -0
  24. package/dist/cjs/runtime/rsc/server.js +246 -0
  25. package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +65 -0
  26. package/dist/cjs/runtime/rsc/symbols.js +72 -0
  27. package/dist/cjs/runtime/types.js +18 -0
  28. package/dist/cjs/runtime/utils.js +142 -0
  29. package/dist/cjs/runtime.js +58 -0
  30. package/dist/esm/cli/index.mjs +201 -0
  31. package/dist/esm/cli/tanstackTypes.mjs +341 -0
  32. package/dist/esm/cli.mjs +2 -0
  33. package/dist/esm/rslib-runtime.mjs +18 -0
  34. package/dist/esm/runtime/DefaultNotFound.mjs +13 -0
  35. package/dist/esm/runtime/basepathRewrite.mjs +28 -0
  36. package/dist/esm/runtime/dataMutation.mjs +305 -0
  37. package/dist/esm/runtime/hooks.mjs +8 -0
  38. package/dist/esm/runtime/index.mjs +6 -0
  39. package/dist/esm/runtime/lifecycle.mjs +82 -0
  40. package/dist/esm/runtime/plugin.mjs +214 -0
  41. package/dist/esm/runtime/plugin.node.mjs +268 -0
  42. package/dist/esm/runtime/prefetchLink.mjs +18 -0
  43. package/dist/esm/runtime/routeTree.mjs +452 -0
  44. package/dist/esm/runtime/rsc/ClientSlot.mjs +19 -0
  45. package/dist/esm/runtime/rsc/CompositeComponent.mjs +41 -0
  46. package/dist/esm/runtime/rsc/ReplayableStream.mjs +104 -0
  47. package/dist/esm/runtime/rsc/RscNodeRenderer.mjs +31 -0
  48. package/dist/esm/runtime/rsc/SlotContext.mjs +17 -0
  49. package/dist/esm/runtime/rsc/client.mjs +53 -0
  50. package/dist/esm/runtime/rsc/createRscProxy.mjs +107 -0
  51. package/dist/esm/runtime/rsc/index.mjs +1 -0
  52. package/dist/esm/runtime/rsc/payloadRouter.mjs +162 -0
  53. package/dist/esm/runtime/rsc/server.mjs +200 -0
  54. package/dist/esm/runtime/rsc/slotUsageSanitizer.mjs +31 -0
  55. package/dist/esm/runtime/rsc/symbols.mjs +17 -0
  56. package/dist/esm/runtime/types.mjs +0 -0
  57. package/dist/esm/runtime/utils.mjs +89 -0
  58. package/dist/esm/runtime.mjs +1 -0
  59. package/dist/esm-node/cli/index.mjs +205 -0
  60. package/dist/esm-node/cli/tanstackTypes.mjs +342 -0
  61. package/dist/esm-node/cli.mjs +3 -0
  62. package/dist/esm-node/rslib-runtime.mjs +19 -0
  63. package/dist/esm-node/runtime/DefaultNotFound.mjs +14 -0
  64. package/dist/esm-node/runtime/basepathRewrite.mjs +29 -0
  65. package/dist/esm-node/runtime/dataMutation.mjs +306 -0
  66. package/dist/esm-node/runtime/hooks.mjs +9 -0
  67. package/dist/esm-node/runtime/index.mjs +7 -0
  68. package/dist/esm-node/runtime/lifecycle.mjs +83 -0
  69. package/dist/esm-node/runtime/plugin.mjs +215 -0
  70. package/dist/esm-node/runtime/plugin.node.mjs +269 -0
  71. package/dist/esm-node/runtime/prefetchLink.mjs +19 -0
  72. package/dist/esm-node/runtime/routeTree.mjs +453 -0
  73. package/dist/esm-node/runtime/rsc/ClientSlot.mjs +20 -0
  74. package/dist/esm-node/runtime/rsc/CompositeComponent.mjs +42 -0
  75. package/dist/esm-node/runtime/rsc/ReplayableStream.mjs +105 -0
  76. package/dist/esm-node/runtime/rsc/RscNodeRenderer.mjs +32 -0
  77. package/dist/esm-node/runtime/rsc/SlotContext.mjs +18 -0
  78. package/dist/esm-node/runtime/rsc/client.mjs +54 -0
  79. package/dist/esm-node/runtime/rsc/createRscProxy.mjs +108 -0
  80. package/dist/esm-node/runtime/rsc/index.mjs +2 -0
  81. package/dist/esm-node/runtime/rsc/payloadRouter.mjs +163 -0
  82. package/dist/esm-node/runtime/rsc/server.mjs +201 -0
  83. package/dist/esm-node/runtime/rsc/slotUsageSanitizer.mjs +32 -0
  84. package/dist/esm-node/runtime/rsc/symbols.mjs +18 -0
  85. package/dist/esm-node/runtime/types.mjs +1 -0
  86. package/dist/esm-node/runtime/utils.mjs +90 -0
  87. package/dist/esm-node/runtime.mjs +2 -0
  88. package/dist/types/cli/index.d.ts +20 -0
  89. package/dist/types/cli/tanstackTypes.d.ts +11 -0
  90. package/dist/types/cli.d.ts +2 -0
  91. package/dist/types/runtime/DefaultNotFound.d.ts +2 -0
  92. package/dist/types/runtime/basepathRewrite.d.ts +8 -0
  93. package/dist/types/runtime/dataMutation.d.ts +29 -0
  94. package/dist/types/runtime/hooks.d.ts +18 -0
  95. package/dist/types/runtime/index.d.ts +9 -0
  96. package/dist/types/runtime/lifecycle.d.ts +22 -0
  97. package/dist/types/runtime/plugin.d.ts +17 -0
  98. package/dist/types/runtime/plugin.node.d.ts +17 -0
  99. package/dist/types/runtime/prefetchLink.d.ts +11 -0
  100. package/dist/types/runtime/routeTree.d.ts +11 -0
  101. package/dist/types/runtime/rsc/ClientSlot.d.ts +5 -0
  102. package/dist/types/runtime/rsc/CompositeComponent.d.ts +3 -0
  103. package/dist/types/runtime/rsc/ReplayableStream.d.ts +24 -0
  104. package/dist/types/runtime/rsc/RscNodeRenderer.d.ts +5 -0
  105. package/dist/types/runtime/rsc/SlotContext.d.ts +11 -0
  106. package/dist/types/runtime/rsc/client.d.ts +11 -0
  107. package/dist/types/runtime/rsc/createRscProxy.d.ts +7 -0
  108. package/dist/types/runtime/rsc/index.d.ts +2 -0
  109. package/dist/types/runtime/rsc/payloadRouter.d.ts +24 -0
  110. package/dist/types/runtime/rsc/server.d.ts +14 -0
  111. package/dist/types/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
  112. package/dist/types/runtime/rsc/symbols.d.ts +46 -0
  113. package/dist/types/runtime/types.d.ts +68 -0
  114. package/dist/types/runtime/utils.d.ts +36 -0
  115. package/dist/types/runtime.d.ts +1 -0
  116. package/dist/types-direct/cli/index.d.ts +20 -0
  117. package/dist/types-direct/cli/tanstackTypes.d.ts +11 -0
  118. package/dist/types-direct/cli.d.ts +2 -0
  119. package/dist/types-direct/runtime/DefaultNotFound.d.ts +2 -0
  120. package/dist/types-direct/runtime/basepathRewrite.d.ts +8 -0
  121. package/dist/types-direct/runtime/dataMutation.d.ts +29 -0
  122. package/dist/types-direct/runtime/hooks.d.ts +18 -0
  123. package/dist/types-direct/runtime/index.d.ts +9 -0
  124. package/dist/types-direct/runtime/lifecycle.d.ts +22 -0
  125. package/dist/types-direct/runtime/plugin.d.ts +17 -0
  126. package/dist/types-direct/runtime/plugin.node.d.ts +17 -0
  127. package/dist/types-direct/runtime/prefetchLink.d.ts +11 -0
  128. package/dist/types-direct/runtime/routeTree.d.ts +11 -0
  129. package/dist/types-direct/runtime/rsc/ClientSlot.d.ts +5 -0
  130. package/dist/types-direct/runtime/rsc/CompositeComponent.d.ts +3 -0
  131. package/dist/types-direct/runtime/rsc/ReplayableStream.d.ts +24 -0
  132. package/dist/types-direct/runtime/rsc/RscNodeRenderer.d.ts +5 -0
  133. package/dist/types-direct/runtime/rsc/SlotContext.d.ts +11 -0
  134. package/dist/types-direct/runtime/rsc/client.d.ts +11 -0
  135. package/dist/types-direct/runtime/rsc/createRscProxy.d.ts +7 -0
  136. package/dist/types-direct/runtime/rsc/index.d.ts +2 -0
  137. package/dist/types-direct/runtime/rsc/payloadRouter.d.ts +24 -0
  138. package/dist/types-direct/runtime/rsc/server.d.ts +14 -0
  139. package/dist/types-direct/runtime/rsc/slotUsageSanitizer.d.ts +2 -0
  140. package/dist/types-direct/runtime/rsc/symbols.d.ts +46 -0
  141. package/dist/types-direct/runtime/types.d.ts +68 -0
  142. package/dist/types-direct/runtime/utils.d.ts +36 -0
  143. package/dist/types-direct/runtime.d.ts +1 -0
  144. package/package.json +126 -0
  145. package/rslib.config.mts +4 -0
  146. package/rstest.config.mts +43 -0
  147. package/src/cli/index.ts +388 -0
  148. package/src/cli/tanstackTypes.ts +503 -0
  149. package/src/cli.ts +2 -0
  150. package/src/runtime/DefaultNotFound.tsx +15 -0
  151. package/src/runtime/basepathRewrite.ts +59 -0
  152. package/src/runtime/dataMutation.tsx +517 -0
  153. package/src/runtime/hooks.ts +34 -0
  154. package/src/runtime/index.tsx +30 -0
  155. package/src/runtime/lifecycle.ts +150 -0
  156. package/src/runtime/plugin.node.tsx +534 -0
  157. package/src/runtime/plugin.tsx +395 -0
  158. package/src/runtime/prefetchLink.tsx +87 -0
  159. package/src/runtime/routeTree.ts +942 -0
  160. package/src/runtime/rsc/ClientSlot.tsx +25 -0
  161. package/src/runtime/rsc/CompositeComponent.tsx +65 -0
  162. package/src/runtime/rsc/ReplayableStream.ts +155 -0
  163. package/src/runtime/rsc/RscNodeRenderer.tsx +45 -0
  164. package/src/runtime/rsc/SlotContext.tsx +31 -0
  165. package/src/runtime/rsc/client.tsx +90 -0
  166. package/src/runtime/rsc/createRscProxy.tsx +189 -0
  167. package/src/runtime/rsc/index.ts +10 -0
  168. package/src/runtime/rsc/payloadRouter.ts +318 -0
  169. package/src/runtime/rsc/server.tsx +303 -0
  170. package/src/runtime/rsc/slotUsageSanitizer.ts +76 -0
  171. package/src/runtime/rsc/symbols.ts +106 -0
  172. package/src/runtime/ssr-shim.d.ts +12 -0
  173. package/src/runtime/types.ts +83 -0
  174. package/src/runtime/utils.tsx +161 -0
  175. package/src/runtime.ts +1 -0
  176. package/tests/router/cli.test.ts +386 -0
  177. package/tests/router/dataMutation.test.tsx +396 -0
  178. package/tests/router/prefetchLink.test.tsx +43 -0
  179. package/tests/router/routeTree.test.ts +502 -0
  180. package/tests/router/rsc.test.tsx +256 -0
  181. package/tests/router/tanstackTypes.test.ts +62 -0
  182. package/tsconfig.json +12 -0
  183. package/tsconfig.tsgo.json +6 -0
@@ -0,0 +1,453 @@
1
+ import "node:module";
2
+ import { createRootRoute, createRoute, notFound, redirect } from "@tanstack/react-router";
3
+ import { DefaultNotFound } from "./DefaultNotFound.mjs";
4
+ import { isTanstackRscPayloadNavigationEnabled, loadTanstackRscRouteData } from "./rsc/payloadRouter.mjs";
5
+ function createTanstackRoute(options) {
6
+ return createRoute(options);
7
+ }
8
+ function createTanstackRootRoute(options) {
9
+ return createRootRoute(options);
10
+ }
11
+ function toTanstackPath(pathname) {
12
+ return pathname.split('/').map((segment)=>{
13
+ if (!segment) return segment;
14
+ if ('*' === segment) return '$';
15
+ if (segment.startsWith(':')) {
16
+ const name = segment.slice(1);
17
+ if (name.endsWith('?')) return `{-$${name.slice(0, -1)}}`;
18
+ return `$${name}`;
19
+ }
20
+ return segment;
21
+ }).join('/');
22
+ }
23
+ function isResponse(value) {
24
+ const record = value;
25
+ return null != record && 'object' == typeof record && 'number' == typeof record.status && 'object' == typeof record.headers;
26
+ }
27
+ function isTanstackRedirect(value) {
28
+ return isResponse(value) && 'object' == typeof value.options;
29
+ }
30
+ const redirectStatusCodes = new Set([
31
+ 301,
32
+ 302,
33
+ 303,
34
+ 307,
35
+ 308
36
+ ]);
37
+ function isRedirectResponse(res) {
38
+ return redirectStatusCodes.has(res.status);
39
+ }
40
+ function isModernDeferredData(value) {
41
+ if (!value || 'object' != typeof value) return false;
42
+ const deferred = value;
43
+ return true === deferred.__modern_deferred && Boolean(deferred.data) && 'object' == typeof deferred.data && !Array.isArray(deferred.data);
44
+ }
45
+ function normalizeModernLoaderResult(result) {
46
+ return isModernDeferredData(result) ? result.data : result;
47
+ }
48
+ function normalizeModernLoaderResponse(result) {
49
+ if (isResponse(result)) {
50
+ if (isRedirectResponse(result)) {
51
+ const location = result.headers.get('Location') || '/';
52
+ throwTanstackRedirect(location);
53
+ }
54
+ if (404 === result.status) throw notFound();
55
+ }
56
+ return normalizeModernLoaderResult(result);
57
+ }
58
+ function isAbsoluteUrl(value) {
59
+ try {
60
+ new URL(value);
61
+ return true;
62
+ } catch {
63
+ return false;
64
+ }
65
+ }
66
+ function throwTanstackRedirect(location) {
67
+ const target = location || '/';
68
+ if (isAbsoluteUrl(target)) throw redirect({
69
+ href: target
70
+ });
71
+ throw redirect({
72
+ to: target
73
+ });
74
+ }
75
+ function mapParamsForModernLoader({ modernRoute, params }) {
76
+ if ('nested' === modernRoute.type && modernRoute.path?.includes('*')) {
77
+ const { _splat, ...rest } = params;
78
+ if (void 0 !== _splat) return {
79
+ ...rest,
80
+ '*': _splat
81
+ };
82
+ return rest;
83
+ }
84
+ return params;
85
+ }
86
+ function createModernRequest(input, signal) {
87
+ return new Request(input, {
88
+ signal
89
+ });
90
+ }
91
+ function getModernUrlFromLoaderContext(ctx) {
92
+ const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '/';
93
+ const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
94
+ const baseUrl = baseRequest?.url || ("u" > typeof window ? window.origin : 'http://localhost');
95
+ return new URL(href || '/', baseUrl);
96
+ }
97
+ function rememberRouteLocation(state, ctx) {
98
+ state.currentUrl = getModernUrlFromLoaderContext(ctx);
99
+ state.currentParams = ctx?.params || {};
100
+ }
101
+ function createModernShouldReload(shouldRevalidate, state) {
102
+ if ('function' != typeof shouldRevalidate) return;
103
+ const revalidate = shouldRevalidate;
104
+ return (ctx)=>{
105
+ const nextUrl = getModernUrlFromLoaderContext(ctx);
106
+ const nextParams = ctx?.params || {};
107
+ const result = revalidate({
108
+ currentUrl: state.currentUrl || nextUrl,
109
+ currentParams: state.currentParams || nextParams,
110
+ nextUrl,
111
+ nextParams,
112
+ defaultShouldRevalidate: void 0
113
+ });
114
+ state.currentUrl = nextUrl;
115
+ state.currentParams = nextParams;
116
+ return 'boolean' == typeof result ? result : void 0;
117
+ };
118
+ }
119
+ function wrapModernLoader(modernRoute, modernLoader, revalidationState, options = {}) {
120
+ const route = modernRoute;
121
+ return async (ctx)=>{
122
+ try {
123
+ if (revalidationState) rememberRouteLocation(revalidationState, ctx);
124
+ if ('function' == typeof route.lazyImport) try {
125
+ await route.lazyImport();
126
+ } catch {}
127
+ const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
128
+ const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
129
+ const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
130
+ const request = baseRequest ? new Request(baseRequest, {
131
+ signal
132
+ }) : createModernRequest(href, signal);
133
+ const params = mapParamsForModernLoader({
134
+ modernRoute,
135
+ params: ctx.params || {}
136
+ });
137
+ const loadModernData = async ()=>{
138
+ const result = modernLoader ? await modernLoader({
139
+ request,
140
+ params,
141
+ context: ctx?.context?.requestContext
142
+ }) : null;
143
+ return normalizeModernLoaderResponse(result);
144
+ };
145
+ if (options.rscPayloadRouter && isTanstackRscPayloadNavigationEnabled()) return loadTanstackRscRouteData({
146
+ hasClientLoader: route.hasClientLoader || void 0 !== route.clientData,
147
+ loadClientData: loadModernData,
148
+ request,
149
+ routeId: ctx.route?.id
150
+ });
151
+ return loadModernData();
152
+ } catch (err) {
153
+ if (isResponse(err)) {
154
+ if (isTanstackRedirect(err)) throw err;
155
+ if (isRedirectResponse(err)) {
156
+ const location = err.headers.get('Location') || '/';
157
+ throwTanstackRedirect(location);
158
+ }
159
+ if (404 === err.status) throw notFound();
160
+ }
161
+ throw err;
162
+ }
163
+ };
164
+ }
165
+ function isRouteObjectPathlessLayout(route) {
166
+ return !route.path && !route.index;
167
+ }
168
+ function isRouteObjectSplatRoute(route) {
169
+ return 'string' == typeof route.path && route.path.includes('*');
170
+ }
171
+ function mapParamsForRouteObjectLoader({ route, params }) {
172
+ if (isRouteObjectSplatRoute(route)) {
173
+ const { _splat, ...rest } = params;
174
+ if (void 0 !== _splat) return {
175
+ ...rest,
176
+ '*': _splat
177
+ };
178
+ return rest;
179
+ }
180
+ return params;
181
+ }
182
+ function wrapRouteObjectLoader(route, revalidationState, options = {}) {
183
+ const modernRoute = route;
184
+ const routeLoader = modernRoute.loader;
185
+ if ('function' != typeof routeLoader) return;
186
+ return async (ctx)=>{
187
+ try {
188
+ if (revalidationState) rememberRouteLocation(revalidationState, ctx);
189
+ if ('function' == typeof modernRoute.lazyImport) try {
190
+ await modernRoute.lazyImport();
191
+ } catch {}
192
+ const signal = ctx?.abortController?.signal || ctx?.signal || new AbortController().signal;
193
+ const baseRequest = ctx?.context?.request instanceof Request ? ctx.context.request : void 0;
194
+ const href = 'string' == typeof ctx?.location ? ctx.location : ctx?.location?.publicHref || ctx?.location?.href || ctx?.location?.url?.href || '';
195
+ const request = baseRequest ? new Request(baseRequest, {
196
+ signal
197
+ }) : createModernRequest(href, signal);
198
+ const params = mapParamsForRouteObjectLoader({
199
+ route,
200
+ params: ctx.params || {}
201
+ });
202
+ const loadModernData = async ()=>{
203
+ const result = await routeLoader({
204
+ request,
205
+ params,
206
+ context: ctx?.context?.requestContext
207
+ });
208
+ return normalizeModernLoaderResponse(result);
209
+ };
210
+ if (options.rscPayloadRouter && isTanstackRscPayloadNavigationEnabled()) return loadTanstackRscRouteData({
211
+ hasClientLoader: modernRoute.hasClientLoader || void 0 !== modernRoute.clientData,
212
+ loadClientData: loadModernData,
213
+ request,
214
+ routeId: ctx.route?.id
215
+ });
216
+ return loadModernData();
217
+ } catch (err) {
218
+ if (isResponse(err)) {
219
+ if (isTanstackRedirect(err)) throw err;
220
+ if (isRedirectResponse(err)) {
221
+ const location = err.headers.get('Location') || '/';
222
+ throwTanstackRedirect(location);
223
+ }
224
+ if (404 === err.status) throw notFound();
225
+ }
226
+ throw err;
227
+ }
228
+ };
229
+ }
230
+ function toRouteComponent(routeObject) {
231
+ const route = routeObject;
232
+ if (route.Component) return route.Component;
233
+ const element = route.element;
234
+ if (element) return ()=>element;
235
+ }
236
+ function toErrorComponent(routeObject) {
237
+ const route = routeObject;
238
+ if (route.ErrorBoundary) return route.ErrorBoundary;
239
+ if (route.errorElement) return ()=>route.errorElement;
240
+ }
241
+ function toPendingComponent(routeObject) {
242
+ const route = routeObject;
243
+ return route.HydrateFallback || route.pendingComponent || void 0;
244
+ }
245
+ function mergeModernRouteHandle(route) {
246
+ const config = route.config;
247
+ const handle = {
248
+ ...route.handle,
249
+ ...config && 'object' == typeof config ? config.handle : {}
250
+ };
251
+ return Object.keys(handle).length > 0 ? handle : void 0;
252
+ }
253
+ function createRouteStaticData(opts) {
254
+ const staticData = {};
255
+ if (opts.modernRouteId) staticData.modernRouteId = opts.modernRouteId;
256
+ if (opts.modernRouteAction) staticData.modernRouteAction = opts.modernRouteAction;
257
+ if (opts.modernRouteHandle) staticData.modernRouteHandle = opts.modernRouteHandle;
258
+ if (opts.modernRouteHasAction) staticData.modernRouteHasAction = true;
259
+ if (opts.modernRouteHasClientLoader) staticData.modernRouteHasClientLoader = true;
260
+ if (opts.modernRouteHasLoader) staticData.modernRouteHasLoader = true;
261
+ if (opts.modernRouteIsClientComponent) staticData.modernRouteIsClientComponent = true;
262
+ if (opts.modernRouteLoader) staticData.modernRouteLoader = opts.modernRouteLoader;
263
+ if (opts.modernRouteShouldRevalidate) staticData.modernRouteShouldRevalidate = opts.modernRouteShouldRevalidate;
264
+ return Object.keys(staticData).length > 0 ? staticData : void 0;
265
+ }
266
+ function createRouteFromRouteObject(opts) {
267
+ const { options = {}, parent, routeObject } = opts;
268
+ const modernRouteObject = routeObject;
269
+ const revalidationState = {};
270
+ const shouldRevalidate = modernRouteObject.shouldRevalidate;
271
+ const shouldReload = createModernShouldReload(shouldRevalidate, revalidationState);
272
+ const stableFallbackId = routeObject.id || modernRouteObject.file || routeObject.path || 'pathless';
273
+ const base = {
274
+ getParentRoute: ()=>parent,
275
+ component: toRouteComponent(routeObject),
276
+ pendingComponent: toPendingComponent(routeObject),
277
+ errorComponent: toErrorComponent(routeObject),
278
+ wrapInSuspense: true,
279
+ staticData: createRouteStaticData({
280
+ modernRouteId: routeObject.id,
281
+ modernRouteAction: modernRouteObject.action,
282
+ modernRouteHandle: mergeModernRouteHandle(modernRouteObject),
283
+ modernRouteHasAction: modernRouteObject.hasAction || Boolean(modernRouteObject.action),
284
+ modernRouteHasClientLoader: modernRouteObject.hasClientLoader || void 0 !== modernRouteObject.clientData,
285
+ modernRouteHasLoader: modernRouteObject.hasLoader || 'function' == typeof modernRouteObject.loader,
286
+ modernRouteIsClientComponent: modernRouteObject.isClientComponent,
287
+ modernRouteLoader: modernRouteObject.loader,
288
+ modernRouteShouldRevalidate: shouldRevalidate
289
+ }),
290
+ loader: wrapRouteObjectLoader(routeObject, revalidationState, options)
291
+ };
292
+ if (modernRouteObject.inValidSSRRoute) base.ssr = false;
293
+ if (shouldReload) base.shouldReload = shouldReload;
294
+ if (isRouteObjectPathlessLayout(routeObject)) base.id = stableFallbackId;
295
+ else base.path = routeObject.index ? '/' : toTanstackPath(routeObject.path || '');
296
+ const route = createTanstackRoute(base);
297
+ const children = routeObject.children;
298
+ if (children && children.length > 0) {
299
+ const childRoutes = children.map((child)=>createRouteFromRouteObject({
300
+ options,
301
+ parent: route,
302
+ routeObject: child
303
+ }));
304
+ route.addChildren(childRoutes);
305
+ }
306
+ return route;
307
+ }
308
+ function createRouteFromModernRoute(opts) {
309
+ const { options = {}, parent, modernRoute } = opts;
310
+ const route = modernRoute;
311
+ const revalidationState = {};
312
+ const modernId = route.id;
313
+ const stableFallbackId = modernId || route._component || route.filename || route.data || ('function' == typeof route.loader ? route.id : void 0);
314
+ const pendingComponent = route.loading || route.pendingComponent;
315
+ const errorComponent = route.error || route.errorComponent;
316
+ const component = route.component;
317
+ const modernLoader = route.loader;
318
+ const modernAction = route.action;
319
+ const modernShouldRevalidate = route.shouldRevalidate;
320
+ const shouldReload = createModernShouldReload(modernShouldRevalidate, revalidationState);
321
+ const isPathlessLayout = 'nested' === route.type && 'boolean' != typeof route.index && void 0 === route.path;
322
+ const isIndexRoute = 'nested' === route.type && Boolean(route.index);
323
+ const base = {
324
+ getParentRoute: ()=>parent,
325
+ component: component || void 0,
326
+ pendingComponent: pendingComponent || void 0,
327
+ errorComponent: errorComponent || void 0,
328
+ wrapInSuspense: true,
329
+ staticData: createRouteStaticData({
330
+ modernRouteId: modernId,
331
+ modernRouteAction: modernAction,
332
+ modernRouteHandle: mergeModernRouteHandle(route),
333
+ modernRouteHasAction: route.hasAction || Boolean(modernAction),
334
+ modernRouteHasClientLoader: route.hasClientLoader || void 0 !== route.clientData,
335
+ modernRouteHasLoader: route.hasLoader || 'function' == typeof modernLoader,
336
+ modernRouteIsClientComponent: route.isClientComponent,
337
+ modernRouteLoader: modernLoader,
338
+ modernRouteShouldRevalidate: modernShouldRevalidate
339
+ }),
340
+ loader: wrapModernLoader(modernRoute, modernLoader, revalidationState, options)
341
+ };
342
+ if (route.inValidSSRRoute) base.ssr = false;
343
+ if (shouldReload) base.shouldReload = shouldReload;
344
+ if (isPathlessLayout) base.id = stableFallbackId || 'pathless';
345
+ else {
346
+ const rawPath = route.path;
347
+ base.path = isIndexRoute ? '/' : toTanstackPath(rawPath || '');
348
+ }
349
+ const tanstackRoute = createTanstackRoute(base);
350
+ const children = route.children;
351
+ if (children && children.length > 0) {
352
+ const childRoutes = children.map((child)=>createRouteFromModernRoute({
353
+ options,
354
+ parent: tanstackRoute,
355
+ modernRoute: child
356
+ }));
357
+ tanstackRoute.addChildren(childRoutes);
358
+ }
359
+ return tanstackRoute;
360
+ }
361
+ function createRouteTreeFromModernRoutes(routes, options = {}) {
362
+ const rootModern = routes.find((r)=>r && 'nested' === r.type && r.isRoot);
363
+ const rootComponent = rootModern?.component;
364
+ const pendingComponent = rootModern?.loading;
365
+ const errorComponent = rootModern?.error;
366
+ const rootLoader = rootModern?.loader;
367
+ const rootAction = rootModern?.action;
368
+ const rootModernId = rootModern?.id;
369
+ const rootShouldRevalidate = rootModern?.shouldRevalidate;
370
+ const rootRevalidationState = {};
371
+ const rootShouldReload = createModernShouldReload(rootShouldRevalidate, rootRevalidationState);
372
+ const rootRouteOptions = {
373
+ component: rootComponent || void 0,
374
+ pendingComponent: pendingComponent || void 0,
375
+ errorComponent: errorComponent || void 0,
376
+ wrapInSuspense: true,
377
+ notFoundComponent: DefaultNotFound,
378
+ staticData: createRouteStaticData({
379
+ modernRouteId: rootModernId,
380
+ modernRouteAction: rootAction,
381
+ modernRouteHandle: rootModern ? mergeModernRouteHandle(rootModern) : void 0,
382
+ modernRouteHasAction: rootModern?.hasAction || Boolean(rootAction),
383
+ modernRouteHasClientLoader: rootModern?.hasClientLoader || void 0 !== rootModern?.clientData,
384
+ modernRouteHasLoader: rootModern?.hasLoader || 'function' == typeof rootLoader,
385
+ modernRouteIsClientComponent: rootModern?.isClientComponent,
386
+ modernRouteLoader: rootLoader,
387
+ modernRouteShouldRevalidate: rootShouldRevalidate
388
+ }),
389
+ loader: rootModern ? wrapModernLoader(rootModern, rootLoader, rootRevalidationState, options) : void 0
390
+ };
391
+ if (rootShouldReload) rootRouteOptions.shouldReload = rootShouldReload;
392
+ if (rootModern?.inValidSSRRoute) rootRouteOptions.ssr = false;
393
+ const rootRoute = createTanstackRootRoute(rootRouteOptions);
394
+ const topLevel = rootModern ? rootModern.children || [] : routes;
395
+ const childRoutes = topLevel.map((child)=>createRouteFromModernRoute({
396
+ options,
397
+ parent: rootRoute,
398
+ modernRoute: child
399
+ }));
400
+ rootRoute.addChildren(childRoutes);
401
+ return rootRoute;
402
+ }
403
+ function getRootLikeRouteObject(routes) {
404
+ return routes.find((route)=>'/' === route.path && !route.index);
405
+ }
406
+ function createRouteTreeFromRouteObjects(routes, options = {}) {
407
+ const rootLikeRoute = getRootLikeRouteObject(routes);
408
+ const rootRevalidationState = {};
409
+ const rootShouldRevalidate = rootLikeRoute?.shouldRevalidate;
410
+ const rootShouldReload = createModernShouldReload(rootShouldRevalidate, rootRevalidationState);
411
+ const rootRouteOptions = {
412
+ component: rootLikeRoute ? toRouteComponent(rootLikeRoute) : void 0,
413
+ pendingComponent: rootLikeRoute ? toPendingComponent(rootLikeRoute) : void 0,
414
+ errorComponent: rootLikeRoute ? toErrorComponent(rootLikeRoute) : void 0,
415
+ wrapInSuspense: true,
416
+ notFoundComponent: DefaultNotFound,
417
+ staticData: createRouteStaticData({
418
+ modernRouteId: rootLikeRoute?.id,
419
+ modernRouteAction: rootLikeRoute?.action,
420
+ modernRouteHandle: rootLikeRoute ? mergeModernRouteHandle(rootLikeRoute) : void 0,
421
+ modernRouteHasAction: rootLikeRoute?.hasAction || Boolean(rootLikeRoute?.action),
422
+ modernRouteHasClientLoader: rootLikeRoute?.hasClientLoader || void 0 !== rootLikeRoute?.clientData,
423
+ modernRouteHasLoader: rootLikeRoute?.hasLoader || 'function' == typeof rootLikeRoute?.loader,
424
+ modernRouteIsClientComponent: rootLikeRoute?.isClientComponent,
425
+ modernRouteLoader: rootLikeRoute?.loader,
426
+ modernRouteShouldRevalidate: rootShouldRevalidate
427
+ }),
428
+ loader: rootLikeRoute ? wrapRouteObjectLoader(rootLikeRoute, rootRevalidationState, options) : void 0
429
+ };
430
+ if (rootShouldReload) rootRouteOptions.shouldReload = rootShouldReload;
431
+ if (rootLikeRoute?.inValidSSRRoute) rootRouteOptions.ssr = false;
432
+ const rootRoute = createTanstackRootRoute(rootRouteOptions);
433
+ const topLevel = rootLikeRoute ? [
434
+ ...rootLikeRoute.children || [],
435
+ ...routes.filter((route)=>route !== rootLikeRoute)
436
+ ] : routes;
437
+ const childRoutes = topLevel.map((routeObject)=>createRouteFromRouteObject({
438
+ options,
439
+ parent: rootRoute,
440
+ routeObject
441
+ }));
442
+ rootRoute.addChildren(childRoutes);
443
+ return rootRoute;
444
+ }
445
+ function getModernRouteIdsFromMatches(router) {
446
+ const matches = router.state.matches || [];
447
+ const ids = matches.map((match)=>{
448
+ const route = match.route;
449
+ return route?.options?.staticData?.modernRouteId;
450
+ }).filter((id)=>'string' == typeof id);
451
+ return Array.from(new Set(ids));
452
+ }
453
+ export { createRouteTreeFromModernRoutes, createRouteTreeFromRouteObjects, getModernRouteIdsFromMatches };
@@ -0,0 +1,20 @@
1
+ import "node:module";
2
+ "use client";
3
+ import { Fragment, jsx } from "react/jsx-runtime";
4
+ import { useSlotContext } from "./SlotContext.mjs";
5
+ function ClientSlot({ args, slot }) {
6
+ const context = useSlotContext();
7
+ if (!context) throw new Error('ClientSlot must be rendered inside CompositeComponent.');
8
+ const implementation = context.implementations[slot];
9
+ if (void 0 === implementation) {
10
+ if (context.strict) throw new Error(`Missing RSC slot implementation for "${slot}".`);
11
+ return null;
12
+ }
13
+ if ('function' == typeof implementation) return /*#__PURE__*/ jsx(Fragment, {
14
+ children: implementation(...args)
15
+ });
16
+ return /*#__PURE__*/ jsx(Fragment, {
17
+ children: implementation
18
+ });
19
+ }
20
+ export { ClientSlot };
@@ -0,0 +1,42 @@
1
+ import "node:module";
2
+ "use client";
3
+ import { jsx } from "react/jsx-runtime";
4
+ import { Suspense } from "react";
5
+ import { SlotProvider } from "./SlotContext.mjs";
6
+ import { RSC_PROXY_GET_TREE, RSC_PROXY_PATH } from "./symbols.mjs";
7
+ function EmptyFallback() {
8
+ return null;
9
+ }
10
+ function selectTreePath(tree, path) {
11
+ let current = tree;
12
+ for (const key of path){
13
+ if (null === current || 'object' != typeof current) return null;
14
+ current = current[key];
15
+ }
16
+ return current;
17
+ }
18
+ function CompositeInner({ slotProps, src, strict }) {
19
+ const getTree = src[RSC_PROXY_GET_TREE];
20
+ if (!getTree) throw new Error('CompositeComponent src must come from createCompositeComponent().');
21
+ const tree = selectTreePath(getTree(), src[RSC_PROXY_PATH] || []);
22
+ return /*#__PURE__*/ jsx(SlotProvider, {
23
+ implementations: slotProps,
24
+ strict: strict,
25
+ children: tree
26
+ });
27
+ }
28
+ function CompositeComponent(props) {
29
+ const { children, src, strict, ...slotProps } = props;
30
+ return /*#__PURE__*/ jsx(Suspense, {
31
+ fallback: /*#__PURE__*/ jsx(EmptyFallback, {}),
32
+ children: /*#__PURE__*/ jsx(CompositeInner, {
33
+ slotProps: {
34
+ ...slotProps,
35
+ children
36
+ },
37
+ src: src,
38
+ strict: strict
39
+ })
40
+ });
41
+ }
42
+ export { CompositeComponent };
@@ -0,0 +1,105 @@
1
+ import "node:module";
2
+ const REPLAYABLE_STREAM_MARKER = Symbol.for('modern.tanstack.rsc.ReplayableStream');
3
+ class ReplayableStream {
4
+ start() {
5
+ const signal = this.options.signal;
6
+ if (signal?.aborted) return void this.release();
7
+ this.abortListener = ()=>this.release();
8
+ signal?.addEventListener('abort', this.abortListener, {
9
+ once: true
10
+ });
11
+ const reader = this.source.getReader();
12
+ this.reader = reader;
13
+ const pump = async ()=>{
14
+ try {
15
+ while(!this.released){
16
+ const { done, value } = await reader.read();
17
+ if (done) break;
18
+ this.chunks.push(value);
19
+ this.notify();
20
+ }
21
+ } catch (err) {
22
+ if (!this.released) this.error = err;
23
+ } finally{
24
+ this.done = true;
25
+ this.detachAbortListener();
26
+ try {
27
+ reader.releaseLock();
28
+ } catch {}
29
+ if (this.reader === reader) this.reader = null;
30
+ this.notify();
31
+ }
32
+ };
33
+ pump();
34
+ }
35
+ detachAbortListener() {
36
+ const signal = this.options.signal;
37
+ if (signal && this.abortListener) signal.removeEventListener('abort', this.abortListener);
38
+ this.abortListener = null;
39
+ }
40
+ notify() {
41
+ this.waiter?.resolve();
42
+ this.waiter = null;
43
+ }
44
+ wait() {
45
+ if (this.done || this.released) return Promise.resolve();
46
+ if (!this.waiter) {
47
+ let resolve;
48
+ const promise = new Promise((res)=>{
49
+ resolve = res;
50
+ });
51
+ this.waiter = {
52
+ promise,
53
+ resolve
54
+ };
55
+ }
56
+ return this.waiter.promise;
57
+ }
58
+ release() {
59
+ if (this.released) return;
60
+ this.released = true;
61
+ this.chunks = [];
62
+ this.detachAbortListener();
63
+ try {
64
+ this.reader?.cancel(new Error('ReplayableStream released'));
65
+ } catch {}
66
+ this.notify();
67
+ }
68
+ isReleased() {
69
+ return this.released;
70
+ }
71
+ createReplayStream() {
72
+ if (this.released) return new ReadableStream({
73
+ start (controller) {
74
+ controller.close();
75
+ }
76
+ });
77
+ let index = 0;
78
+ return new ReadableStream({
79
+ pull: async (controller)=>{
80
+ while(true){
81
+ if (index < this.chunks.length) return void controller.enqueue(this.chunks[index++]);
82
+ if (this.error) return void controller.error(this.error);
83
+ if (this.done || this.released) return void controller.close();
84
+ await this.wait();
85
+ }
86
+ },
87
+ cancel: ()=>{}
88
+ });
89
+ }
90
+ constructor(source, options = {}){
91
+ this.source = source;
92
+ this.options = options;
93
+ this[_REPLAYABLE_STREAM_MARKER] = true;
94
+ this.chunks = [];
95
+ this.done = false;
96
+ this.waiter = null;
97
+ this.released = false;
98
+ this.reader = null;
99
+ this.abortListener = null;
100
+ this.start();
101
+ }
102
+ }
103
+ _REPLAYABLE_STREAM_MARKER = REPLAYABLE_STREAM_MARKER;
104
+ var _REPLAYABLE_STREAM_MARKER;
105
+ export { REPLAYABLE_STREAM_MARKER, ReplayableStream };
@@ -0,0 +1,32 @@
1
+ import "node:module";
2
+ "use client";
3
+ import { Fragment, jsx } from "react/jsx-runtime";
4
+ import { Suspense } from "react";
5
+ import { RSC_PROXY_GET_TREE, RSC_PROXY_PATH } from "./symbols.mjs";
6
+ function EmptyFallback() {
7
+ return null;
8
+ }
9
+ function selectTreePath(tree, path) {
10
+ let current = tree;
11
+ for (const key of path){
12
+ if (null === current || 'object' != typeof current) return null;
13
+ current = current[key];
14
+ }
15
+ return current;
16
+ }
17
+ function 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
+ return /*#__PURE__*/ jsx(Fragment, {
21
+ children: selectTreePath(getTree(), data[RSC_PROXY_PATH] || [])
22
+ });
23
+ }
24
+ function RscNodeRenderer({ data }) {
25
+ return /*#__PURE__*/ jsx(Suspense, {
26
+ fallback: /*#__PURE__*/ jsx(EmptyFallback, {}),
27
+ children: /*#__PURE__*/ jsx(RscNodeRenderInner, {
28
+ data: data
29
+ })
30
+ });
31
+ }
32
+ export { RscNodeRenderer };
@@ -0,0 +1,18 @@
1
+ import "node:module";
2
+ "use client";
3
+ import { jsx } from "react/jsx-runtime";
4
+ import { createContext, use } from "react";
5
+ const SlotContext = /*#__PURE__*/ createContext(null);
6
+ function useSlotContext() {
7
+ return use(SlotContext);
8
+ }
9
+ function SlotProvider({ children, implementations, strict }) {
10
+ return /*#__PURE__*/ jsx(SlotContext, {
11
+ value: {
12
+ implementations,
13
+ strict: true === strict
14
+ },
15
+ children: children
16
+ });
17
+ }
18
+ export { SlotProvider, useSlotContext };