@bleedingdev/modern-js-plugin-tanstack 3.5.0-ultramodern.9 → 3.5.0-ultramodern.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (270) hide show
  1. package/dist/cjs/cli/artifacts.js +157 -0
  2. package/dist/cjs/cli/index.js +8 -79
  3. package/dist/cjs/cli/tanstackTypes/canonicalRoutes.js +113 -0
  4. package/dist/cjs/cli/tanstackTypes/shared.js +123 -0
  5. package/dist/cjs/cli/tanstackTypes/source.js +255 -0
  6. package/dist/cjs/cli/tanstackTypes.js +4 -350
  7. package/dist/cjs/runtime/blockingSubscribe.js +57 -0
  8. package/dist/cjs/runtime/{pluginCore.js → clientBasepath.js} +12 -19
  9. package/dist/cjs/runtime/clientHydration.js +118 -0
  10. package/dist/cjs/runtime/dataMutation.js +11 -176
  11. package/dist/cjs/runtime/formData.js +116 -0
  12. package/dist/cjs/runtime/loaderBridge.js +7 -11
  13. package/dist/cjs/runtime/plugin.js +21 -125
  14. package/dist/cjs/runtime/plugin.node.js +45 -125
  15. package/dist/cjs/runtime/pluginShared.js +87 -0
  16. package/dist/cjs/runtime/prefetchLink.js +15 -2
  17. package/dist/cjs/runtime/register.js +3 -16
  18. package/dist/cjs/runtime/routeTree/components.js +102 -0
  19. package/dist/cjs/runtime/routeTree/construction.js +152 -0
  20. package/dist/cjs/runtime/routeTree/index.js +47 -0
  21. package/dist/cjs/runtime/routeTree/loaders.js +158 -0
  22. package/dist/cjs/runtime/routeTree/paths.js +57 -0
  23. package/dist/cjs/runtime/routeTree/staticData.js +63 -0
  24. package/dist/cjs/runtime/routeTree/tanstackRoutes.js +57 -0
  25. package/dist/cjs/runtime/routeTree/types.js +18 -0
  26. package/dist/cjs/runtime/routeTree.js +7 -320
  27. package/dist/cjs/runtime/router.js +15 -2
  28. package/dist/cjs/runtime/rsc/CompositeComponent.js +18 -13
  29. package/dist/cjs/runtime/rsc/ReplayableStream.js +0 -4
  30. package/dist/cjs/runtime/rsc/RscNodeRenderer.js +5 -16
  31. package/dist/cjs/runtime/rsc/client.js +8 -25
  32. package/dist/cjs/runtime/rsc/flightSerialization.js +132 -0
  33. package/dist/cjs/runtime/rsc/payloadErrors.js +99 -0
  34. package/dist/cjs/runtime/rsc/payloadFetch.js +105 -0
  35. package/dist/cjs/runtime/rsc/payloadRouter.js +21 -142
  36. package/dist/cjs/runtime/rsc/payloadRoutes.js +94 -0
  37. package/dist/cjs/runtime/rsc/payloadStorage.js +58 -0
  38. package/dist/cjs/runtime/rsc/server.js +14 -18
  39. package/dist/cjs/runtime/rsc/shared.js +68 -0
  40. package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +1 -0
  41. package/dist/cjs/runtime/rsc/treeGetter.js +72 -0
  42. package/dist/cjs/runtime/shared/isAbsoluteUrl.js +47 -0
  43. package/dist/cjs/runtime/ssrManagedTags.js +103 -0
  44. package/dist/cjs/runtime/ssrPreload.js +89 -0
  45. package/dist/cjs/runtime/ssrTypes.js +18 -0
  46. package/dist/cjs/runtime/state.js +1 -1
  47. package/dist/cjs/runtime/submitAction.js +161 -0
  48. package/dist/cjs/runtime/utils.js +49 -86
  49. package/dist/esm/cli/artifacts.mjs +103 -0
  50. package/dist/esm/cli/index.mjs +8 -82
  51. package/dist/esm/cli/tanstackTypes/canonicalRoutes.mjs +75 -0
  52. package/dist/esm/cli/tanstackTypes/shared.mjs +61 -0
  53. package/dist/esm/cli/tanstackTypes/source.mjs +207 -0
  54. package/dist/esm/cli/tanstackTypes.mjs +2 -339
  55. package/dist/esm/runtime/blockingSubscribe.mjs +19 -0
  56. package/dist/esm/runtime/clientBasepath.mjs +10 -0
  57. package/dist/esm/runtime/clientHydration.mjs +71 -0
  58. package/dist/esm/runtime/dataMutation.mjs +2 -167
  59. package/dist/esm/runtime/formData.mjs +63 -0
  60. package/dist/esm/runtime/loaderBridge.mjs +5 -9
  61. package/dist/esm/runtime/plugin.mjs +14 -118
  62. package/dist/esm/runtime/plugin.node.mjs +41 -121
  63. package/dist/esm/runtime/pluginShared.mjs +40 -0
  64. package/dist/esm/runtime/prefetchLink.mjs +18 -5
  65. package/dist/esm/runtime/register.mjs +1 -14
  66. package/dist/esm/runtime/routeTree/components.mjs +55 -0
  67. package/dist/esm/runtime/routeTree/construction.mjs +111 -0
  68. package/dist/esm/runtime/routeTree/index.mjs +2 -0
  69. package/dist/esm/runtime/routeTree/loaders.mjs +117 -0
  70. package/dist/esm/runtime/routeTree/paths.mjs +16 -0
  71. package/dist/esm/runtime/routeTree/staticData.mjs +22 -0
  72. package/dist/esm/runtime/routeTree/tanstackRoutes.mjs +13 -0
  73. package/dist/esm/runtime/routeTree/types.mjs +0 -0
  74. package/dist/esm/runtime/routeTree.mjs +1 -318
  75. package/dist/esm/runtime/router.mjs +16 -2
  76. package/dist/esm/runtime/rsc/CompositeComponent.mjs +18 -13
  77. package/dist/esm/runtime/rsc/ReplayableStream.mjs +1 -1
  78. package/dist/esm/runtime/rsc/RscNodeRenderer.mjs +4 -15
  79. package/dist/esm/runtime/rsc/client.mjs +6 -26
  80. package/dist/esm/runtime/rsc/flightSerialization.mjs +88 -0
  81. package/dist/esm/runtime/rsc/payloadErrors.mjs +49 -0
  82. package/dist/esm/runtime/rsc/payloadFetch.mjs +55 -0
  83. package/dist/esm/runtime/rsc/payloadRouter.mjs +12 -133
  84. package/dist/esm/runtime/rsc/payloadRoutes.mjs +50 -0
  85. package/dist/esm/runtime/rsc/payloadStorage.mjs +14 -0
  86. package/dist/esm/runtime/rsc/server.mjs +17 -21
  87. package/dist/esm/runtime/rsc/shared.mjs +21 -0
  88. package/dist/esm/runtime/rsc/slotUsageSanitizer.mjs +1 -0
  89. package/dist/esm/runtime/rsc/treeGetter.mjs +34 -0
  90. package/dist/esm/runtime/shared/isAbsoluteUrl.mjs +9 -0
  91. package/dist/esm/runtime/ssrManagedTags.mjs +53 -0
  92. package/dist/esm/runtime/ssrPreload.mjs +51 -0
  93. package/dist/esm/runtime/ssrTypes.mjs +0 -0
  94. package/dist/esm/runtime/state.mjs +1 -1
  95. package/dist/esm/runtime/submitAction.mjs +120 -0
  96. package/dist/esm/runtime/utils.mjs +47 -75
  97. package/dist/esm-node/cli/artifacts.mjs +104 -0
  98. package/dist/esm-node/cli/index.mjs +8 -82
  99. package/dist/esm-node/cli/tanstackTypes/canonicalRoutes.mjs +76 -0
  100. package/dist/esm-node/cli/tanstackTypes/shared.mjs +62 -0
  101. package/dist/esm-node/cli/tanstackTypes/source.mjs +208 -0
  102. package/dist/esm-node/cli/tanstackTypes.mjs +2 -339
  103. package/dist/esm-node/runtime/blockingSubscribe.mjs +20 -0
  104. package/dist/esm-node/runtime/clientBasepath.mjs +11 -0
  105. package/dist/esm-node/runtime/clientHydration.mjs +72 -0
  106. package/dist/esm-node/runtime/dataMutation.mjs +2 -167
  107. package/dist/esm-node/runtime/formData.mjs +64 -0
  108. package/dist/esm-node/runtime/loaderBridge.mjs +5 -9
  109. package/dist/esm-node/runtime/plugin.mjs +14 -118
  110. package/dist/esm-node/runtime/plugin.node.mjs +41 -121
  111. package/dist/esm-node/runtime/pluginShared.mjs +41 -0
  112. package/dist/esm-node/runtime/prefetchLink.mjs +18 -5
  113. package/dist/esm-node/runtime/register.mjs +1 -14
  114. package/dist/esm-node/runtime/routeTree/components.mjs +56 -0
  115. package/dist/esm-node/runtime/routeTree/construction.mjs +112 -0
  116. package/dist/esm-node/runtime/routeTree/index.mjs +3 -0
  117. package/dist/esm-node/runtime/routeTree/loaders.mjs +118 -0
  118. package/dist/esm-node/runtime/routeTree/paths.mjs +17 -0
  119. package/dist/esm-node/runtime/routeTree/staticData.mjs +23 -0
  120. package/dist/esm-node/runtime/routeTree/tanstackRoutes.mjs +14 -0
  121. package/dist/esm-node/runtime/routeTree/types.mjs +1 -0
  122. package/dist/esm-node/runtime/routeTree.mjs +1 -318
  123. package/dist/esm-node/runtime/router.mjs +16 -2
  124. package/dist/esm-node/runtime/rsc/CompositeComponent.mjs +18 -13
  125. package/dist/esm-node/runtime/rsc/ReplayableStream.mjs +1 -1
  126. package/dist/esm-node/runtime/rsc/RscNodeRenderer.mjs +4 -15
  127. package/dist/esm-node/runtime/rsc/client.mjs +6 -26
  128. package/dist/esm-node/runtime/rsc/flightSerialization.mjs +89 -0
  129. package/dist/esm-node/runtime/rsc/payloadErrors.mjs +50 -0
  130. package/dist/esm-node/runtime/rsc/payloadFetch.mjs +56 -0
  131. package/dist/esm-node/runtime/rsc/payloadRouter.mjs +12 -133
  132. package/dist/esm-node/runtime/rsc/payloadRoutes.mjs +51 -0
  133. package/dist/esm-node/runtime/rsc/payloadStorage.mjs +15 -0
  134. package/dist/esm-node/runtime/rsc/server.mjs +17 -21
  135. package/dist/esm-node/runtime/rsc/shared.mjs +22 -0
  136. package/dist/esm-node/runtime/rsc/slotUsageSanitizer.mjs +1 -0
  137. package/dist/esm-node/runtime/rsc/treeGetter.mjs +35 -0
  138. package/dist/esm-node/runtime/shared/isAbsoluteUrl.mjs +10 -0
  139. package/dist/esm-node/runtime/ssrManagedTags.mjs +54 -0
  140. package/dist/esm-node/runtime/ssrPreload.mjs +52 -0
  141. package/dist/esm-node/runtime/ssrTypes.mjs +1 -0
  142. package/dist/esm-node/runtime/state.mjs +1 -1
  143. package/dist/esm-node/runtime/submitAction.mjs +121 -0
  144. package/dist/esm-node/runtime/utils.mjs +47 -75
  145. package/dist/types/cli/artifacts.d.ts +33 -0
  146. package/dist/types/cli/index.d.ts +2 -22
  147. package/dist/types/cli/tanstackTypes/canonicalRoutes.d.ts +22 -0
  148. package/dist/types/cli/tanstackTypes/shared.d.ts +20 -0
  149. package/dist/types/cli/tanstackTypes/source.d.ts +12 -0
  150. package/dist/types/cli/tanstackTypes.d.ts +3 -31
  151. package/dist/types/runtime/blockingSubscribe.d.ts +1 -0
  152. package/dist/types/runtime/clientBasepath.d.ts +1 -0
  153. package/dist/types/runtime/clientHydration.d.ts +10 -0
  154. package/dist/types/runtime/dataMutation.d.ts +3 -12
  155. package/dist/types/runtime/formData.d.ts +24 -0
  156. package/dist/types/runtime/loaderBridge.d.ts +2 -1
  157. package/dist/types/runtime/plugin.d.ts +1 -1
  158. package/dist/types/runtime/plugin.node.d.ts +1 -1
  159. package/dist/types/runtime/pluginShared.d.ts +38 -0
  160. package/dist/types/runtime/register.d.ts +10 -9
  161. package/dist/types/runtime/routeTree/components.d.ts +7 -0
  162. package/dist/types/runtime/routeTree/construction.d.ts +5 -0
  163. package/dist/types/runtime/routeTree/index.d.ts +2 -0
  164. package/dist/types/runtime/routeTree/loaders.d.ts +4 -0
  165. package/dist/types/runtime/routeTree/paths.d.ts +3 -0
  166. package/dist/types/runtime/routeTree/staticData.d.ts +19 -0
  167. package/dist/types/runtime/routeTree/tanstackRoutes.d.ts +4 -0
  168. package/dist/types/runtime/routeTree/types.d.ts +76 -0
  169. package/dist/types/runtime/routeTree.d.ts +1 -9
  170. package/dist/types/runtime/router.d.ts +6 -7
  171. package/dist/types/runtime/rsc/CompositeComponent.d.ts +1 -2
  172. package/dist/types/runtime/rsc/ReplayableStream.d.ts +3 -2
  173. package/dist/types/runtime/rsc/RscNodeRenderer.d.ts +2 -3
  174. package/dist/types/runtime/rsc/SlotContext.d.ts +2 -1
  175. package/dist/types/runtime/rsc/client.d.ts +2 -0
  176. package/dist/types/runtime/rsc/flightSerialization.d.ts +3 -0
  177. package/dist/types/runtime/rsc/payloadErrors.d.ts +6 -0
  178. package/dist/types/runtime/rsc/payloadFetch.d.ts +8 -0
  179. package/dist/types/runtime/rsc/payloadRouter.d.ts +2 -10
  180. package/dist/types/runtime/rsc/payloadRoutes.d.ts +40 -0
  181. package/dist/types/runtime/rsc/payloadStorage.d.ts +5 -0
  182. package/dist/types/runtime/rsc/shared.d.ts +18 -0
  183. package/dist/types/runtime/rsc/treeGetter.d.ts +1 -0
  184. package/dist/types/runtime/shared/isAbsoluteUrl.d.ts +1 -0
  185. package/dist/types/runtime/ssrManagedTags.d.ts +7 -0
  186. package/dist/types/runtime/ssrPreload.d.ts +2 -0
  187. package/dist/types/runtime/ssrTypes.d.ts +44 -0
  188. package/dist/types/runtime/state.d.ts +1 -1
  189. package/dist/types/runtime/submitAction.d.ts +14 -0
  190. package/dist/types/runtime/types.d.ts +4 -10
  191. package/dist/types/runtime/utils.d.ts +4 -24
  192. package/package.json +37 -17
  193. package/rstest.config.mts +23 -0
  194. package/src/cli/artifacts.ts +255 -0
  195. package/src/cli/index.ts +7 -185
  196. package/src/cli/tanstackTypes/canonicalRoutes.ts +157 -0
  197. package/src/cli/tanstackTypes/shared.ts +113 -0
  198. package/src/cli/tanstackTypes/source.ts +414 -0
  199. package/src/cli/tanstackTypes.ts +4 -647
  200. package/src/runtime/blockingSubscribe.ts +48 -0
  201. package/src/runtime/clientBasepath.ts +12 -0
  202. package/src/runtime/clientHydration.ts +149 -0
  203. package/src/runtime/dataMutation.tsx +9 -306
  204. package/src/runtime/formData.ts +153 -0
  205. package/src/runtime/loaderBridge.ts +11 -12
  206. package/src/runtime/plugin.node.tsx +76 -291
  207. package/src/runtime/plugin.tsx +21 -257
  208. package/src/runtime/pluginShared.ts +112 -0
  209. package/src/runtime/prefetchLink.tsx +78 -15
  210. package/src/runtime/register.ts +10 -42
  211. package/src/runtime/routeTree/components.ts +130 -0
  212. package/src/runtime/routeTree/construction.ts +238 -0
  213. package/src/runtime/routeTree/index.ts +7 -0
  214. package/src/runtime/routeTree/loaders.ts +232 -0
  215. package/src/runtime/routeTree/paths.ts +36 -0
  216. package/src/runtime/routeTree/staticData.ts +66 -0
  217. package/src/runtime/routeTree/tanstackRoutes.ts +36 -0
  218. package/src/runtime/routeTree/types.ts +87 -0
  219. package/src/runtime/routeTree.ts +5 -750
  220. package/src/runtime/router.ts +35 -7
  221. package/src/runtime/rsc/CompositeComponent.tsx +29 -20
  222. package/src/runtime/rsc/ReplayableStream.ts +2 -2
  223. package/src/runtime/rsc/RscNodeRenderer.tsx +9 -27
  224. package/src/runtime/rsc/SlotContext.tsx +1 -1
  225. package/src/runtime/rsc/client.tsx +12 -40
  226. package/src/runtime/rsc/flightSerialization.ts +158 -0
  227. package/src/runtime/rsc/payloadErrors.ts +73 -0
  228. package/src/runtime/rsc/payloadFetch.ts +92 -0
  229. package/src/runtime/rsc/payloadRouter.ts +29 -234
  230. package/src/runtime/rsc/payloadRoutes.ts +122 -0
  231. package/src/runtime/rsc/payloadStorage.ts +35 -0
  232. package/src/runtime/rsc/server.tsx +20 -29
  233. package/src/runtime/rsc/shared.ts +70 -0
  234. package/src/runtime/rsc/slotUsageSanitizer.ts +4 -0
  235. package/src/runtime/rsc/treeGetter.tsx +52 -0
  236. package/src/runtime/shared/isAbsoluteUrl.ts +8 -0
  237. package/src/runtime/ssrManagedTags.ts +107 -0
  238. package/src/runtime/ssrPreload.ts +125 -0
  239. package/src/runtime/ssrTypes.ts +51 -0
  240. package/src/runtime/state.ts +9 -3
  241. package/src/runtime/submitAction.ts +201 -0
  242. package/src/runtime/types.ts +4 -18
  243. package/src/runtime/utils.tsx +76 -110
  244. package/src/types/react-server-dom-rspack.d.ts +56 -0
  245. package/tests/castRatchet.test.ts +85 -0
  246. package/tests/realm-isolation.test.ts +114 -0
  247. package/tests/router/cli.test.ts +7 -0
  248. package/tests/router/clientHydration.test.tsx +61 -0
  249. package/tests/router/dataMutation.test.tsx +59 -0
  250. package/tests/router/fixtures/legacyRuntimeRouter.ts +10 -0
  251. package/tests/router/fixtures/router-gen.golden.txt +71 -0
  252. package/tests/router/fixtures/router-gen.oxlint.json +5 -0
  253. package/tests/router/flightSerialization.roundtrip.test.tsx +137 -0
  254. package/tests/router/generateRouteArtifacts.test.ts +106 -0
  255. package/tests/router/hooks.test.ts +14 -0
  256. package/tests/router/loaderBridge.test.ts +21 -0
  257. package/tests/router/prefetchLink.test.tsx +106 -59
  258. package/tests/router/prefetchLinkPreload.test.tsx +85 -0
  259. package/tests/router/register.test.ts +1 -39
  260. package/tests/router/routeTree.test.ts +51 -11
  261. package/tests/router/routerCompatibility.test.ts +245 -0
  262. package/tests/router/rsc.test.tsx +189 -0
  263. package/tests/router/rscPayloadRouterMatrix.test.ts +197 -0
  264. package/tests/router/slotUsageSanitizer.test.ts +23 -0
  265. package/tests/router/ssrPreload.test.ts +30 -0
  266. package/tests/router/tanstackTypes.test.ts +298 -1
  267. package/dist/esm/runtime/pluginCore.mjs +0 -14
  268. package/dist/esm-node/runtime/pluginCore.mjs +0 -15
  269. package/dist/types/runtime/pluginCore.d.ts +0 -21
  270. package/src/runtime/pluginCore.ts +0 -48
