@tonyclaw/agent-inspector 3.0.18 → 3.0.20

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 (110) hide show
  1. package/.output/cli.js +1257 -506
  2. package/.output/nitro.json +3 -3
  3. package/.output/public/assets/CompareDrawer-CV7rBBty.js +1 -0
  4. package/.output/public/assets/ProxyViewerContainer-CqRfBWJ3.js +127 -0
  5. package/.output/public/assets/ReplayDialog-yDeF-z9y.js +1 -0
  6. package/.output/public/assets/RequestAnatomy-BXxKNdgk.js +1 -0
  7. package/.output/public/assets/ResponseView-BIYNgUNB.js +3 -0
  8. package/.output/public/assets/StreamingChunkSequence-C1faiChu.js +1 -0
  9. package/.output/public/assets/_sessionId-B34PrfCQ.js +1 -0
  10. package/.output/public/assets/index-B3YOj8-_.css +1 -0
  11. package/.output/public/assets/index-BLwqIxup.js +12 -0
  12. package/.output/public/assets/{index-ClQ7Vi3J.js → index-DOspyaW6.js} +1 -1
  13. package/.output/public/assets/index-DT476lno.js +1 -0
  14. package/.output/public/assets/json-viewer-C1S08J_2.js +1 -0
  15. package/.output/server/_chunks/ssr-renderer.mjs +18 -2
  16. package/.output/server/_libs/@radix-ui/react-dismissable-layer+[...].mjs +165 -31
  17. package/.output/server/_libs/@radix-ui/react-use-callback-ref+[...].mjs +1 -1
  18. package/.output/server/_libs/@radix-ui/react-use-controllable-state+[...].mjs +2 -2
  19. package/.output/server/_libs/@radix-ui/react-use-is-hydrated+[...].mjs +28 -1
  20. package/.output/server/_libs/mistralai__mistralai.mjs +1 -1
  21. package/.output/server/_libs/modelcontextprotocol__server.mjs +11571 -8127
  22. package/.output/server/_libs/radix-ui__primitive.mjs +1 -1
  23. package/.output/server/_libs/radix-ui__react-collapsible.mjs +1 -1
  24. package/.output/server/_libs/radix-ui__react-collection.mjs +8 -8
  25. package/.output/server/_libs/radix-ui__react-compose-refs.mjs +0 -1
  26. package/.output/server/_libs/radix-ui__react-context.mjs +4 -18
  27. package/.output/server/_libs/radix-ui__react-dialog.mjs +41 -88
  28. package/.output/server/_libs/radix-ui__react-focus-guards.mjs +15 -5
  29. package/.output/server/_libs/radix-ui__react-focus-scope.mjs +6 -2
  30. package/.output/server/_libs/radix-ui__react-id.mjs +3 -3
  31. package/.output/server/_libs/radix-ui__react-popper.mjs +62 -8
  32. package/.output/server/_libs/radix-ui__react-portal.mjs +2 -2
  33. package/.output/server/_libs/radix-ui__react-presence.mjs +50 -5
  34. package/.output/server/_libs/radix-ui__react-roving-focus.mjs +15 -4
  35. package/.output/server/_libs/radix-ui__react-scroll-area.mjs +30 -20
  36. package/.output/server/_libs/radix-ui__react-select.mjs +167 -123
  37. package/.output/server/_libs/radix-ui__react-slot.mjs +74 -41
  38. package/.output/server/_libs/radix-ui__react-tabs.mjs +6 -1
  39. package/.output/server/_libs/radix-ui__react-tooltip.mjs +6 -3
  40. package/.output/server/_libs/react-dom.mjs +13 -15
  41. package/.output/server/_libs/react.mjs +45 -45
  42. package/.output/server/_libs/srvx.mjs +409 -53
  43. package/.output/server/_libs/swr.mjs +10 -2
  44. package/.output/server/_libs/tailwind-merge.mjs +286 -41
  45. package/.output/server/_libs/tanstack__history.mjs +9 -13
  46. package/.output/server/_libs/tanstack__react-router.mjs +788 -1092
  47. package/.output/server/_libs/tanstack__react-store.mjs +1 -1
  48. package/.output/server/_libs/tanstack__react-virtual.mjs +82 -7
  49. package/.output/server/_libs/tanstack__router-core.mjs +1841 -2060
  50. package/.output/server/_libs/tanstack__virtual-core.mjs +116 -45
  51. package/.output/server/_libs/use-sync-external-store.mjs +1 -1
  52. package/.output/server/_libs/zod-to-json-schema.mjs +1 -1
  53. package/.output/server/_libs/zod.mjs +5085 -200
  54. package/.output/server/{_sessionId-Bi3ZIrqT.mjs → _sessionId-CmoBbtKT.mjs} +30 -32
  55. package/.output/server/_ssr/{CompareDrawer-BYZS_hCR.mjs → CompareDrawer-BsXnVK4e.mjs} +29 -31
  56. package/.output/server/_ssr/{ProxyViewerContainer-BE4umfVs.mjs → ProxyViewerContainer-D-_7pyfx.mjs} +54 -52
  57. package/.output/server/_ssr/{ReplayDialog-BlID2ZH4.mjs → ReplayDialog-deDQA2M5.mjs} +30 -32
  58. package/.output/server/_ssr/{RequestAnatomy-CGJ2lkzT.mjs → RequestAnatomy-CX-cCRdX.mjs} +29 -31
  59. package/.output/server/_ssr/{ResponseView-DDjcGf7M.mjs → ResponseView-D0LJR1qj.mjs} +29 -31
  60. package/.output/server/_ssr/{StreamingChunkSequence-G7B8M5G2.mjs → StreamingChunkSequence-CJRECetE.mjs} +29 -31
  61. package/.output/server/_ssr/empty-plugin-adapters-BFgPZ6_d.mjs +6 -0
  62. package/.output/server/_ssr/{index-ClQ9FvRJ.mjs → index-CYWOXS4d.mjs} +31 -33
  63. package/.output/server/_ssr/index.mjs +1102 -784
  64. package/.output/server/_ssr/{json-viewer-CFbpkiBJ.mjs → json-viewer-CCneYiCn.mjs} +29 -31
  65. package/.output/server/_ssr/{router-Cq8LEvhE.mjs → router-D-PAN8IK.mjs} +182 -67
  66. package/.output/server/_tanstack-start-manifest_v-CVZ9yh4R.mjs +4 -0
  67. package/.output/server/index.mjs +74 -92
  68. package/README.md +4 -4
  69. package/package.json +17 -8
  70. package/src/cli/onboard.ts +1 -1
  71. package/src/cli.ts +2 -2
  72. package/src/components/clients/ClientLogo.tsx +5 -1
  73. package/src/components/proxy-viewer/RequestToolsPanel.tsx +1 -0
  74. package/src/components/proxy-viewer/ResponseView.tsx +1 -0
  75. package/src/components/proxy-viewer/StreamingChunkSequence.tsx +1 -0
  76. package/src/components/proxy-viewer/TurnGroup.tsx +1 -0
  77. package/src/components/proxy-viewer/anatomy/SegmentBar.tsx +1 -0
  78. package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +4 -0
  79. package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +1 -0
  80. package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +2 -0
  81. package/src/components/ui/dialog.tsx +1 -1
  82. package/src/components/ui/json-viewer.tsx +2 -0
  83. package/src/components/ui/select.tsx +1 -1
  84. package/src/contracts/json.ts +7 -2
  85. package/src/lib/providerContract.ts +25 -5
  86. package/src/mcp/server.ts +12 -3
  87. package/src/mcp/toolHandlers.ts +6 -1
  88. package/src/proxy/handler.ts +17 -7
  89. package/src/proxy/logFinalizer.ts +76 -8
  90. package/src/proxy/logIndex.ts +16 -32
  91. package/src/proxy/providers.ts +22 -1
  92. package/src/proxy/sessionProcess.ts +15 -1
  93. package/src/proxy/upstream.ts +4 -2
  94. package/src/router.tsx +9 -0
  95. package/.output/public/assets/CompareDrawer-Daj03-RL.js +0 -1
  96. package/.output/public/assets/ProxyViewerContainer-BLCRQtU_.js +0 -106
  97. package/.output/public/assets/ReplayDialog-5FR5crdo.js +0 -1
  98. package/.output/public/assets/RequestAnatomy-DF0hHdQY.js +0 -1
  99. package/.output/public/assets/ResponseView-BwkMSsUa.js +0 -3
  100. package/.output/public/assets/StreamingChunkSequence-CKeUd58x.js +0 -1
  101. package/.output/public/assets/_sessionId-CThgXa41.js +0 -1
  102. package/.output/public/assets/index-BHXN1Fsx.css +0 -1
  103. package/.output/public/assets/index-gm3A0idN.js +0 -1
  104. package/.output/public/assets/json-viewer-BA-W-PZq.js +0 -1
  105. package/.output/public/assets/main-BnRC1932.js +0 -18
  106. package/.output/server/_libs/@radix-ui/react-use-escape-keydown+[...].mjs +0 -17
  107. package/.output/server/_libs/cfworker__json-schema.mjs +0 -1
  108. package/.output/server/_libs/tiny-invariant.mjs +0 -12
  109. package/.output/server/_libs/tiny-warning.mjs +0 -5
  110. package/.output/server/_tanstack-start-manifest_v-p7J0QCMh.mjs +0 -4
@@ -1,36 +1,40 @@
1
- import { j as jsxRuntimeExports, r as reactExports, R as React, a as React$1 } from "./react.mjs";
2
- import { w as warning } from "./tiny-warning.mjs";
3
- import { i as isNotFound, d as defaultGetScrollRestorationKey, r as restoreScroll, e as escapeHtml, s as storageKey, a as rootRouteId, b as isRedirect, g as getLocationChangeInfo, t as transformReadableStreamWithRouter, c as transformPipeableStreamWithRouter, f as isDangerousProtocol, h as exactPathTest, j as removeTrailingSlash, k as deepEqual, l as functionalUpdate, B as BaseRootRoute, m as BaseRoute, n as isModuleNotFoundError, R as RouterCore } from "./tanstack__router-core.mjs";
4
- import { i as invariant } from "./tiny-invariant.mjs";
1
+ import { r as reactExports, j as jsxRuntimeExports, R as React } from "./react.mjs";
2
+ import { i as invariant, a as isDangerousProtocol, e as exactPathTest, r as removeTrailingSlash, h as hasKeys, d as deepEqual, f as functionalUpdate, B as BaseRootRoute, b as BaseRoute, c as isModuleNotFoundError, g as isNotFound, j as getScrollRestorationScriptForRouter, k as rootRouteId, l as isServer, m as isRedirect, n as createNonReactiveReadonlyStore, o as createNonReactiveMutableStore, R as RouterCore, p as escapeHtml, q as getAssetCrossOrigin, s as getScriptPreloadAttrs, t as appendUniqueUserTags, u as resolveManifestCssLink, v as transformReadableStreamWithRouter, w as createSsrStreamResponse, x as transformPipeableStreamWithRouter } from "./tanstack__router-core.mjs";
5
3
  import { R as ReactDOMServer } from "./react-dom.mjs";
6
4
  import { PassThrough } from "node:stream";
7
5
  import { i as isbot } from "./isbot.mjs";
6
+ var reactUse = reactExports.use;
7
+ function useForwardedRef(ref) {
8
+ const innerRef = reactExports.useRef(null);
9
+ reactExports.useImperativeHandle(ref, () => innerRef.current, []);
10
+ return innerRef;
11
+ }
8
12
  function CatchBoundary(props) {
9
13
  const errorComponent = props.errorComponent ?? ErrorComponent;
10
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
11
- CatchBoundaryImpl,
12
- {
13
- getResetKey: props.getResetKey,
14
- onCatch: props.onCatch,
15
- children: ({ error, reset }) => {
16
- if (error) {
17
- return reactExports.createElement(errorComponent, {
18
- error,
19
- reset
20
- });
21
- }
22
- return props.children;
23
- }
14
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(CatchBoundaryImpl, {
15
+ getResetKey: props.getResetKey,
16
+ onCatch: props.onCatch,
17
+ children: ({ error, reset }) => {
18
+ if (error) return reactExports.createElement(errorComponent, {
19
+ error,
20
+ reset
21
+ });
22
+ return props.children;
24
23
  }
25
- );
24
+ });
26
25
  }