@@ -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
- import { DefaultNotFound } from "@modern-js/runtime/context";
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";
@@ -1,2 +1,16 @@
1
- import "./register.mjs";
2
- export { routerPlugin } from "@modern-js/runtime/router/internal";
1
+ import * as __rspack_external__modern_js_runtime_router_internal_8b8183c5 from "@modern-js/runtime/router/internal";
2
+ import { tanstackRouterProviderFactory } from "./register.mjs";
3
+ function getRouterPlugin() {
4
+ const createRouterPlugin = Reflect.get(__rspack_external__modern_js_runtime_router_internal_8b8183c5, 'createRouterPlugin');
5
+ if ('function' == typeof createRouterPlugin) return createRouterPlugin([
6
+ {
7
+ name: 'tanstack',
8
+ factory: tanstackRouterProviderFactory
9
+ }
10
+ ]);
11
+ const legacyRouterPlugin = Reflect.get(__rspack_external__modern_js_runtime_router_internal_8b8183c5, 'routerPlugin');
12
+ if ('function' == typeof legacyRouterPlugin) return tanstackRouterProviderFactory;
13
+ throw new Error('[@modern-js/plugin-tanstack] The installed @modern-js/runtime/router/internal exports neither createRouterPlugin nor routerPlugin. Install a compatible @modern-js/runtime version.');
14
+ }
15
+ const routerPlugin = getRouterPlugin();
16
+ export { routerPlugin };
@@ -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 { 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];
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 current;
19
+ return getTree;
16
20
  }