27
- class CatchBoundaryImpl extends reactExports.Component {
28
- constructor() {
29
- super(...arguments);
26
+ var CatchBoundaryImpl = class extends reactExports.Component {
27
+ constructor(..._args) {
28
+ super(..._args);
30
29
  this.state = { error: null };
31
30
  }
32
- static getDerivedStateFromProps(props) {
33
- return { resetKey: props.getResetKey() };
31
+ static getDerivedStateFromProps(props, state) {
32
+ const resetKey = props.getResetKey();
33
+ if (state.error && state.resetKey !== resetKey) return {
34
+ resetKey,
35
+ error: null
36
+ };
37
+ return { resetKey };
34
38
  }
35
39
  static getDerivedStateFromError(error) {
36
40
  return { error };
@@ -38,33 +42,36 @@ class CatchBoundaryImpl extends reactExports.Component {
38
42
  reset() {
39
43
  this.setState({ error: null });
40
44
  }
41
- componentDidUpdate(prevProps, prevState) {
42
- if (prevState.error && prevState.resetKey !== this.state.resetKey) {
43
- this.reset();
44
- }
45
- }
46
45
  componentDidCatch(error, errorInfo) {
47
- if (this.props.onCatch) {
48
- this.props.onCatch(error, errorInfo);
49
- }
46
+ if (this.props.onCatch) this.props.onCatch(error, errorInfo);
50
47
  }
51
48
  render() {
52
49
  return this.props.children({
53
- error: this.state.resetKey !== this.props.getResetKey() ? null : this.state.error,
50
+ error: this.state.error,
54
51
  reset: () => {
55
52
  this.reset();
56
53
  }
57
54
  });
58
55
  }
59
- }
56
+ };
60
57
  function ErrorComponent({ error }) {
61
58
  const [show, setShow] = reactExports.useState(false);
62
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: { padding: ".5rem", maxWidth: "100%" }, children: [
63
- /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { style: { display: "flex", alignItems: "center", gap: ".5rem" }, children: [
64
- /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { style: { fontSize: "1rem" }, children: "Something went wrong!" }),
65
- /* @__PURE__ */ jsxRuntimeExports.jsx(
66
- "button",
67
- {
59
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", {
60
+ style: {
61
+ padding: ".5rem",
62
+ maxWidth: "100%"
63
+ },
64
+ children: [
65
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", {
66
+ style: {
67
+ display: "flex",
68
+ alignItems: "center",
69
+ gap: ".5rem"
70
+ },
71
+ children: [/* @__PURE__ */ jsxRuntimeExports.jsx("strong", {
72
+ style: { fontSize: "1rem" },
73
+ children: "Something went wrong!"
74
+ }), /* @__PURE__ */ jsxRuntimeExports.jsx("button", {
68
75
  style: {
69
76
  appearance: "none",
70
77
  fontSize: ".6em",
@@ -75,13 +82,10 @@ function ErrorComponent({ error }) {
75
82
  },
76
83
  onClick: () => setShow((d) => !d),
77
84
  children: show ? "Hide Error" : "Show Error"
78
- }
79
- )
80
- ] }),
81
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { height: ".25rem" } }),
82
- show ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
83
- "pre",
84
- {
85
+ })]
86
+ }),
87
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { height: ".25rem" } }),
88
+ show ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: /* @__PURE__ */ jsxRuntimeExports.jsx("pre", {
85
89
  style: {
86
90
  fontSize: ".7em",
87
91
  border: "1px solid red",
@@ -91,504 +95,49 @@ function ErrorComponent({ error }) {
91
95
  overflow: "auto"
92
96
  },
93
97
  children: error.message ? /* @__PURE__ */ jsxRuntimeExports.jsx("code", { children: error.message }) : null
94
- }
95
- ) }) : null
96
- ] });
97
- }
98
- const routerContext = reactExports.createContext(null);
99
- function getRouterContext() {
100
- if (typeof document === "undefined") {
101
- return routerContext;
102
- }
103
- if (window.__TSR_ROUTER_CONTEXT__) {
104
- return window.__TSR_ROUTER_CONTEXT__;
105
- }
106
- window.__TSR_ROUTER_CONTEXT__ = routerContext;
107
- return routerContext;
108
- }
109
- function useRouter(opts) {
110
- const value = reactExports.useContext(getRouterContext());
111
- warning(
112
- !((opts?.warn ?? true) && !value)
113
- );
114
- return value;
115
- }
116
- function useRouterState(opts) {
117
- const contextRouter = useRouter({
118
- warn: opts?.router === void 0
119
- });
120
- const router = opts?.router || contextRouter;
121
- {
122
- const state = router.state;
123
- return opts?.select ? opts.select(state) : state;
124
- }
125
- }
126
- const REACT_USE = "use";
127
- const reactUse = React[REACT_USE];
128
- function useForwardedRef(ref) {
129
- const innerRef = reactExports.useRef(null);
130
- reactExports.useImperativeHandle(ref, () => innerRef.current, []);
131
- return innerRef;
132
- }
133
- const matchContext = reactExports.createContext(void 0);
134
- const dummyMatchContext = reactExports.createContext(
135
- void 0
136
- );
137
- function CatchNotFound(props) {
138
- const resetKey = useRouterState({
139
- select: (s) => `not-found-${s.location.pathname}-${s.status}`
98
+ }) }) : null
99
+ ]
140
100
  });
141
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
142
- CatchBoundary,
143
- {
144
- getResetKey: () => resetKey,
145
- onCatch: (error, errorInfo) => {
146
- if (isNotFound(error)) {
147
- props.onCatch?.(error, errorInfo);
148
- } else {
149
- throw error;
150
- }
151
- },
152
- errorComponent: ({ error }) => {
153
- if (isNotFound(error)) {
154
- return props.fallback?.(error);
155
- } else {
156
- throw error;
157
- }
158
- },
159
- children: props.children
160
- }
161
- );
162
- }
163
- function DefaultGlobalNotFound() {
164
- return /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: "Not Found" });
165
- }
166
- function SafeFragment(props) {
167
- return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: props.children });
168
- }
169
- function renderRouteNotFound(router, route, data) {
170
- if (!route.options.notFoundComponent) {
171
- if (router.options.defaultNotFoundComponent) {
172
- return /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.defaultNotFoundComponent, { ...data });
173
- }
174
- return /* @__PURE__ */ jsxRuntimeExports.jsx(DefaultGlobalNotFound, {});
175
- }
176
- return /* @__PURE__ */ jsxRuntimeExports.jsx(route.options.notFoundComponent, { ...data });
177
- }
178
- function ScriptOnce({ children }) {
179
- const router = useRouter();
180
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
181
- "script",
182
- {
183
- nonce: router.options.ssr?.nonce,
184
- dangerouslySetInnerHTML: {
185
- __html: children + ";document.currentScript.remove()"
186
- }
187
- }
188
- );
189
- }
190
- function ScrollRestoration() {
191
- const router = useRouter();
192
- if (!router.isScrollRestoring || false) {
193
- return null;
194
- }
195
- if (typeof router.options.scrollRestoration === "function") {
196
- const shouldRestore = router.options.scrollRestoration({
197
- location: router.latestLocation
198
- });
199
- if (!shouldRestore) {
200
- return null;
201
- }
202
- }
203
- const getKey = router.options.getScrollRestorationKey || defaultGetScrollRestorationKey;
204
- const userKey = getKey(router.latestLocation);
205
- const resolvedKey = userKey !== defaultGetScrollRestorationKey(router.latestLocation) ? userKey : void 0;
206
- const restoreScrollOptions = {
207
- storageKey,
208
- shouldScrollRestoration: true
209
- };
210
- if (resolvedKey) {
211
- restoreScrollOptions.key = resolvedKey;
212
- }
213
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
214
- ScriptOnce,
215
- {
216
- children: `(${restoreScroll.toString()})(${escapeHtml(JSON.stringify(restoreScrollOptions))})`
217
- }
218
- );
219
101
  }
220
102
  function ClientOnly({ children, fallback = null }) {
221
- return useHydrated() ? /* @__PURE__ */ jsxRuntimeExports.jsx(React$1.Fragment, { children }) : /* @__PURE__ */ jsxRuntimeExports.jsx(React$1.Fragment, { children: fallback });
103
+ return useHydrated() ? /* @__PURE__ */ jsxRuntimeExports.jsx(React.Fragment, { children }) : /* @__PURE__ */ jsxRuntimeExports.jsx(React.Fragment, { children: fallback });
222
104
  }
223
105
  function useHydrated() {
224
- return React$1.useSyncExternalStore(
225
- subscribe,
226
- () => true,
227
- () => false
228
- );
106
+ return React.useSyncExternalStore(subscribe, () => true, () => false);
229
107
  }
230
108
  function subscribe() {
231
109
  return () => {
232
110
  };
233
111
  }
234
- const Match = reactExports.memo(function MatchImpl({
235
- matchId
236
- }) {
237
- const router = useRouter();
238
- const matchState = useRouterState({
239
- select: (s) => {
240
- const matchIndex = s.matches.findIndex((d) => d.id === matchId);
241
- const match = s.matches[matchIndex];
242
- invariant(
243
- match
244
- );
245
- return {
246
- routeId: match.routeId,
247
- ssr: match.ssr,
248
- _displayPending: match._displayPending,
249
- resetKey: s.loadedAt,
250
- parentRouteId: s.matches[matchIndex - 1]?.routeId
251
- };
252
- },
253
- structuralSharing: true
254
- });
255
- const route = router.routesById[matchState.routeId];
256
- const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent;
257
- const pendingElement = PendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(PendingComponent, {}) : null;
258
- const routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent;
259
- const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch;
260
- const routeNotFoundComponent = route.isRoot ? (
261
- // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component
262
- route.options.notFoundComponent ?? router.options.notFoundRoute?.options.component
263
- ) : route.options.notFoundComponent;
264
- const resolvedNoSsr = matchState.ssr === false || matchState.ssr === "data-only";
265
- const ResolvedSuspenseBoundary = (
266
- // If we're on the root route, allow forcefully wrapping in suspense
267
- (!route.isRoot || route.options.wrapInSuspense || resolvedNoSsr) && (route.options.wrapInSuspense ?? PendingComponent ?? (route.options.errorComponent?.preload || resolvedNoSsr)) ? reactExports.Suspense : SafeFragment
268
- );
269
- const ResolvedCatchBoundary = routeErrorComponent ? CatchBoundary : SafeFragment;
270
- const ResolvedNotFoundBoundary = routeNotFoundComponent ? CatchNotFound : SafeFragment;
271
- const ShellComponent = route.isRoot ? route.options.shellComponent ?? SafeFragment : SafeFragment;
272
- return /* @__PURE__ */ jsxRuntimeExports.jsxs(ShellComponent, { children: [
273
- /* @__PURE__ */ jsxRuntimeExports.jsx(matchContext.Provider, { value: matchId, children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResolvedSuspenseBoundary, { fallback: pendingElement, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
274
- ResolvedCatchBoundary,
275
- {
276
- getResetKey: () => matchState.resetKey,
277
- errorComponent: routeErrorComponent || ErrorComponent,
278
- onCatch: (error, errorInfo) => {
279
- if (isNotFound(error)) throw error;
280
- routeOnCatch?.(error, errorInfo);
281
- },
282
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(
283
- ResolvedNotFoundBoundary,
284
- {
285
- fallback: (error) => {
286
- if (!routeNotFoundComponent || error.routeId && error.routeId !== matchState.routeId || !error.routeId && !route.isRoot)
287
- throw error;
288
- return reactExports.createElement(routeNotFoundComponent, error);
289
- },
290
- children: resolvedNoSsr || matchState._displayPending ? /* @__PURE__ */ jsxRuntimeExports.jsx(ClientOnly, { fallback: pendingElement, children: /* @__PURE__ */ jsxRuntimeExports.jsx(MatchInner, { matchId }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(MatchInner, { matchId })
291
- }
292
- )
293
- }
294
- ) }) }),
295
- matchState.parentRouteId === rootRouteId && router.options.scrollRestoration ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
296
- /* @__PURE__ */ jsxRuntimeExports.jsx(OnRendered, {}),
297
- /* @__PURE__ */ jsxRuntimeExports.jsx(ScrollRestoration, {})
298
- ] }) : null
299
- ] });
300
- });
301
- function OnRendered() {
302
- const router = useRouter();
303
- const prevLocationRef = reactExports.useRef(
304
- void 0
305
- );
306
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
307
- "script",
308
- {
309
- suppressHydrationWarning: true,
310
- ref: (el) => {
311
- if (el && (prevLocationRef.current === void 0 || prevLocationRef.current.href !== router.latestLocation.href)) {
312
- router.emit({
313
- type: "onRendered",
314
- ...getLocationChangeInfo(router.state)
315
- });
316
- prevLocationRef.current = router.latestLocation;
317
- }
318
- }
319
- },
320
- router.latestLocation.state.__TSR_key
321
- );
322
- }
323
- const MatchInner = reactExports.memo(function MatchInnerImpl({
324
- matchId
325
- }) {
326
- const router = useRouter();
327
- const { match, key, routeId } = useRouterState({
328
- select: (s) => {
329
- const match2 = s.matches.find((d) => d.id === matchId);
330
- const routeId2 = match2.routeId;
331
- const remountFn = router.routesById[routeId2].options.remountDeps ?? router.options.defaultRemountDeps;
332
- const remountDeps = remountFn?.({
333
- routeId: routeId2,
334
- loaderDeps: match2.loaderDeps,
335
- params: match2._strictParams,
336
- search: match2._strictSearch
337
- });
338
- const key2 = remountDeps ? JSON.stringify(remountDeps) : void 0;
339
- return {
340
- key: key2,
341
- routeId: routeId2,
342
- match: {
343
- id: match2.id,
344
- status: match2.status,
345
- error: match2.error,
346
- invalid: match2.invalid,
347
- _forcePending: match2._forcePending,
348
- _displayPending: match2._displayPending
349
- }
350
- };
351
- },
352
- structuralSharing: true
353
- });
354
- const route = router.routesById[routeId];
355
- const out = reactExports.useMemo(() => {
356
- const Comp = route.options.component ?? router.options.defaultComponent;
357
- if (Comp) {
358
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Comp, {}, key);
359
- }
360
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Outlet, {});
361
- }, [key, route.options.component, router.options.defaultComponent]);
362
- if (match._displayPending) {
363
- throw router.getMatch(match.id)?._nonReactive.displayPendingPromise;
364
- }
365
- if (match._forcePending) {
366
- throw router.getMatch(match.id)?._nonReactive.minPendingPromise;
367
- }
368
- if (match.status === "pending") {
369
- const pendingMinMs = route.options.pendingMinMs ?? router.options.defaultPendingMinMs;
370
- if (pendingMinMs) {
371
- const routerMatch = router.getMatch(match.id);
372
- if (routerMatch && !routerMatch._nonReactive.minPendingPromise) ;
373
- }
374
- throw router.getMatch(match.id)?._nonReactive.loadPromise;
375
- }
376
- if (match.status === "notFound") {
377
- invariant(isNotFound(match.error));
378
- return renderRouteNotFound(router, route, match.error);
379
- }
380
- if (match.status === "redirected") {
381
- invariant(isRedirect(match.error));
382
- throw router.getMatch(match.id)?._nonReactive.loadPromise;
383
- }
384
- if (match.status === "error") {
385
- {
386
- const RouteErrorComponent = (route.options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent;
387
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
388
- RouteErrorComponent,
389
- {
390
- error: match.error,
391
- reset: void 0,
392
- info: {
393
- componentStack: ""
394
- }
395
- }
396
- );
397
- }
398
- }
399
- return out;
400
- });
401
- const Outlet = reactExports.memo(function OutletImpl() {
402
- const router = useRouter();
403
- const matchId = reactExports.useContext(matchContext);
404
- const routeId = useRouterState({
405
- select: (s) => s.matches.find((d) => d.id === matchId)?.routeId
406
- });
407
- const route = router.routesById[routeId];
408
- const parentGlobalNotFound = useRouterState({
409
- select: (s) => {
410
- const matches = s.matches;
411
- const parentMatch = matches.find((d) => d.id === matchId);
412
- invariant(
413
- parentMatch
414
- );
415
- return parentMatch.globalNotFound;
416
- }
417
- });
418
- const childMatchId = useRouterState({
419
- select: (s) => {
420
- const matches = s.matches;
421
- const index = matches.findIndex((d) => d.id === matchId);
422
- return matches[index + 1]?.id;
423
- }
424
- });
425
- const pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.defaultPendingComponent, {}) : null;
426
- if (parentGlobalNotFound) {
427
- return renderRouteNotFound(router, route, void 0);
428
- }
429
- if (!childMatchId) {
430
- return null;
431
- }
432
- const nextMatch = /* @__PURE__ */ jsxRuntimeExports.jsx(Match, { matchId: childMatchId });
433
- if (routeId === rootRouteId) {
434
- return /* @__PURE__ */ jsxRuntimeExports.jsx(reactExports.Suspense, { fallback: pendingElement, children: nextMatch });
435
- }
436
- return nextMatch;
437
- });
438
- function Matches() {
439
- const router = useRouter();
440
- const rootRoute = router.routesById[rootRouteId];
441
- const PendingComponent = rootRoute.options.pendingComponent ?? router.options.defaultPendingComponent;
442
- const pendingElement = PendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(PendingComponent, {}) : null;
443
- const ResolvedSuspense = SafeFragment;
444
- const inner = /* @__PURE__ */ jsxRuntimeExports.jsxs(ResolvedSuspense, { fallback: pendingElement, children: [
445
- false,
446
- /* @__PURE__ */ jsxRuntimeExports.jsx(MatchesInner, {})
447
- ] });
448
- return router.options.InnerWrap ? /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.InnerWrap, { children: inner }) : inner;
112
+ var routerContext = reactExports.createContext(null);
113
+ function useRouter(opts) {
114
+ const value = reactExports.useContext(routerContext);
115
+ return value;
449
116
  }