17
21
  function CompositeInner({ slotProps, src, strict }) {
18
- const getTree = src[RSC_PROXY_GET_TREE];
19
- if (!getTree) throw new Error('CompositeComponent src must come from createCompositeComponent().');
20
- const tree = selectTreePath(getTree(), src[RSC_PROXY_PATH] || []);
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,
@@ -101,4 +101,4 @@ class ReplayableStream {
101
101
  }
102
102
  _REPLAYABLE_STREAM_MARKER = REPLAYABLE_STREAM_MARKER;
103
103
  var _REPLAYABLE_STREAM_MARKER;
104
- export { REPLAYABLE_STREAM_MARKER, ReplayableStream };
104
+ export { ReplayableStream };
@@ -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 { RSC_PROXY_GET_TREE, RSC_PROXY_PATH } from "./symbols.mjs";
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: selectTreePath(getTree(), data[RSC_PROXY_PATH] || [])
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 { use } from "react";
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(createTreeGetter(serialized.stream), {
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 };
@@ -0,0 +1,88 @@
1
+ import { TANSTACK_RSC_FLIGHT_VALUE, isSerializedTanstackRscFlightValue } from "./shared.mjs";
2
+ import { RSC_SLOT_USAGES_STREAM, SERVER_COMPONENT_STREAM, isRenderableServerComponent, isServerComponent } from "./symbols.mjs";
3
+ function isPlainObject(value) {
4
+ if (!value || 'object' != typeof value) return false;
5
+ const prototype = Object.getPrototypeOf(value);
6
+ return prototype === Object.prototype || null === prototype;
7
+ }
8
+ function serializeTanstackRscFlightValues(value, seen = new WeakMap()) {
9
+ if (isServerComponent(value)) {
10
+ const streamWrapper = value[SERVER_COMPONENT_STREAM];
11
+ if (!streamWrapper) throw new Error('Cannot serialize TanStack RSC without a Flight stream.');
12
+ const kind = isRenderableServerComponent(value) ? 'renderable' : 'composite';
13
+ const slotUsagesStream = 'development' === process.env.NODE_ENV && 'composite' === kind ? value[RSC_SLOT_USAGES_STREAM] : void 0;
14
+ return {
15
+ [TANSTACK_RSC_FLIGHT_VALUE]: true,
16
+ kind,
17
+ stream: streamWrapper.createReplayStream(),
18
+ ...slotUsagesStream ? {
19
+ slotUsagesStream
20
+ } : {}
21
+ };
22
+ }
23
+ if (!value || 'object' != typeof value) return value;
24
+ if (seen.has(value)) return seen.get(value);
25
+ if (value instanceof Map) {
26
+ const result = new Map();
27
+ seen.set(value, result);
28
+ for (const [key, item] of value)result.set(serializeTanstackRscFlightValues(key, seen), serializeTanstackRscFlightValues(item, seen));
29
+ return result;
30
+ }
31
+ if (value instanceof Set) {
32
+ const result = new Set();
33
+ seen.set(value, result);
34
+ for (const item of value)result.add(serializeTanstackRscFlightValues(item, seen));
35
+ return result;
36
+ }
37
+ if (Array.isArray(value)) {
38
+ const result = [];
39
+ seen.set(value, result);
40
+ for (const item of value)result.push(serializeTanstackRscFlightValues(item, seen));
41
+ return result;
42
+ }
43
+ if (!isPlainObject(value)) return value;
44
+ const result = {};
45
+ seen.set(value, result);
46
+ for (const [key, item] of Object.entries(value))result[key] = serializeTanstackRscFlightValues(item, seen);
47
+ return result;
48
+ }
49
+ async function reviveTanstackRscFlightValues(value, seen = new WeakMap()) {
50
+ let reviver;
51
+ const getReviver = async ()=>{
52
+ if (!reviver) {
53
+ const client = await import("./client.mjs");
54
+ reviver = client.createTanstackRscValueFromFlight;
55
+ }
56
+ return reviver;
57
+ };
58
+ const visit = async (current)=>{
59
+ if (isSerializedTanstackRscFlightValue(current)) return (await getReviver())(current);
60
+ if (!current || 'object' != typeof current) return current;
61
+ if (seen.has(current)) return seen.get(current);
62
+ if (current instanceof Map) {
63
+ const result = new Map();
64
+ seen.set(current, result);
65
+ for (const [key, item] of current)result.set(await visit(key), await visit(item));
66
+ return result;
67
+ }
68
+ if (current instanceof Set) {
69
+ const result = new Set();
70
+ seen.set(current, result);
71
+ for (const item of current)result.add(await visit(item));
72
+ return result;
73
+ }
74
+ if (Array.isArray(current)) {
75
+ const result = [];
76
+ seen.set(current, result);
77
+ for (const item of current)result.push(await visit(item));
78
+ return result;
79
+ }
80
+ if (!isPlainObject(current)) return current;
81
+ const result = {};
82
+ seen.set(current, result);
83
+ for (const [key, item] of Object.entries(current))result[key] = await visit(item);
84
+ return result;
85
+ };
86
+ return visit(value);
87
+ }
88
+ export { isPlainObject, reviveTanstackRscFlightValues, serializeTanstackRscFlightValues };
@@ -0,0 +1,49 @@
1
+ import { isRouteErrorResponse } from "@modern-js/runtime-utils/router";
2
+ function shouldRedactServerError(status = 500) {
3
+ return status >= 500 && 'development' !== process.env.NODE_ENV && 'test' !== process.env.NODE_ENV;
4
+ }
5
+ function serializePayloadError(error) {
6
+ if (isRouteErrorResponse(error)) {
7
+ if (shouldRedactServerError(error.status)) return {
8
+ status: error.status,
9
+ statusText: 'Internal Server Error',
10
+ data: 'Unexpected Server Error',
11
+ __type: 'RouteErrorResponse'
12
+ };
13
+ return {
14
+ ...error,
15
+ __type: 'RouteErrorResponse'
16
+ };
17
+ }
18
+ if (error instanceof Error) {
19
+ if (shouldRedactServerError()) return {
20
+ message: 'Unexpected Server Error',
21
+ stack: void 0,
22
+ __type: 'Error'
23
+ };
24
+ return {
25
+ message: error.message,
26
+ stack: error.stack,
27
+ __type: 'Error',
28
+ ...'Error' !== error.name ? {
29
+ __subType: error.name
30
+ } : {}
31
+ };
32
+ }
33
+ if (shouldRedactServerError()) return {
34
+ message: 'Unexpected Server Error',
35
+ stack: void 0,
36
+ __type: 'Error'
37
+ };
38
+ return error;
39
+ }
40
+ function isSerializedNotFound(value) {
41
+ return Boolean(value) && 'object' == typeof value && true === value.isNotFound;
42
+ }
43
+ function toRouteErrors(payload) {
44
+ return payload.errors && 'object' == typeof payload.errors ? payload.errors : {};
45
+ }
46
+ function toRouteLoaderData(payload) {
47
+ return payload.loaderData && 'object' == typeof payload.loaderData ? payload.loaderData : {};
48
+ }
49
+ export { isSerializedNotFound, serializePayloadError, shouldRedactServerError, toRouteErrors, toRouteLoaderData };