450
- function MatchesInner() {
117
+ var matchContext = reactExports.createContext(void 0);
118
+ var dummyMatchContext = reactExports.createContext(void 0);
119
+ function useMatch(opts) {
451
120
  const router = useRouter();
452
- const matchId = useRouterState({
453
- select: (s) => {
454
- return s.matches[0]?.id;
455
- }
456
- });
457
- const resetKey = useRouterState({
458
- select: (s) => s.loadedAt
459
- });
460
- const matchComponent = matchId ? /* @__PURE__ */ jsxRuntimeExports.jsx(Match, { matchId }) : null;
461
- return /* @__PURE__ */ jsxRuntimeExports.jsx(matchContext.Provider, { value: matchId, children: router.options.disableGlobalCatchBoundary ? matchComponent : /* @__PURE__ */ jsxRuntimeExports.jsx(
462
- CatchBoundary,
463
- {
464
- getResetKey: () => resetKey,
465
- errorComponent: ErrorComponent,
466
- onCatch: (error) => {
467
- warning(false, error.message || error.toString());
468
- },
469
- children: matchComponent
470
- }
471
- ) });
472
- }
473
- function RouterContextProvider({
474
- router,
475
- children,
476
- ...rest
477
- }) {
478
- if (Object.keys(rest).length > 0) {
479
- router.update({
480
- ...router.options,
481
- ...rest,
482
- context: {
483
- ...router.options.context,
484
- ...rest.context
121
+ const nearestMatchId = reactExports.useContext(opts.from ? dummyMatchContext : matchContext);
122
+ const matchStore = opts.from ? router.stores.getRouteMatchStore(opts.from) : router.stores.matchStores.get(nearestMatchId);
123
+ {
124
+ const match = matchStore?.get();
125
+ if (!match) {
126
+ if (opts.shouldThrow ?? true) {
127
+ invariant();
485
128
  }
486
- });
487
- }
488
- const routerContext2 = getRouterContext();
489
- const provider = /* @__PURE__ */ jsxRuntimeExports.jsx(routerContext2.Provider, { value: router, children });
490
- if (router.options.Wrap) {
491
- return /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.Wrap, { children: provider });
492
- }
493
- return provider;
494
- }
495
- function RouterProvider({ router, ...rest }) {
496
- return /* @__PURE__ */ jsxRuntimeExports.jsx(RouterContextProvider, { router, ...rest, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Matches, {}) });
497
- }
498
- const renderRouterToStream = async ({
499
- request,
500
- router,
501
- responseHeaders,
502
- children
503
- }) => {
504
- if (typeof ReactDOMServer.renderToReadableStream === "function") {
505
- const stream = await ReactDOMServer.renderToReadableStream(children, {
506
- signal: request.signal,
507
- nonce: router.options.ssr?.nonce,
508
- progressiveChunkSize: Number.POSITIVE_INFINITY
509
- });
510
- if (isbot(request.headers.get("User-Agent"))) {
511
- await stream.allReady;
512
- }
513
- const responseStream = transformReadableStreamWithRouter(
514
- router,
515
- stream
516
- );
517
- return new Response(responseStream, {
518
- status: router.state.statusCode,
519
- headers: responseHeaders
520
- });
521
- }
522
- if (typeof ReactDOMServer.renderToPipeableStream === "function") {
523
- const reactAppPassthrough = new PassThrough();
524
- try {
525
- const pipeable = ReactDOMServer.renderToPipeableStream(children, {
526
- nonce: router.options.ssr?.nonce,
527
- progressiveChunkSize: Number.POSITIVE_INFINITY,
528
- ...isbot(request.headers.get("User-Agent")) ? {
529
- onAllReady() {
530
- pipeable.pipe(reactAppPassthrough);
531
- }
532
- } : {
533
- onShellReady() {
534
- pipeable.pipe(reactAppPassthrough);
535
- }
536
- },
537
- onError: (error, info) => {
538
- console.error("Error in renderToPipeableStream:", error, info);
539
- if (!reactAppPassthrough.destroyed) {
540
- reactAppPassthrough.destroy(
541
- error instanceof Error ? error : new Error(String(error))
542
- );
543
- }
544
- }
545
- });
546
- } catch (e) {
547
- console.error("Error in renderToPipeableStream:", e);
548
- reactAppPassthrough.destroy(e instanceof Error ? e : new Error(String(e)));
129
+ return;
549
130
  }
550
- const responseStream = transformPipeableStreamWithRouter(
551
- router,
552
- reactAppPassthrough
553
- );
554
- return new Response(responseStream, {
555
- status: router.state.statusCode,
556
- headers: responseHeaders
557
- });
131
+ return opts.select ? opts.select(match) : match;
558
132
  }
559
- throw new Error(
560
- "No renderToReadableStream or renderToPipeableStream found in react-dom/server. Ensure you are using a version of react-dom that supports streaming."
561
- );
562
- };
563
- function useMatch(opts) {
564
- const nearestMatchId = reactExports.useContext(
565
- opts.from ? dummyMatchContext : matchContext
566
- );
567
- const matchSelection = useRouterState({
568
- select: (state) => {
569
- const match = state.matches.find(
570
- (d) => opts.from ? opts.from === d.routeId : d.id === nearestMatchId
571
- );
572
- invariant(
573
- !((opts.shouldThrow ?? true) && !match),
574
- `Could not find ${opts.from ? `an active match from "${opts.from}"` : "a nearest match!"}`
575
- );
576
- if (match === void 0) {
577
- return void 0;
578
- }
579
- return opts.select ? opts.select(match) : match;
580
- },
581
- structuralSharing: opts.structuralSharing
582
- });
583
- return matchSelection;
584
133
  }
585
134
  function useLoaderData(opts) {
586
135
  return useMatch({
587
136
  from: opts.from,
588
137
  strict: opts.strict,
589
138
  structuralSharing: opts.structuralSharing,
590
- select: (s) => {
591
- return opts.select ? opts.select(s.loaderData) : s.loaderData;
139
+ select: (match) => {
140
+ return opts.select ? opts.select(match.loaderData) : match.loaderData;
592
141
  }
593
142
  });
594
143
  }
@@ -596,8 +145,8 @@ function useLoaderDeps(opts) {
596
145
  const { select, ...rest } = opts;
597
146
  return useMatch({
598
147
  ...rest,
599
- select: (s) => {
600
- return select ? select(s.loaderDeps) : s.loaderDeps;
148
+ select: (match) => {
149
+ return select ? select(match.loaderDeps) : match.loaderDeps;
601
150
  }
602
151
  });
603
152
  }
@@ -626,196 +175,121 @@ function useSearch(opts) {
626
175
  }
627
176
  function useNavigate(_defaultOpts) {
628
177
  const router = useRouter();
629
- return reactExports.useCallback(
630
- (options) => {
631
- return router.navigate({
632
- ...options,
633
- from: options.from ?? _defaultOpts?.from
634
- });
635
- },
636
- [_defaultOpts?.from, router]
637
- );
178
+ return reactExports.useCallback((options) => {
179
+ return router.navigate({
180
+ ...options,
181
+ from: options.from ?? _defaultOpts?.from
182
+ });
183
+ }, [_defaultOpts?.from, router]);
184
+ }
185
+ function useRouteContext(opts) {
186
+ return useMatch({
187
+ ...opts,
188
+ select: (match) => opts.select ? opts.select(match.context) : match.context
189
+ });
638
190
  }
639
191
  function useLinkProps(options, forwardedRef) {
640
192
  const router = useRouter();
641
193
  const innerRef = useForwardedRef(forwardedRef);
642
- const {
643
- // custom props
644
- activeProps,
645
- inactiveProps,
646
- activeOptions,
647
- to,
648
- preload: userPreload,
649
- preloadDelay: userPreloadDelay,
650
- hashScrollIntoView,
651
- replace,
652
- startTransition,
653
- resetScroll,
654
- viewTransition,
655
- // element props
656
- children,
657
- target,
658
- disabled,
659
- style,
660
- className,
661
- onClick,
662
- onFocus,
663
- onMouseEnter,
664
- onMouseLeave,
665
- onTouchStart,
666
- ignoreBlocker,
667
- // prevent these from being returned
668
- params: _params,
669
- search: _search,
670
- hash: _hash,
671
- state: _state,
672
- mask: _mask,
673
- reloadDocument: _reloadDocument,
674
- unsafeRelative: _unsafeRelative,
675
- from: _from,
676
- _fromLocation,
677
- ...propsSafeToSpread
678
- } = options;
194
+ const { activeProps, inactiveProps, activeOptions, to, preload: userPreload, preloadDelay: userPreloadDelay, preloadIntentProximity: _preloadIntentProximity, hashScrollIntoView, replace, startTransition, resetScroll, viewTransition, children, target, disabled, style, className, onClick, onBlur, onFocus, onMouseEnter, onMouseLeave, onTouchStart, ignoreBlocker, params: _params, search: _search, hash: _hash, state: _state, mask: _mask, reloadDocument: _reloadDocument, unsafeRelative: _unsafeRelative, from: _from, _fromLocation, ...propsSafeToSpread } = options;
679
195
  {
680
196
  const safeInternal = isSafeInternal(to);
681
- if (typeof to === "string" && !safeInternal && // Quick checks to avoid `new URL` in common internal-like cases
682
- to.indexOf(":") > -1) {
683
- try {
684
- new URL(to);
685
- if (isDangerousProtocol(to, router.protocolAllowlist)) {
686
- if (false) ;
687
- return {
688
- ...propsSafeToSpread,
689
- ref: innerRef,
690
- href: void 0,
691
- ...children && { children },
692
- ...target && { target },
693
- ...disabled && { disabled },
694
- ...style && { style },
695
- ...className && { className }
696
- };
697
- }
197
+ if (typeof to === "string" && !safeInternal && to.indexOf(":") > -1) try {
198
+ new URL(to);
199
+ if (isDangerousProtocol(to, router.protocolAllowlist)) {
200
+ if (false) ;
698
201
  return {
699
202
  ...propsSafeToSpread,
700
203
  ref: innerRef,
701
- href: to,
204
+ href: void 0,
702
205
  ...children && { children },
703
206
  ...target && { target },
704
207
  ...disabled && { disabled },
705
208
  ...style && { style },
706
209
  ...className && { className }
707
210
  };
708
- } catch {
709
211
  }
212
+ return {
213
+ ...propsSafeToSpread,
214
+ ref: innerRef,
215
+ href: to,
216
+ ...children && { children },
217
+ ...target && { target },
218
+ ...disabled && { disabled },
219
+ ...style && { style },
220
+ ...className && { className }
221
+ };
222
+ } catch {
710
223
  }
711
- const next2 = router.buildLocation({ ...options, from: options.from });
712
- const hrefOptionPublicHref2 = next2.maskedLocation ? next2.maskedLocation.publicHref : next2.publicHref;
713
- const hrefOptionExternal2 = next2.maskedLocation ? next2.maskedLocation.external : next2.external;
714
- const hrefOption2 = getHrefOption(
715
- hrefOptionPublicHref2,
716
- hrefOptionExternal2,
717
- router.history,
718
- disabled
719
- );
224
+ const next2 = router.buildLocation({
225
+ ...options,
226
+ from: options.from
227
+ });
228
+ const hrefOption2 = getHrefOption(next2.maskedLocation ? next2.maskedLocation.publicHref : next2.publicHref, next2.maskedLocation ? next2.maskedLocation.external : next2.external, router.history, disabled);
720
229
  const externalLink2 = (() => {
721
230
  if (hrefOption2?.external) {
722
231
  if (isDangerousProtocol(hrefOption2.href, router.protocolAllowlist)) {
723
- return void 0;
232
+ return;
724
233
  }
725
234
  return hrefOption2.href;
726
235
  }
727
236
  if (safeInternal) return void 0;
728
- if (typeof to === "string" && to.indexOf(":") > -1) {
729
- try {
730
- new URL(to);
731
- if (isDangerousProtocol(to, router.protocolAllowlist)) {
732
- if (false) ;
733
- return void 0;
734
- }
735
- return to;
736
- } catch {
237
+ if (typeof to === "string" && to.indexOf(":") > -1) try {
238
+ new URL(to);
239
+ if (isDangerousProtocol(to, router.protocolAllowlist)) {
240
+ if (false) ;
241
+ return;
737
242
  }
243
+ return to;
244
+ } catch {
738
245
  }
739
- return void 0;
740
246
  })();
741
247
  const isActive2 = (() => {
742
248
  if (externalLink2) return false;
743
- const currentLocation = router.state.location;
249
+ const currentLocation2 = router.stores.location.get();
744
250
  const exact = activeOptions?.exact ?? false;
745
251
  if (exact) {
746
- const testExact = exactPathTest(
747
- currentLocation.pathname,
748
- next2.pathname,
749
- router.basepath
750
- );
751
- if (!testExact) {
752
- return false;
753
- }
252
+ if (!exactPathTest(currentLocation2.pathname, next2.pathname, router.basepath)) return false;
754
253
  } else {
755
- const currentPathSplit = removeTrailingSlash(
756
- currentLocation.pathname,
757
- router.basepath
758
- );
759
- const nextPathSplit = removeTrailingSlash(
760
- next2.pathname,
761
- router.basepath
762
- );
763
- const pathIsFuzzyEqual = currentPathSplit.startsWith(nextPathSplit) && (currentPathSplit.length === nextPathSplit.length || currentPathSplit[nextPathSplit.length] === "/");
764
- if (!pathIsFuzzyEqual) {
765
- return false;
766
- }
254
+ const currentPathSplit = removeTrailingSlash(currentLocation2.pathname, router.basepath);
255
+ const nextPathSplit = removeTrailingSlash(next2.pathname, router.basepath);
256
+ if (!(currentPathSplit.startsWith(nextPathSplit) && (currentPathSplit.length === nextPathSplit.length || currentPathSplit[nextPathSplit.length] === "/"))) return false;
767
257
  }
768
- const includeSearch = activeOptions?.includeSearch ?? true;
769
- if (includeSearch) {
770
- if (currentLocation.search !== next2.search) {
771
- const currentSearchEmpty = !currentLocation.search || typeof currentLocation.search === "object" && Object.keys(currentLocation.search).length === 0;
772
- const nextSearchEmpty = !next2.search || typeof next2.search === "object" && Object.keys(next2.search).length === 0;
258
+ if (activeOptions?.includeSearch ?? true) {
259
+ if (currentLocation2.search !== next2.search) {
260
+ const currentSearchEmpty = !currentLocation2.search || typeof currentLocation2.search === "object" && !hasKeys(currentLocation2.search);
261
+ const nextSearchEmpty = !next2.search || typeof next2.search === "object" && !hasKeys(next2.search);
773
262
  if (!(currentSearchEmpty && nextSearchEmpty)) {
774
- const searchTest = deepEqual(currentLocation.search, next2.search, {
263
+ if (!deepEqual(currentLocation2.search, next2.search, {
775
264
  partial: !exact,
776
265
  ignoreUndefined: !activeOptions?.explicitUndefined
777
- });
778
- if (!searchTest) {
779
- return false;
780
- }
266
+ })) return false;
781
267
  }
782
268
  }
783
269
  }
784
- if (activeOptions?.includeHash) {
785
- return false;
786
- }
270
+ if (activeOptions?.includeHash) return false;
787
271
  return true;
788
272
  })();
789
- if (externalLink2) {
790
- return {
791
- ...propsSafeToSpread,
792
- ref: innerRef,
793
- href: externalLink2,
794
- ...children && { children },
795
- ...target && { target },
796
- ...disabled && { disabled },
797
- ...style && { style },
798
- ...className && { className }
799
- };
800
- }
273
+ if (externalLink2) return {
274
+ ...propsSafeToSpread,
275
+ ref: innerRef,
276
+ href: externalLink2,
277
+ ...children && { children },
278
+ ...target && { target },
279
+ ...disabled && { disabled },
280
+ ...style && { style },
281
+ ...className && { className }
282
+ };
801
283
  const resolvedActiveProps2 = isActive2 ? functionalUpdate(activeProps, {}) ?? STATIC_ACTIVE_OBJECT : STATIC_EMPTY_OBJECT;
802
284
  const resolvedInactiveProps2 = isActive2 ? STATIC_EMPTY_OBJECT : functionalUpdate(inactiveProps, {}) ?? STATIC_EMPTY_OBJECT;
803
285
  const resolvedStyle2 = (() => {
804
286
  const baseStyle = style;
805
287
  const activeStyle = resolvedActiveProps2.style;
806
288
  const inactiveStyle = resolvedInactiveProps2.style;
807
- if (!baseStyle && !activeStyle && !inactiveStyle) {
808
- return void 0;
809
- }
810
- if (baseStyle && !activeStyle && !inactiveStyle) {
811
- return baseStyle;
812
- }
813
- if (!baseStyle && activeStyle && !inactiveStyle) {
814
- return activeStyle;
815
- }
816
- if (!baseStyle && !activeStyle && inactiveStyle) {
817
- return inactiveStyle;
818
- }
289
+ if (!baseStyle && !activeStyle && !inactiveStyle) return;
290
+ if (baseStyle && !activeStyle && !inactiveStyle) return baseStyle;
291
+ if (!baseStyle && activeStyle && !inactiveStyle) return activeStyle;
292
+ if (!baseStyle && !activeStyle && inactiveStyle) return inactiveStyle;
819
293
  return {
820
294
  ...baseStyle,
821
295
  ...activeStyle,
@@ -826,19 +300,11 @@ function useLinkProps(options, forwardedRef) {
826
300
  const baseClassName = className;
827
301
  const activeClassName = resolvedActiveProps2.className;
828
302
  const inactiveClassName = resolvedInactiveProps2.className;
829
- if (!baseClassName && !activeClassName && !inactiveClassName) {
830
- return "";
831
- }
303
+ if (!baseClassName && !activeClassName && !inactiveClassName) return "";
832
304
  let out = "";
833
- if (baseClassName) {
834
- out = baseClassName;
835
- }
836
- if (activeClassName) {
837
- out = out ? `${out} ${activeClassName}` : activeClassName;
838
- }
839
- if (inactiveClassName) {
840
- out = out ? `${out} ${inactiveClassName}` : inactiveClassName;
841
- }
305
+ if (baseClassName) out = baseClassName;
306
+ if (activeClassName) out = out ? `${out} ${activeClassName}` : activeClassName;
307
+ if (inactiveClassName) out = out ? `${out} ${inactiveClassName}` : inactiveClassName;
842
308
  return out;
843
309
  })();
844
310
  return {
@@ -856,15 +322,22 @@ function useLinkProps(options, forwardedRef) {
856
322
  };
857
323
  }
858
324
  }
859
- const STATIC_EMPTY_OBJECT = {};
860
- const STATIC_ACTIVE_OBJECT = { className: "active" };
861
- const STATIC_DISABLED_PROPS = { role: "link", "aria-disabled": true };
862
- const STATIC_ACTIVE_PROPS = { "data-status": "active", "aria-current": "page" };
325
+ var STATIC_EMPTY_OBJECT = {};
326
+ var STATIC_ACTIVE_OBJECT = { className: "active" };
327
+ var STATIC_DISABLED_PROPS = {
328
+ role: "link",
329
+ "aria-disabled": true
330
+ };
331
+ var STATIC_ACTIVE_PROPS = {
332
+ "data-status": "active",
333
+ "aria-current": "page"
334
+ };
863
335
  function getHrefOption(publicHref, external, history, disabled) {
864
336
  if (disabled) return void 0;
865
- if (external) {
866
- return { href: publicHref, external: true };
867
- }
337
+ if (external) return {
338
+ href: publicHref,
339
+ external: true
340
+ };
868
341
  return {
869
342
  href: history.createHref(publicHref) || "/",
870
343
  external: false
@@ -876,24 +349,20 @@ function isSafeInternal(to) {
876
349
  if (zero === 47) return to.charCodeAt(1) !== 47;
877
350
  return zero === 46;
878
351
  }
879
- const Link = reactExports.forwardRef(
880
- (props, ref) => {
881
- const { _asChild, ...rest } = props;
882
- const { type: _type, ...linkProps } = useLinkProps(rest, ref);
883
- const children = typeof rest.children === "function" ? rest.children({
884
- isActive: linkProps["data-status"] === "active"
885
- }) : rest.children;
886
- if (!_asChild) {
887
- const { disabled: _, ...rest2 } = linkProps;
888
- return reactExports.createElement("a", rest2, children);
889
- }
890
- return reactExports.createElement(_asChild, linkProps, children);
352
+ var Link = reactExports.forwardRef((props, ref) => {
353
+ const { _asChild, ...rest } = props;
354
+ const { type: _type, ...linkProps } = useLinkProps(rest, ref);
355
+ const children = typeof rest.children === "function" ? rest.children({ isActive: linkProps["data-status"] === "active" }) : rest.children;
356
+ if (!_asChild) {
357
+ const { disabled: _, ...rest2 } = linkProps;
358
+ return reactExports.createElement("a", rest2, children);
891
359
  }
892
- );
893
- class Route extends BaseRoute {
360
+ return reactExports.createElement(_asChild, linkProps, children);
361
+ });
362
+ var Route = class extends BaseRoute {
894
363
  /**
895
- * @deprecated Use the `createRoute` function instead.
896
- */
364
+ * @deprecated Use the `createRoute` function instead.
365
+ */
897
366
  constructor(options) {
898
367
  super(options);
899
368
  this.useMatch = (opts) => {
@@ -904,10 +373,9 @@ class Route extends BaseRoute {
904
373
  });
905
374
  };
906
375
  this.useRouteContext = (opts) => {
907
- return useMatch({
376
+ return useRouteContext({
908
377
  ...opts,
909
- from: this.id,
910
- select: (d) => opts?.select ? opts.select(d.context) : d.context
378
+ from: this.id
911
379
  });
912
380
  };
913
381
  this.useSearch = (opts) => {
@@ -925,32 +393,36 @@ class Route extends BaseRoute {
925
393
  });
926
394
  };
927
395
  this.useLoaderDeps = (opts) => {
928
- return useLoaderDeps({ ...opts, from: this.id });
396
+ return useLoaderDeps({
397
+ ...opts,
398
+ from: this.id
399
+ });
929
400
  };
930
401
  this.useLoaderData = (opts) => {
931
- return useLoaderData({ ...opts, from: this.id });
402
+ return useLoaderData({
403
+ ...opts,
404
+ from: this.id
405
+ });
932
406
  };
933
407
  this.useNavigate = () => {
934
408
  return useNavigate({ from: this.fullPath });
935
409
  };
936
- this.Link = React$1.forwardRef(
937
- (props, ref) => {
938
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Link, { ref, from: this.fullPath, ...props });
939
- }
940
- );
941
- this.$$typeof = /* @__PURE__ */ Symbol.for("react.memo");
410
+ this.Link = React.forwardRef((props, ref) => {
411
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(Link, {
412
+ ref,
413
+ from: this.fullPath,
414
+ ...props
415
+ });
416
+ });
942
417
  }
943
- }
418
+ };
944
419
  function createRoute(options) {
945
- return new Route(
946
- // TODO: Help us TypeChris, you're our only hope!
947
- options
948
- );
420
+ return new Route(options);
949
421
  }
950
- class RootRoute extends BaseRootRoute {
422
+ var RootRoute = class extends BaseRootRoute {
951
423
  /**
952
- * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
953
- */
424
+ * @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
425
+ */
954
426
  constructor(options) {
955
427
  super(options);
956
428
  this.useMatch = (opts) => {
@@ -961,10 +433,9 @@ class RootRoute extends BaseRootRoute {
961
433
  });
962
434
  };
963
435
  this.useRouteContext = (opts) => {
964
- return useMatch({
436
+ return useRouteContext({
965
437
  ...opts,
966
- from: this.id,
967
- select: (d) => opts?.select ? opts.select(d.context) : d.context
438
+ from: this.id
968
439
  });
969
440
  };
970
441
  this.useSearch = (opts) => {
@@ -982,121 +453,67 @@ class RootRoute extends BaseRootRoute {
982
453
  });
983
454
  };
984
455
  this.useLoaderDeps = (opts) => {
985
- return useLoaderDeps({ ...opts, from: this.id });
456
+ return useLoaderDeps({
457
+ ...opts,
458
+ from: this.id
459
+ });
986
460
  };
987
461
  this.useLoaderData = (opts) => {
988
- return useLoaderData({ ...opts, from: this.id });
462
+ return useLoaderData({
463
+ ...opts,
464
+ from: this.id
465
+ });
989
466
  };
990
467
  this.useNavigate = () => {
991
468
  return useNavigate({ from: this.fullPath });
992
469
  };
993
- this.Link = React$1.forwardRef(
994
- (props, ref) => {
995
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Link, { ref, from: this.fullPath, ...props });
996
- }
997
- );
998
- this.$$typeof = /* @__PURE__ */ Symbol.for("react.memo");
470
+ this.Link = React.forwardRef((props, ref) => {
471
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(Link, {
472
+ ref,
473
+ from: this.fullPath,
474
+ ...props
475
+ });
476
+ });
999
477
  }
1000
- }
478
+ };
1001
479
  function createRootRoute(options) {
1002
480
  return new RootRoute(options);
1003
481
  }
1004
482
  function createFileRoute(path) {
1005
- if (typeof path === "object") {
1006
- return new FileRoute(path, {
1007
- silent: true
1008
- }).createRoute(path);
1009
- }
1010
- return new FileRoute(path, {
1011
- silent: true
1012
- }).createRoute;
483
+ return new FileRoute(path, { silent: true }).createRoute;
1013
484
  }
1014
- class FileRoute {
485
+ var FileRoute = class {
1015
486
  constructor(path, _opts) {
1016
487
  this.path = path;
1017
488
  this.createRoute = (options) => {
1018
- warning(
1019
- this.silent
1020
- );
1021
489
  const route = createRoute(options);
1022
490
  route.isRoot = false;
1023
491
  return route;
1024
492
  };
1025
493
  this.silent = _opts?.silent;
1026
494
  }
1027
- }
1028
- class LazyRoute {
1029
- constructor(opts) {
1030
- this.useMatch = (opts2) => {
1031
- return useMatch({
1032
- select: opts2?.select,
1033
- from: this.options.id,
1034
- structuralSharing: opts2?.structuralSharing
1035
- });
1036
- };
1037
- this.useRouteContext = (opts2) => {
1038
- return useMatch({
1039
- from: this.options.id,
1040
- select: (d) => opts2?.select ? opts2.select(d.context) : d.context
1041
- });
1042
- };
1043
- this.useSearch = (opts2) => {
1044
- return useSearch({
1045
- select: opts2?.select,
1046
- structuralSharing: opts2?.structuralSharing,
1047
- from: this.options.id
1048
- });
1049
- };
1050
- this.useParams = (opts2) => {
1051
- return useParams({
1052
- select: opts2?.select,
1053
- structuralSharing: opts2?.structuralSharing,
1054
- from: this.options.id
1055
- });
1056
- };
1057
- this.useLoaderDeps = (opts2) => {
1058
- return useLoaderDeps({ ...opts2, from: this.options.id });
1059
- };
1060
- this.useLoaderData = (opts2) => {
1061
- return useLoaderData({ ...opts2, from: this.options.id });
1062
- };
1063
- this.useNavigate = () => {
1064
- const router = useRouter();
1065
- return useNavigate({ from: router.routesById[this.options.id].fullPath });
1066
- };
1067
- this.options = opts;
1068
- this.$$typeof = /* @__PURE__ */ Symbol.for("react.memo");
1069
- }
1070
- }
1071
- function createLazyFileRoute(id) {
1072
- if (typeof id === "object") {
1073
- return new LazyRoute(id);
1074
- }
1075
- return (opts) => new LazyRoute({ id, ...opts });
1076
- }
495
+ };
1077
496
  function lazyRouteComponent(importer, exportName) {
1078
497
  let loadPromise;
1079
498
  let comp;
1080
499
  let error;
1081
500
  let reload;
1082
501
  const load = () => {
1083
- if (!loadPromise) {
1084
- loadPromise = importer().then((res) => {
1085
- loadPromise = void 0;
1086
- comp = res[exportName];
1087
- }).catch((err) => {
1088
- error = err;
1089
- if (isModuleNotFoundError(error)) {
1090
- if (error instanceof Error && typeof window !== "undefined" && typeof sessionStorage !== "undefined") {
1091
- const storageKey2 = `tanstack_router_reload:${error.message}`;
1092
- if (!sessionStorage.getItem(storageKey2)) {
1093
- sessionStorage.setItem(storageKey2, "1");
1094
- reload = true;
1095
- }
502
+ if (!loadPromise) loadPromise = importer().then((res) => {
503
+ loadPromise = void 0;
504
+ comp = res[exportName];
505
+ }).catch((err) => {
506
+ error = err;
507
+ if (isModuleNotFoundError(error)) {
508
+ if (error instanceof Error && typeof window !== "undefined" && typeof sessionStorage !== "undefined") {
509
+ const storageKey = `tanstack_router_reload:${error.message}`;
510
+ if (!sessionStorage.getItem(storageKey)) {
511
+ sessionStorage.setItem(storageKey, "1");
512
+ reload = true;
1096
513
  }
1097
514
  }
1098
- });
1099
- }
515
+ }
516
+ });
1100
517
  return loadPromise;
1101
518
  };
1102
519
  const lazyComp = function Lazy(props) {
@@ -1105,68 +522,305 @@ function lazyRouteComponent(importer, exportName) {
1105
522
  throw new Promise(() => {
1106
523
  });
1107
524
  }
1108
- if (error) {
1109
- throw error;
1110
- }
1111
- if (!comp) {
1112
- if (reactUse) {
1113
- reactUse(load());
1114
- } else {
1115
- throw load();
1116
- }
1117
- }
525
+ if (error) throw error;
526
+ if (!comp) if (reactUse) reactUse(load());
527
+ else throw load();
1118
528
  return reactExports.createElement(comp, props);
1119
529
  };
1120
530
  lazyComp.preload = load;
1121
531
  return lazyComp;
1122
532
  }
1123
- const createRouter = (options) => {
533
+ function CatchNotFound(props) {
534
+ const router = useRouter();
535
+ {
536
+ const resetKey = `not-found-${router.stores.location.get().pathname}-${router.stores.status.get()}`;
537
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(CatchBoundary, {
538
+ getResetKey: () => resetKey,
539
+ onCatch: (error, errorInfo) => {
540
+ if (isNotFound(error)) props.onCatch?.(error, errorInfo);
541
+ else throw error;
542
+ },
543
+ errorComponent: ({ error }) => {
544
+ if (isNotFound(error)) return props.fallback?.(error);
545
+ else throw error;
546
+ },
547
+ children: props.children
548
+ });
549
+ }
550
+ }
551
+ function DefaultGlobalNotFound() {
552
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: "Not Found" });
553
+ }
554
+ function ScriptOnce({ children }) {
555
+ const router = useRouter();
556
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("script", {
557
+ nonce: router.options.ssr?.nonce,
558
+ dangerouslySetInnerHTML: { __html: children + ";document.currentScript.remove()" }
559
+ });
560
+ }
561
+ function SafeFragment(props) {
562
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: props.children });
563
+ }
564
+ function renderRouteNotFound(router, route, data) {
565
+ if (!route.options.notFoundComponent) {
566
+ if (router.options.defaultNotFoundComponent) return /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.defaultNotFoundComponent, { ...data });
567
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(DefaultGlobalNotFound, {});
568
+ }
569
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(route.options.notFoundComponent, { ...data });
570
+ }
571
+ function ScrollRestoration() {
572
+ const script = getScrollRestorationScriptForRouter(useRouter());
573
+ if (!script) return null;
574
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(ScriptOnce, { children: script });
575
+ }
576
+ var Match = reactExports.memo(function MatchImpl({ matchId }) {
577
+ const router = useRouter();
578
+ {
579
+ const match2 = router.stores.matchStores.get(matchId)?.get();
580
+ if (!match2) {
581
+ invariant();
582
+ }
583
+ const routeId = match2.routeId;
584
+ const parentRouteId = router.routesById[routeId].parentRoute?.id;
585
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(MatchView, {
586
+ router,
587
+ matchId,
588
+ resetKey: router.stores.loadedAt.get(),
589
+ matchState: {
590
+ routeId,
591
+ ssr: match2.ssr,
592
+ _displayPending: match2._displayPending,
593
+ parentRouteId
594
+ }
595
+ });
596
+ }
597
+ });
598
+ function MatchView({ router, matchId, resetKey, matchState }) {
599
+ const route = router.routesById[matchState.routeId];
600
+ const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent;
601
+ const pendingElement = PendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(PendingComponent, {}) : null;
602
+ const routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent;
603
+ const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch;
604
+ const routeNotFoundComponent = route.isRoot ? route.options.notFoundComponent ?? router.options.notFoundRoute?.options.component : route.options.notFoundComponent;
605
+ const resolvedNoSsr = matchState.ssr === false || matchState.ssr === "data-only";
606
+ const ResolvedSuspenseBoundary = (!route.isRoot || route.options.wrapInSuspense || resolvedNoSsr) && (route.options.wrapInSuspense ?? PendingComponent ?? (route.options.errorComponent?.preload || resolvedNoSsr)) ? reactExports.Suspense : SafeFragment;
607
+ const ResolvedCatchBoundary = routeErrorComponent ? CatchBoundary : SafeFragment;
608
+ const ResolvedNotFoundBoundary = routeNotFoundComponent ? CatchNotFound : SafeFragment;
609
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(route.isRoot ? route.options.shellComponent ?? SafeFragment : SafeFragment, { children: [/* @__PURE__ */ jsxRuntimeExports.jsx(matchContext.Provider, {
610
+ value: matchId,
611
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResolvedSuspenseBoundary, {
612
+ fallback: pendingElement,
613
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResolvedCatchBoundary, {
614
+ getResetKey: () => resetKey,
615
+ errorComponent: routeErrorComponent || ErrorComponent,
616
+ onCatch: (error, errorInfo) => {
617
+ if (isNotFound(error)) {
618
+ error.routeId ??= matchState.routeId;
619
+ throw error;
620
+ }
621
+ routeOnCatch?.(error, errorInfo);
622
+ },
623
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(ResolvedNotFoundBoundary, {
624
+ fallback: (error) => {
625
+ error.routeId ??= matchState.routeId;
626
+ if (!routeNotFoundComponent || error.routeId && error.routeId !== matchState.routeId || !error.routeId && !route.isRoot) throw error;
627
+ return reactExports.createElement(routeNotFoundComponent, error);
628
+ },
629
+ children: resolvedNoSsr || matchState._displayPending ? /* @__PURE__ */ jsxRuntimeExports.jsx(ClientOnly, {
630
+ fallback: pendingElement,
631
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(MatchInner, { matchId })
632
+ }) : /* @__PURE__ */ jsxRuntimeExports.jsx(MatchInner, { matchId })
633
+ })
634
+ })
635
+ })
636
+ }), matchState.parentRouteId === rootRouteId ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [/* @__PURE__ */ jsxRuntimeExports.jsx(OnRendered, {}), router.options.scrollRestoration && isServer ? /* @__PURE__ */ jsxRuntimeExports.jsx(ScrollRestoration, {}) : null] }) : null] });
637
+ }
638
+ function OnRendered() {
639
+ useRouter();
640
+ return null;
641
+ }
642
+ var MatchInner = reactExports.memo(function MatchInnerImpl({ matchId }) {
643
+ const router = useRouter();
644
+ const getMatchPromise = (match2, key2) => {
645
+ return router.getMatch(match2.id)?._nonReactive[key2] ?? match2._nonReactive[key2];
646
+ };
647
+ {
648
+ const match2 = router.stores.matchStores.get(matchId)?.get();
649
+ if (!match2) {
650
+ invariant();
651
+ }
652
+ const routeId2 = match2.routeId;
653
+ const route2 = router.routesById[routeId2];
654
+ const remountDeps = (router.routesById[routeId2].options.remountDeps ?? router.options.defaultRemountDeps)?.({
655
+ routeId: routeId2,
656
+ loaderDeps: match2.loaderDeps,
657
+ params: match2._strictParams,
658
+ search: match2._strictSearch
659
+ });
660
+ const key2 = remountDeps ? JSON.stringify(remountDeps) : void 0;
661
+ const Comp = route2.options.component ?? router.options.defaultComponent;
662
+ const out2 = Comp ? /* @__PURE__ */ jsxRuntimeExports.jsx(Comp, {}, key2) : /* @__PURE__ */ jsxRuntimeExports.jsx(Outlet, {});
663
+ if (match2._displayPending) throw getMatchPromise(match2, "displayPendingPromise");
664
+ if (match2._forcePending) throw getMatchPromise(match2, "minPendingPromise");
665
+ if (match2.status === "pending") throw getMatchPromise(match2, "loadPromise");
666
+ if (match2.status === "notFound") {
667
+ if (!isNotFound(match2.error)) {
668
+ invariant();
669
+ }
670
+ return renderRouteNotFound(router, route2, match2.error);
671
+ }
672
+ if (match2.status === "redirected") {
673
+ if (!isRedirect(match2.error)) {
674
+ invariant();
675
+ }
676
+ throw getMatchPromise(match2, "loadPromise");
677
+ }
678
+ if (match2.status === "error") return /* @__PURE__ */ jsxRuntimeExports.jsx((route2.options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent, {
679
+ error: match2.error,
680
+ reset: void 0,
681
+ info: { componentStack: "" }
682
+ });
683
+ return out2;
684
+ }
685
+ });
686
+ var Outlet = reactExports.memo(function OutletImpl() {
687
+ const router = useRouter();
688
+ const matchId = reactExports.useContext(matchContext);
689
+ let routeId;
690
+ let parentGlobalNotFound = false;
691
+ let childMatchId;
692
+ {
693
+ const matches = router.stores.matches.get();
694
+ const parentIndex = matchId ? matches.findIndex((match) => match.id === matchId) : -1;
695
+ const parentMatch = parentIndex >= 0 ? matches[parentIndex] : void 0;
696
+ routeId = parentMatch?.routeId;
697
+ parentGlobalNotFound = parentMatch?.globalNotFound ?? false;
698
+ childMatchId = parentIndex >= 0 ? matches[parentIndex + 1]?.id : void 0;
699
+ }
700
+ const route = routeId ? router.routesById[routeId] : void 0;
701
+ const pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.defaultPendingComponent, {}) : null;
702
+ if (parentGlobalNotFound) {
703
+ if (!route) {
704
+ invariant();
705
+ }
706
+ return renderRouteNotFound(router, route, void 0);
707
+ }
708
+ if (!childMatchId) return null;
709
+ const nextMatch = /* @__PURE__ */ jsxRuntimeExports.jsx(Match, { matchId: childMatchId });
710
+ if (routeId === rootRouteId) return /* @__PURE__ */ jsxRuntimeExports.jsx(reactExports.Suspense, {
711
+ fallback: pendingElement,
712
+ children: nextMatch
713
+ });
714
+ return nextMatch;
715
+ });
716
+ function Matches() {
717
+ const router = useRouter();
718
+ const PendingComponent = router.routesById[rootRouteId].options.pendingComponent ?? router.options.defaultPendingComponent;
719
+ const pendingElement = PendingComponent ? /* @__PURE__ */ jsxRuntimeExports.jsx(PendingComponent, {}) : null;
720
+ const inner = /* @__PURE__ */ jsxRuntimeExports.jsxs(SafeFragment, {
721
+ fallback: pendingElement,
722
+ children: [false, /* @__PURE__ */ jsxRuntimeExports.jsx(MatchesInner, {})]
723
+ });
724
+ return router.options.InnerWrap ? /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.InnerWrap, { children: inner }) : inner;
725
+ }
726
+ function MatchesInner() {
727
+ const router = useRouter();
728
+ const matchId = router.stores.firstId.get();
729
+ const resetKey = router.stores.loadedAt.get();
730
+ const matchComponent = matchId ? /* @__PURE__ */ jsxRuntimeExports.jsx(Match, { matchId }) : null;
731
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(matchContext.Provider, {
732
+ value: matchId,
733
+ children: router.options.disableGlobalCatchBoundary ? matchComponent : /* @__PURE__ */ jsxRuntimeExports.jsx(CatchBoundary, {
734
+ getResetKey: () => resetKey,
735
+ errorComponent: ErrorComponent,
736
+ onCatch: void 0,
737
+ children: matchComponent
738
+ })
739
+ });
740
+ }
741
+ var getStoreFactory = (opts) => {
742
+ return {
743
+ createMutableStore: createNonReactiveMutableStore,
744
+ createReadonlyStore: createNonReactiveReadonlyStore,
745
+ batch: (fn) => fn()
746
+ };
747
+ };
748
+ var createRouter = (options) => {
1124
749
  return new Router(options);
1125
750
  };
1126
- class Router extends RouterCore {
751
+ var Router = class extends RouterCore {
1127
752
  constructor(options) {
1128
- super(options);
753
+ super(options, getStoreFactory);
1129
754
  }
755
+ };
756
+ function RouterContextProvider({ router, children, ...rest }) {
757
+ if (hasKeys(rest)) router.update({
758
+ ...router.options,
759
+ ...rest,
760
+ context: {
761
+ ...router.options.context,
762
+ ...rest.context
763
+ }
764
+ });
765
+ const provider = /* @__PURE__ */ jsxRuntimeExports.jsx(routerContext.Provider, {
766
+ value: router,
767
+ children
768
+ });
769
+ if (router.options.Wrap) return /* @__PURE__ */ jsxRuntimeExports.jsx(router.options.Wrap, { children: provider });
770
+ return provider;
771
+ }
772
+ function RouterProvider({ router, ...rest }) {
773
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(RouterContextProvider, {
774
+ router,
775
+ ...rest,
776
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(Matches, {})
777
+ });
1130
778
  }
1131
- if (typeof globalThis !== "undefined") {
1132
- globalThis.createFileRoute = createFileRoute;
1133
- globalThis.createLazyFileRoute = createLazyFileRoute;
1134
- } else if (typeof window !== "undefined") {
1135
- window.createFileRoute = createFileRoute;
1136
- window.createLazyFileRoute = createLazyFileRoute;
779
+ var noopScriptHandler = () => {
780
+ };
781
+ function setScriptAttrs(script, attrs) {
782
+ if (!attrs) return;
783
+ for (const [key, value] of Object.entries(attrs)) if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) script.setAttribute(key, typeof value === "boolean" ? "" : String(value));
1137
784
  }
1138
- function Asset({
1139
- tag,
1140
- attrs,
1141
- children,
1142
- nonce
1143
- }) {
1144
- switch (tag) {
785
+ function Asset(asset) {
786
+ const { attrs, children, nonce, preventScriptHoist } = asset;
787
+ switch (asset.tag) {
1145
788
  case "title":
1146
- return /* @__PURE__ */ jsxRuntimeExports.jsx("title", { ...attrs, suppressHydrationWarning: true, children });
789
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("title", {
790
+ ...attrs,
791
+ suppressHydrationWarning: true,
792
+ children
793
+ });
1147
794
  case "meta":
1148
- return /* @__PURE__ */ jsxRuntimeExports.jsx("meta", { ...attrs, suppressHydrationWarning: true });
795
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("meta", {
796
+ ...attrs,
797
+ suppressHydrationWarning: true
798
+ });
1149
799
  case "link":
1150
- return /* @__PURE__ */ jsxRuntimeExports.jsx("link", { ...attrs, nonce, suppressHydrationWarning: true });
800
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("link", {
801
+ ...attrs,
802
+ precedence: attrs?.precedence ?? (attrs?.rel === "stylesheet" ? "default" : void 0),
803
+ nonce,
804
+ suppressHydrationWarning: true
805
+ });
1151
806
  case "style":
1152
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
1153
- "style",
1154
- {
1155
- ...attrs,
1156
- dangerouslySetInnerHTML: { __html: children },
1157
- nonce
1158
- }
1159
- );
807
+ if (asset.inlineCss && false) ;
808
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("style", {
809
+ ...attrs,
810
+ dangerouslySetInnerHTML: { __html: children },
811
+ nonce
812
+ });
1160
813
  case "script":
1161
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Script, { attrs, children });
814
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(Script, {
815
+ attrs,
816
+ preventScriptHoist,
817
+ children
818
+ });
1162
819
  default:
1163
820
  return null;
1164
821
  }
1165
822
  }
1166
- function Script({
1167
- attrs,
1168
- children
1169
- }) {
823
+ function Script({ attrs, children, preventScriptHoist }) {
1170
824
  useRouter();
1171
825
  useHydrated();
1172
826
  const dataScript = typeof attrs?.type === "string" && attrs.type !== "" && attrs.type !== "text/javascript" && attrs.type !== "module";
@@ -1181,291 +835,333 @@ function Script({
1181
835
  return attrs.src;
1182
836
  }
1183
837
  })();
1184
- const existingScript = Array.from(
1185
- document.querySelectorAll("script[src]")
1186
- ).find((el) => el.src === normSrc);
1187
- if (existingScript) {
1188
- return;
1189
- }
838
+ for (const el of document.querySelectorAll("script[src]")) if (el.src === normSrc) return;
1190
839
  const script = document.createElement("script");
1191
- for (const [key, value] of Object.entries(attrs)) {
1192
- if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) {
1193
- script.setAttribute(
1194
- key,
1195
- typeof value === "boolean" ? "" : String(value)
1196
- );
1197
- }
1198
- }
840
+ setScriptAttrs(script, attrs);
1199
841
  document.head.appendChild(script);
1200
- return () => {
1201
- if (script.parentNode) {
1202
- script.parentNode.removeChild(script);
1203
- }
1204
- };
842
+ return () => script.remove();
1205
843
  }
1206
844
  if (typeof children === "string") {
1207
845
  const typeAttr = typeof attrs?.type === "string" ? attrs.type : "text/javascript";
1208
846
  const nonceAttr = typeof attrs?.nonce === "string" ? attrs.nonce : void 0;
1209
- const existingScript = Array.from(
1210
- document.querySelectorAll("script:not([src])")
1211
- ).find((el) => {
1212
- if (!(el instanceof HTMLScriptElement)) return false;
847
+ for (const el of document.querySelectorAll("script:not([src])")) {
848
+ if (!(el instanceof HTMLScriptElement)) continue;
1213
849
  const sType = el.getAttribute("type") ?? "text/javascript";
1214
850
  const sNonce = el.getAttribute("nonce") ?? void 0;
1215
- return el.textContent === children && sType === typeAttr && sNonce === nonceAttr;
1216
- });
1217
- if (existingScript) {
1218
- return;
851
+ if (el.textContent === children && sType === typeAttr && sNonce === nonceAttr) return;
1219
852
  }
1220
853
  const script = document.createElement("script");
1221
854
  script.textContent = children;
1222
- if (attrs) {
1223
- for (const [key, value] of Object.entries(attrs)) {
1224
- if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) {
1225
- script.setAttribute(
1226
- key,
1227
- typeof value === "boolean" ? "" : String(value)
1228
- );
1229
- }
1230
- }
1231
- }
855
+ setScriptAttrs(script, attrs);
1232
856
  document.head.appendChild(script);
1233
- return () => {
1234
- if (script.parentNode) {
1235
- script.parentNode.removeChild(script);
1236
- }
1237
- };
857
+ return () => script.remove();
1238
858
  }
1239
- return void 0;
1240
- }, [attrs, children, dataScript]);
859
+ }, [
860
+ attrs,
861
+ children,
862
+ dataScript
863
+ ]);
1241
864
  {
1242
865
  if (attrs?.src) {
1243
- return /* @__PURE__ */ jsxRuntimeExports.jsx("script", { ...attrs, suppressHydrationWarning: true });
1244
- }
1245
- if (typeof children === "string") {
1246
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
1247
- "script",
1248
- {
1249
- ...attrs,
1250
- dangerouslySetInnerHTML: { __html: children },
1251
- suppressHydrationWarning: true
1252
- }
1253
- );
866
+ if (!preventScriptHoist) return /* @__PURE__ */ jsxRuntimeExports.jsx("script", {
867
+ ...attrs,
868
+ suppressHydrationWarning: true
869
+ });
870
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("script", {
871
+ ...attrs,
872
+ onLoad: noopScriptHandler,
873
+ suppressHydrationWarning: true
874
+ });
1254
875
  }
876
+ if (typeof children === "string") return /* @__PURE__ */ jsxRuntimeExports.jsx("script", {
877
+ ...attrs,
878
+ dangerouslySetInnerHTML: { __html: children },
879
+ suppressHydrationWarning: true
880
+ });
1255
881
  return null;
1256
882
  }
1257
883
  }
1258
- const useTags = () => {
1259
- const router = useRouter();
1260
- const nonce = router.options.ssr?.nonce;
1261
- const routeMeta = useRouterState({
1262
- select: (state) => {
1263
- return state.matches.map((match) => match.meta).filter(Boolean);
1264
- }
1265
- });
1266
- const meta = reactExports.useMemo(() => {
1267
- const resultMeta = [];
1268
- const metaByAttribute = {};
1269
- let title;
1270
- for (let i = routeMeta.length - 1; i >= 0; i--) {
1271
- const metas = routeMeta[i];
1272
- for (let j = metas.length - 1; j >= 0; j--) {
1273
- const m = metas[j];
1274
- if (!m) continue;
1275
- if (m.title) {
1276
- if (!title) {
1277
- title = {
1278
- tag: "title",
1279
- children: m.title
1280
- };
1281
- }
1282
- } else if ("script:ld+json" in m) {
1283
- try {
1284
- const json = JSON.stringify(m["script:ld+json"]);
1285
- resultMeta.push({
1286
- tag: "script",
1287
- attrs: {
1288
- type: "application/ld+json"
1289
- },
1290
- children: escapeHtml(json)
1291
- });
1292
- } catch {
1293
- }
1294
- } else {
1295
- const attribute = m.name ?? m.property;
1296
- if (attribute) {
1297
- if (metaByAttribute[attribute]) {
1298
- continue;
1299
- } else {
1300
- metaByAttribute[attribute] = true;
1301
- }
884
+ function buildTagsFromMatches(router, nonce, matches, assetCrossOrigin) {
885
+ const routeMeta = matches.map((match) => match.meta).filter((meta) => meta !== void 0);
886
+ const resultMeta = [];
887
+ const metaByAttribute = {};
888
+ let title;
889
+ for (let i = routeMeta.length - 1; i >= 0; i--) {
890
+ const metas = routeMeta[i];
891
+ for (let j = metas.length - 1; j >= 0; j--) {
892
+ const m = metas[j];
893
+ if (!m) continue;
894
+ if (m.title) {
895
+ if (!title) title = {
896
+ tag: "title",
897
+ children: m.title
898
+ };
899
+ } else if ("script:ld+json" in m) try {
900
+ const json = JSON.stringify(m["script:ld+json"]);
901
+ resultMeta.push({
902
+ tag: "script",
903
+ attrs: { type: "application/ld+json" },
904
+ children: escapeHtml(json)
905
+ });
906
+ } catch {
907
+ }
908
+ else {
909
+ const attribute = m.name ?? m.property;
910
+ if (attribute) if (metaByAttribute[attribute]) continue;
911
+ else metaByAttribute[attribute] = true;
912
+ resultMeta.push({
913
+ tag: "meta",
914
+ attrs: {
915
+ ...m,
916
+ nonce
1302
917
  }
1303
- resultMeta.push({
1304
- tag: "meta",
1305
- attrs: {
1306
- ...m,
1307
- nonce
1308
- }
1309
- });
1310
- }
918
+ });
1311
919
  }
1312
920
  }
1313
- if (title) {
1314
- resultMeta.push(title);
921
+ }
922
+ if (title) resultMeta.push(title);
923
+ if (nonce) resultMeta.push({
924
+ tag: "meta",
925
+ attrs: {
926
+ property: "csp-nonce",
927
+ content: nonce
1315
928
  }
1316
- if (nonce) {
1317
- resultMeta.push({
1318
- tag: "meta",
1319
- attrs: {
1320
- property: "csp-nonce",
1321
- content: nonce
1322
- }
1323
- });
929
+ });
930
+ resultMeta.reverse();
931
+ const constructedLinks = matches.flatMap((match) => match.links ?? []).filter((link) => link !== void 0).map((link) => ({
932
+ tag: "link",
933
+ attrs: {
934
+ ...link,
935
+ nonce
1324
936
  }
1325
- resultMeta.reverse();
1326
- return resultMeta;
1327
- }, [routeMeta, nonce]);
1328
- const links = useRouterState({
1329
- select: (state) => {
1330
- const constructed = state.matches.map((match) => match.links).filter(Boolean).flat(1).map((link) => ({
1331
- tag: "link",
1332
- attrs: {
1333
- ...link,
1334
- nonce
1335
- }
1336
- }));
1337
- const manifest = router.ssr?.manifest;
1338
- const assets = state.matches.map((match) => manifest?.routes[match.routeId]?.assets ?? []).filter(Boolean).flat(1).filter((asset) => asset.tag === "link").map(
1339
- (asset) => ({
937
+ }));
938
+ const manifest = router.ssr?.manifest;
939
+ const manifestCssTags = [];
940
+ if (manifest) {
941
+ matches.forEach((match) => {
942
+ manifest.routes[match.routeId]?.css?.forEach((link) => {
943
+ const resolvedLink = resolveManifestCssLink(link);
944
+ manifestCssTags.push({
1340
945
  tag: "link",
1341
946
  attrs: {
1342
- ...asset.attrs,
947
+ rel: "stylesheet",
948
+ ...resolvedLink,
949
+ crossOrigin: getAssetCrossOrigin(assetCrossOrigin, "stylesheet") ?? resolvedLink.crossOrigin,
1343
950
  suppressHydrationWarning: true,
1344
951
  nonce
1345
952
  }
1346
- })
1347
- );
1348
- return [...constructed, ...assets];
1349
- },
1350
- structuralSharing: true
1351
- });
1352
- const preloadLinks = useRouterState({
1353
- select: (state) => {
1354
- const preloadLinks2 = [];
1355
- state.matches.map((match) => router.looseRoutesById[match.routeId]).forEach(
1356
- (route) => router.ssr?.manifest?.routes[route.id]?.preloads?.filter(Boolean).forEach((preload) => {
1357
- preloadLinks2.push({
1358
- tag: "link",
1359
- attrs: {
1360
- rel: "modulepreload",
1361
- href: preload,
1362
- nonce
1363
- }
1364
- });
1365
- })
1366
- );
1367
- return preloadLinks2;
1368
- },
1369
- structuralSharing: true
1370
- });
1371
- const styles = useRouterState({
1372
- select: (state) => state.matches.map((match) => match.styles).flat(1).filter(Boolean).map(({ children, ...attrs }) => ({
953
+ });
954
+ });
955
+ });
956
+ if (manifest.inlineStyle) manifestCssTags.push({
1373
957
  tag: "style",
1374
958
  attrs: {
1375
- ...attrs,
959
+ ...manifest.inlineStyle.attrs,
1376
960
  nonce
1377
961
  },
1378
- children
1379
- })),
1380
- structuralSharing: true
1381
- });
1382
- const headScripts = useRouterState({
1383
- select: (state) => state.matches.map((match) => match.headScripts).flat(1).filter(Boolean).map(({ children, ...script }) => ({
1384
- tag: "script",
1385
- attrs: {
1386
- ...script,
1387
- nonce
1388
- },
1389
- children
1390
- })),
1391
- structuralSharing: true
1392
- });
1393
- return uniqBy(
1394
- [
1395
- ...meta,
1396
- ...preloadLinks,
1397
- ...links,
1398
- ...styles,
1399
- ...headScripts
1400
- ],
1401
- (d) => {
1402
- return JSON.stringify(d);
1403
- }
1404
- );
1405
- };
1406
- function uniqBy(arr, fn) {
1407
- const seen = /* @__PURE__ */ new Set();
1408
- return arr.filter((item) => {
1409
- const key = fn(item);
1410
- if (seen.has(key)) {
1411
- return false;
1412
- }
1413
- seen.add(key);
1414
- return true;
962
+ children: manifest.inlineStyle.children,
963
+ inlineCss: true
964
+ });
965
+ }
966
+ const preloadLinks = [];
967
+ if (manifest) matches.forEach((match) => {
968
+ manifest.routes[match.routeId]?.preloads?.forEach((preload) => {
969
+ preloadLinks.push({
970
+ tag: "link",
971
+ attrs: {
972
+ ...getScriptPreloadAttrs(manifest, preload, assetCrossOrigin),
973
+ nonce
974
+ }
975
+ });
976
+ });
1415
977
  });
978
+ const styles = matches.flatMap((match) => match.styles ?? []).filter((style) => style !== void 0).map(({ children, ...attrs }) => ({
979
+ tag: "style",
980
+ attrs: {
981
+ ...attrs,
982
+ nonce
983
+ },
984
+ children
985
+ }));
986
+ const headScripts = matches.flatMap((match) => match.headScripts ?? []).filter((script) => script !== void 0).map(({ children, ...script }) => ({
987
+ tag: "script",
988
+ attrs: {
989
+ ...script,
990
+ nonce
991
+ },
992
+ children
993
+ }));
994
+ const tags = [];
995
+ appendUniqueUserTags(tags, resultMeta);
996
+ tags.push(...preloadLinks);
997
+ appendUniqueUserTags(tags, constructedLinks);
998
+ tags.push(...manifestCssTags);
999
+ appendUniqueUserTags(tags, styles);
1000
+ appendUniqueUserTags(tags, headScripts);
1001
+ return tags;
1416
1002
  }
1417
- function HeadContent() {
1418
- const tags = useTags();
1003
+ var useTags = (assetCrossOrigin) => {
1419
1004
  const router = useRouter();
1420
1005
  const nonce = router.options.ssr?.nonce;
1421
- return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: tags.map((tag) => /* @__PURE__ */ reactExports.createElement(Asset, { ...tag, key: `tsr-meta-${JSON.stringify(tag)}`, nonce })) });
1006
+ return buildTagsFromMatches(router, nonce, router.stores.matches.get(), assetCrossOrigin);
1007
+ };
1008
+ function HeadContent(props) {
1009
+ const tags = useTags(props.assetCrossOrigin);
1010
+ const nonce = useRouter().options.ssr?.nonce;
1011
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: tags.map((tag) => /* @__PURE__ */ reactExports.createElement(Asset, {
1012
+ ...tag,
1013
+ key: `tsr-meta-${JSON.stringify(tag)}`,
1014
+ nonce
1015
+ })) });
1422
1016
  }
1423
- const Scripts = () => {
1017
+ var Scripts = () => {
1424
1018
  const router = useRouter();
1425
1019
  const nonce = router.options.ssr?.nonce;
1426
- const assetScripts = useRouterState({
1427
- select: (state) => {
1428
- const assetScripts2 = [];
1429
- const manifest = router.ssr?.manifest;
1430
- if (!manifest) {
1431
- return [];
1432
- }
1433
- state.matches.map((match) => router.looseRoutesById[match.routeId]).forEach(
1434
- (route) => manifest.routes[route.id]?.assets?.filter((d) => d.tag === "script").forEach((asset) => {
1435
- assetScripts2.push({
1436
- tag: "script",
1437
- attrs: { ...asset.attrs, nonce },
1438
- children: asset.children
1439
- });
1440
- })
1441
- );
1442
- return assetScripts2;
1443
- },
1444
- structuralSharing: true
1445
- });
1446
- const { scripts } = useRouterState({
1447
- select: (state) => ({
1448
- scripts: state.matches.map((match) => match.scripts).flat(1).filter(Boolean).map(({ children, ...script }) => ({
1020
+ const getAssetScripts = (matches) => {
1021
+ const assetScripts = [];
1022
+ const manifest = router.ssr?.manifest;
1023
+ if (!manifest) return [];
1024
+ for (const match of matches) {
1025
+ const scripts = manifest.routes[match.routeId]?.scripts;
1026
+ if (!scripts) continue;
1027
+ for (const asset of scripts) assetScripts.push({
1449
1028
  tag: "script",
1450
1029
  attrs: {
1451
- ...script,
1452
- suppressHydrationWarning: true,
1030
+ ...asset.attrs,
1453
1031
  nonce
1454
1032
  },
1455
- children
1456
- }))
1457
- }),
1458
- structuralSharing: true
1459
- });
1460
- let serverBufferedScript = void 0;
1461
- if (router.serverSsr) {
1462
- serverBufferedScript = router.serverSsr.takeBufferedScripts();
1033
+ children: asset.children,
1034
+ ...typeof asset.attrs?.src === "string" ? { preventScriptHoist: true } : {}
1035
+ });
1036
+ }
1037
+ return assetScripts;
1038
+ };
1039
+ const getScripts = (matches) => matches.map((match) => match.scripts).flat(1).filter(Boolean).map(({ children, ...script }) => ({
1040
+ tag: "script",
1041
+ attrs: {
1042
+ ...script,
1043
+ suppressHydrationWarning: true,
1044
+ nonce
1045
+ },
1046
+ children
1047
+ }));
1048
+ {
1049
+ const activeMatches = router.stores.matches.get();
1050
+ const assetScripts = getAssetScripts(activeMatches);
1051
+ return renderScripts(router, getScripts(activeMatches), assetScripts);
1463
1052
  }
1053
+ };
1054
+ function renderScripts(router, scripts, assetScripts) {
1464
1055
  const allScripts = [...scripts, ...assetScripts];
1465
- if (serverBufferedScript) {
1466
- allScripts.unshift(serverBufferedScript);
1056
+ if (router.serverSsr) {
1057
+ const serverBufferedScript = router.serverSsr.takeBufferedScripts();
1058
+ if (serverBufferedScript) allScripts.unshift(serverBufferedScript);
1059
+ }
1060
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: allScripts.map((asset, i) => /* @__PURE__ */ reactExports.createElement(Asset, {
1061
+ ...asset,
1062
+ key: `tsr-scripts-${asset.tag}-${i}`
1063
+ })) });
1064
+ }
1065
+ var noop = () => {
1066
+ };
1067
+ async function waitForReadyOrAbort(ready, signal) {
1068
+ let cleanup = noop;
1069
+ try {
1070
+ await Promise.race([ready, new Promise((resolve) => {
1071
+ const onAbort = () => resolve();
1072
+ cleanup = () => signal.removeEventListener("abort", onAbort);
1073
+ signal.addEventListener("abort", onAbort, { once: true });
1074
+ if (signal.aborted) resolve();
1075
+ })]);
1076
+ } finally {
1077
+ cleanup();
1078
+ }
1079
+ }
1080
+ var isAbortError = (request, error) => request.signal.aborted && error === request.signal.reason || error instanceof Error && error.name === "AbortError";
1081
+ var renderRouterToStream = async ({ request, router, responseHeaders, children }) => {
1082
+ if (typeof ReactDOMServer.renderToReadableStream === "function") {
1083
+ const stream = await ReactDOMServer.renderToReadableStream(children, {
1084
+ signal: request.signal,
1085
+ nonce: router.options.ssr?.nonce,
1086
+ progressiveChunkSize: Number.POSITIVE_INFINITY,
1087
+ onError: (error, info) => {
1088
+ if (!isAbortError(request, error)) console.error("Error in renderToReadableStream:", error, info);
1089
+ }
1090
+ });
1091
+ if (isbot(request.headers.get("User-Agent"))) await waitForReadyOrAbort(stream.allReady, request.signal);
1092
+ const responseStream = transformReadableStreamWithRouter(router, stream, { onAbort: () => stream.cancel().catch(() => {
1093
+ }) });
1094
+ return createSsrStreamResponse(router, new Response(responseStream, {
1095
+ status: router.stores.statusCode.get(),
1096
+ headers: responseHeaders
1097
+ }));
1098
+ }
1099
+ if (typeof ReactDOMServer.renderToPipeableStream === "function") {
1100
+ const reactAppPassthrough = new PassThrough();
1101
+ let pipeable;
1102
+ let responseAttached = false;
1103
+ let aborted = false;
1104
+ let endedBeforeAttach = false;
1105
+ let pendingAbortReason;
1106
+ const toError = (reason) => reason instanceof Error ? reason : new Error(String(reason ?? "SSR aborted"));
1107
+ const destroyError = (reason) => reason === void 0 ? void 0 : toError(reason);
1108
+ const pendingDestroyError = () => pendingAbortReason === void 0 ? toError(pendingAbortReason) : destroyError(pendingAbortReason);
1109
+ const finishPassThrough = (reason, opts) => {
1110
+ if (reactAppPassthrough.destroyed) return;
1111
+ if (responseAttached) reactAppPassthrough.destroy(opts?.defaultError ? toError(reason) : destroyError(reason));
1112
+ else endedBeforeAttach = true;
1113
+ };
1114
+ const abortPipeable = (reason, opts) => {
1115
+ if (aborted) return;
1116
+ aborted = true;
1117
+ pendingAbortReason = reason;
1118
+ const err = toError(reason);
1119
+ try {
1120
+ pipeable?.abort(err);
1121
+ } catch {
1122
+ }
1123
+ finishPassThrough(reason, opts);
1124
+ };
1125
+ if (request.signal.aborted) abortPipeable(request.signal.reason);
1126
+ else {
1127
+ const onRequestAbort = () => abortPipeable(request.signal.reason);
1128
+ request.signal.addEventListener("abort", onRequestAbort, { once: true });
1129
+ router.serverSsr?.onCleanup(() => {
1130
+ request.signal.removeEventListener("abort", onRequestAbort);
1131
+ });
1132
+ }
1133
+ try {
1134
+ pipeable = ReactDOMServer.renderToPipeableStream(children, {
1135
+ nonce: router.options.ssr?.nonce,
1136
+ progressiveChunkSize: Number.POSITIVE_INFINITY,
1137
+ ...isbot(request.headers.get("User-Agent")) ? { onAllReady() {
1138
+ pipeable.pipe(reactAppPassthrough);
1139
+ } } : { onShellReady() {
1140
+ pipeable.pipe(reactAppPassthrough);
1141
+ } },
1142
+ onError: (error, info) => {
1143
+ if (!isAbortError(request, error)) console.error("Error in renderToPipeableStream:", error, info);
1144
+ abortPipeable(error, { defaultError: true });
1145
+ }
1146
+ });
1147
+ } catch (e) {
1148
+ console.error("Error in renderToPipeableStream:", e);
1149
+ router.serverSsr?.cleanup();
1150
+ throw e;
1151
+ }
1152
+ const responseStream = transformPipeableStreamWithRouter(router, reactAppPassthrough, { onAbort: abortPipeable });
1153
+ responseAttached = true;
1154
+ if (endedBeforeAttach) reactAppPassthrough.destroy(pendingDestroyError());
1155
+ if (aborted && pipeable) try {
1156
+ pipeable.abort(toError(pendingAbortReason));
1157
+ } catch {
1158
+ }
1159
+ return createSsrStreamResponse(router, new Response(responseStream, {
1160
+ status: router.stores.statusCode.get(),
1161
+ headers: responseHeaders
1162
+ }));
1467
1163
  }
1468
- return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: allScripts.map((asset, i) => /* @__PURE__ */ reactExports.createElement(Asset, { ...asset, key: `tsr-scripts-${asset.tag}-${i}` })) });
1164
+ throw new Error("No renderToReadableStream or renderToPipeableStream found in react-dom/server. Ensure you are using a version of react-dom that supports streaming.");
1469
1165
  };
1470
1166
  export {
1471
1167
  HeadContent as H,