react-router 0.0.0-experimental-e0b6ce9 → 0.0.0-experimental-de3b900

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 (76) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/dist/development/browser-B4aBBnx8.d.ts +310 -0
  3. package/dist/development/browser-CN2w9Cbu.d.mts +310 -0
  4. package/dist/development/{chunk-4FI4BC6Y.mjs → chunk-5VDQAMOM.mjs} +181 -873
  5. package/dist/development/chunk-JEIV2ESS.js +1308 -0
  6. package/dist/development/{chunk-INO4IHBF.js → chunk-K3XLKYJI.js} +892 -409
  7. package/dist/development/{chunk-F6CT5MEB.mjs → chunk-OVO62ONG.mjs} +31 -314
  8. package/dist/development/chunk-UPBUMW2M.js +188 -0
  9. package/dist/development/dom-export.d.mts +51 -61
  10. package/dist/development/dom-export.d.ts +51 -60
  11. package/dist/development/dom-export.js +705 -23
  12. package/dist/development/dom-export.mjs +689 -14
  13. package/dist/{production/index-react-server-client-CYIi6gi0.d.mts → development/index-react-server-client-BOJoTiaG.d.ts} +76 -140
  14. package/dist/development/{index-react-server-client-CYIi6gi0.d.mts → index-react-server-client-CuQLmpku.d.mts} +76 -140
  15. package/dist/development/index-react-server-client.d.mts +2 -3
  16. package/dist/development/index-react-server-client.d.ts +2 -3
  17. package/dist/development/index-react-server-client.js +4 -4
  18. package/dist/development/index-react-server-client.mjs +2 -2
  19. package/dist/development/index-react-server.d.mts +1 -90
  20. package/dist/development/index-react-server.d.ts +1 -90
  21. package/dist/development/index-react-server.js +9 -188
  22. package/dist/development/index-react-server.mjs +9 -188
  23. package/dist/development/index.d.mts +21 -320
  24. package/dist/development/index.d.ts +21 -364
  25. package/dist/development/index.js +131 -977
  26. package/dist/development/index.mjs +5 -9
  27. package/dist/development/lib/types/internal.d.mts +2 -3
  28. package/dist/development/lib/types/internal.d.ts +2 -3
  29. package/dist/development/lib/types/internal.js +1 -1
  30. package/dist/development/lib/types/internal.mjs +1 -1
  31. package/dist/{production/register-DiOIlEq5.d.mts → development/register-BblEgJPm.d.mts} +7 -1
  32. package/dist/development/{register-DiOIlEq5.d.ts → register-D18raRVf.d.ts} +7 -1
  33. package/dist/development/{router-DWv6Clt-.d.mts → route-data-nQS6GSUI.d.mts} +1265 -932
  34. package/dist/development/{routeModules-DqotkItD.d.ts → routeModules-9wlxglVk.d.ts} +1047 -74
  35. package/dist/production/browser-B4aBBnx8.d.ts +310 -0
  36. package/dist/production/browser-CN2w9Cbu.d.mts +310 -0
  37. package/dist/production/{chunk-K7VXYOZD.js → chunk-63YB5VLY.js} +892 -409
  38. package/dist/production/chunk-IE722GR6.js +188 -0
  39. package/dist/production/{chunk-LKSLGWXX.mjs → chunk-U25H5FTL.mjs} +31 -314
  40. package/dist/production/chunk-VX4OHTGR.js +1308 -0
  41. package/dist/production/{chunk-52MYED7O.mjs → chunk-XOCFS75J.mjs} +181 -873
  42. package/dist/production/dom-export.d.mts +51 -61
  43. package/dist/production/dom-export.d.ts +51 -60
  44. package/dist/production/dom-export.js +705 -23
  45. package/dist/production/dom-export.mjs +689 -14
  46. package/dist/production/{index-react-server-client-ChBGplLn.d.ts → index-react-server-client-BOJoTiaG.d.ts} +76 -140
  47. package/dist/{development/index-react-server-client-ChBGplLn.d.ts → production/index-react-server-client-CuQLmpku.d.mts} +76 -140
  48. package/dist/production/index-react-server-client.d.mts +2 -3
  49. package/dist/production/index-react-server-client.d.ts +2 -3
  50. package/dist/production/index-react-server-client.js +4 -4
  51. package/dist/production/index-react-server-client.mjs +2 -2
  52. package/dist/production/index-react-server.d.mts +1 -90
  53. package/dist/production/index-react-server.d.ts +1 -90
  54. package/dist/production/index-react-server.js +9 -188
  55. package/dist/production/index-react-server.mjs +9 -188
  56. package/dist/production/index.d.mts +21 -320
  57. package/dist/production/index.d.ts +21 -364
  58. package/dist/production/index.js +131 -977
  59. package/dist/production/index.mjs +5 -9
  60. package/dist/production/lib/types/internal.d.mts +2 -3
  61. package/dist/production/lib/types/internal.d.ts +2 -3
  62. package/dist/production/lib/types/internal.js +1 -1
  63. package/dist/production/lib/types/internal.mjs +1 -1
  64. package/dist/{development/register-DiOIlEq5.d.mts → production/register-BblEgJPm.d.mts} +7 -1
  65. package/dist/production/{register-DiOIlEq5.d.ts → register-D18raRVf.d.ts} +7 -1
  66. package/dist/production/{router-DWv6Clt-.d.mts → route-data-nQS6GSUI.d.mts} +1265 -932
  67. package/dist/production/{routeModules-DqotkItD.d.ts → routeModules-9wlxglVk.d.ts} +1047 -74
  68. package/package.json +1 -1
  69. package/dist/development/browser-z32v5KVN.d.mts +0 -46
  70. package/dist/development/chunk-ITZFCV4J.js +0 -2092
  71. package/dist/development/instrumentation-BGrNA7uj.d.ts +0 -1122
  72. package/dist/development/routeModules-Cy4Xsfoi.d.mts +0 -483
  73. package/dist/production/browser-z32v5KVN.d.mts +0 -46
  74. package/dist/production/chunk-DASXXYNZ.js +0 -2092
  75. package/dist/production/instrumentation-BGrNA7uj.d.ts +0 -1122
  76. package/dist/production/routeModules-Cy4Xsfoi.d.mts +0 -483
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
2
- * react-router v0.0.0-experimental-e0b6ce9
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
2
+ * react-router v0.0.0-experimental-de3b900
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -11,11 +11,32 @@
11
11
  "use client";
12
12
 
13
13
 
14
- var _chunkINO4IHBFjs = require('./chunk-INO4IHBF.js');
14
+
15
+
16
+ var _chunkUPBUMW2Mjs = require('./chunk-UPBUMW2M.js');
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+ var _chunkK3XLKYJIjs = require('./chunk-K3XLKYJI.js');
15
36
 
16
37
  // lib/dom-export/dom-router-provider.tsx
17
- var _react = require('react'); var React = _interopRequireWildcard(_react); var React2 = _interopRequireWildcard(_react);
18
- var _reactdom = require('react-dom'); var ReactDOM = _interopRequireWildcard(_reactdom);
38
+ var _react = require('react'); var React = _interopRequireWildcard(_react); var React2 = _interopRequireWildcard(_react); var React3 = _interopRequireWildcard(_react);
39
+ var _reactdom = require('react-dom'); var ReactDOM = _interopRequireWildcard(_reactdom); var ReactDOM2 = _interopRequireWildcard(_reactdom);
19
40
  var _reactrouter = require('react-router');
20
41
  function RouterProvider(props) {
21
42
  return /* @__PURE__ */ React.createElement(_reactrouter.RouterProvider, { flushSync: ReactDOM.flushSync, ...props });
@@ -46,7 +67,7 @@ function initSsrInfo() {
46
67
  if (!ssrInfo && window.__reactRouterContext && window.__reactRouterManifest && window.__reactRouterRouteModules) {
47
68
  if (window.__reactRouterManifest.sri === true) {
48
69
  const importMap = document.querySelector("script[rr-importmap]");
49
- if (_optionalChain([importMap, 'optionalAccess', _ => _.textContent])) {
70
+ if (_optionalChain([importMap, 'optionalAccess', _2 => _2.textContent])) {
50
71
  try {
51
72
  window.__reactRouterManifest.sri = JSON.parse(
52
73
  importMap.textContent
@@ -67,8 +88,7 @@ function initSsrInfo() {
67
88
  }
68
89
  }
69
90
  function createHydratedRouter({
70
- getContext,
71
- unstable_instrumentations
91
+ getContext
72
92
  }) {
73
93
  initSsrInfo();
74
94
  if (!ssrInfo) {
@@ -104,7 +124,7 @@ function createHydratedRouter({
104
124
  let hydrationData = void 0;
105
125
  if (ssrInfo.context.isSpaMode) {
106
126
  let { loaderData } = ssrInfo.context.state;
107
- if (_optionalChain([ssrInfo, 'access', _2 => _2.manifest, 'access', _3 => _3.routes, 'access', _4 => _4.root, 'optionalAccess', _5 => _5.hasLoader]) && loaderData && "root" in loaderData) {
127
+ if (_optionalChain([ssrInfo, 'access', _3 => _3.manifest, 'access', _4 => _4.routes, 'access', _5 => _5.root, 'optionalAccess', _6 => _6.hasLoader]) && loaderData && "root" in loaderData) {
108
128
  hydrationData = {
109
129
  loaderData: {
110
130
  root: loaderData.root
@@ -116,12 +136,12 @@ function createHydratedRouter({
116
136
  state: ssrInfo.context.state,
117
137
  routes,
118
138
  getRouteInfo: (routeId) => ({
119
- clientLoader: _optionalChain([ssrInfo, 'access', _6 => _6.routeModules, 'access', _7 => _7[routeId], 'optionalAccess', _8 => _8.clientLoader]),
120
- hasLoader: _optionalChain([ssrInfo, 'access', _9 => _9.manifest, 'access', _10 => _10.routes, 'access', _11 => _11[routeId], 'optionalAccess', _12 => _12.hasLoader]) === true,
121
- hasHydrateFallback: _optionalChain([ssrInfo, 'access', _13 => _13.routeModules, 'access', _14 => _14[routeId], 'optionalAccess', _15 => _15.HydrateFallback]) != null
139
+ clientLoader: _optionalChain([ssrInfo, 'access', _7 => _7.routeModules, 'access', _8 => _8[routeId], 'optionalAccess', _9 => _9.clientLoader]),
140
+ hasLoader: _optionalChain([ssrInfo, 'access', _10 => _10.manifest, 'access', _11 => _11.routes, 'access', _12 => _12[routeId], 'optionalAccess', _13 => _13.hasLoader]) === true,
141
+ hasHydrateFallback: _optionalChain([ssrInfo, 'access', _14 => _14.routeModules, 'access', _15 => _15[routeId], 'optionalAccess', _16 => _16.HydrateFallback]) != null
122
142
  }),
123
143
  location: window.location,
124
- basename: _optionalChain([window, 'access', _16 => _16.__reactRouterContext, 'optionalAccess', _17 => _17.basename]),
144
+ basename: _optionalChain([window, 'access', _17 => _17.__reactRouterContext, 'optionalAccess', _18 => _18.basename]),
125
145
  isSpaMode: ssrInfo.context.isSpaMode
126
146
  });
127
147
  if (hydrationData && hydrationData.errors) {
@@ -135,7 +155,6 @@ function createHydratedRouter({
135
155
  getContext,
136
156
  hydrationData,
137
157
  hydrationRouteProperties: _reactrouter.UNSAFE_hydrationRouteProperties,
138
- unstable_instrumentations,
139
158
  mapRouteProperties: _reactrouter.UNSAFE_mapRouteProperties,
140
159
  future: {
141
160
  middleware: ssrInfo.context.future.v8_middleware
@@ -169,12 +188,11 @@ function createHydratedRouter({
169
188
  function HydratedRouter(props) {
170
189
  if (!router) {
171
190
  router = createHydratedRouter({
172
- getContext: props.getContext,
173
- unstable_instrumentations: props.unstable_instrumentations
191
+ getContext: props.getContext
174
192
  });
175
193
  }
176
194
  let [criticalCss, setCriticalCss] = React2.useState(
177
- process.env.NODE_ENV === "development" ? _optionalChain([ssrInfo, 'optionalAccess', _18 => _18.context, 'access', _19 => _19.criticalCss]) : void 0
195
+ process.env.NODE_ENV === "development" ? _optionalChain([ssrInfo, 'optionalAccess', _19 => _19.context, 'access', _20 => _20.criticalCss]) : void 0
178
196
  );
179
197
  React2.useEffect(() => {
180
198
  if (process.env.NODE_ENV === "development") {
@@ -183,10 +201,10 @@ function HydratedRouter(props) {
183
201
  }, []);
184
202
  React2.useEffect(() => {
185
203
  if (process.env.NODE_ENV === "development" && criticalCss === void 0) {
186
- document.querySelectorAll(`[${_chunkINO4IHBFjs.CRITICAL_CSS_DATA_ATTRIBUTE}]`).forEach((element) => element.remove());
204
+ document.querySelectorAll(`[${_chunkK3XLKYJIjs.CRITICAL_CSS_DATA_ATTRIBUTE}]`).forEach((element) => element.remove());
187
205
  }
188
206
  }, [criticalCss]);
189
- let [location, setLocation] = React2.useState(router.state.location);
207
+ let [location2, setLocation] = React2.useState(router.state.location);
190
208
  React2.useLayoutEffect(() => {
191
209
  if (ssrInfo && ssrInfo.router && !ssrInfo.routerInitialized) {
192
210
  ssrInfo.routerInitialized = true;
@@ -196,12 +214,12 @@ function HydratedRouter(props) {
196
214
  React2.useLayoutEffect(() => {
197
215
  if (ssrInfo && ssrInfo.router) {
198
216
  return ssrInfo.router.subscribe((newState) => {
199
- if (newState.location !== location) {
217
+ if (newState.location !== location2) {
200
218
  setLocation(newState.location);
201
219
  }
202
220
  });
203
221
  }
204
- }, [location]);
222
+ }, [location2]);
205
223
  _reactrouter.UNSAFE_invariant.call(void 0, ssrInfo, "ssrInfo unavailable for HydratedRouter");
206
224
  _reactrouter.UNSAFE_useFogOFWarDiscovery.call(void 0,
207
225
  router,
@@ -227,7 +245,7 @@ function HydratedRouter(props) {
227
245
  routeDiscovery: ssrInfo.context.routeDiscovery
228
246
  }
229
247
  },
230
- /* @__PURE__ */ React2.createElement(_reactrouter.UNSAFE_RemixErrorBoundary, { location }, /* @__PURE__ */ React2.createElement(
248
+ /* @__PURE__ */ React2.createElement(_reactrouter.UNSAFE_RemixErrorBoundary, { location: location2 }, /* @__PURE__ */ React2.createElement(
231
249
  RouterProvider,
232
250
  {
233
251
  router,
@@ -238,6 +256,670 @@ function HydratedRouter(props) {
238
256
  );
239
257
  }
240
258
 
259
+ // lib/rsc/browser.tsx
260
+
261
+
262
+ function createCallServer({
263
+ createFromReadableStream,
264
+ createTemporaryReferenceSet,
265
+ encodeReply,
266
+ fetch: fetchImplementation = fetch
267
+ }) {
268
+ const globalVar = window;
269
+ let landedActionId = 0;
270
+ return async (id, args) => {
271
+ let actionId = globalVar.__routerActionID = (_nullishCoalesce(globalVar.__routerActionID, () => ( (globalVar.__routerActionID = 0)))) + 1;
272
+ const temporaryReferences = createTemporaryReferenceSet();
273
+ const payloadPromise = fetchImplementation(
274
+ new Request(location.href, {
275
+ body: await encodeReply(args, { temporaryReferences }),
276
+ method: "POST",
277
+ headers: {
278
+ Accept: "text/x-component",
279
+ "rsc-action-id": id
280
+ }
281
+ })
282
+ ).then((response) => {
283
+ if (!response.body) {
284
+ throw new Error("No response body");
285
+ }
286
+ return createFromReadableStream(response.body, {
287
+ temporaryReferences
288
+ });
289
+ });
290
+ globalVar.__reactRouterDataRouter.__setPendingRerender(
291
+ Promise.resolve(payloadPromise).then(async (payload) => {
292
+ if (payload.type === "redirect") {
293
+ if (payload.reload || isExternalLocation(payload.location)) {
294
+ window.location.href = payload.location;
295
+ return () => {
296
+ };
297
+ }
298
+ return () => {
299
+ globalVar.__reactRouterDataRouter.navigate(payload.location, {
300
+ replace: payload.replace
301
+ });
302
+ };
303
+ }
304
+ if (payload.type !== "action") {
305
+ throw new Error("Unexpected payload type");
306
+ }
307
+ const rerender = await payload.rerender;
308
+ if (rerender && landedActionId < actionId && globalVar.__routerActionID <= actionId) {
309
+ if (rerender.type === "redirect") {
310
+ if (rerender.reload || isExternalLocation(rerender.location)) {
311
+ window.location.href = rerender.location;
312
+ return;
313
+ }
314
+ return () => {
315
+ globalVar.__reactRouterDataRouter.navigate(rerender.location, {
316
+ replace: rerender.replace
317
+ });
318
+ };
319
+ }
320
+ return () => {
321
+ let lastMatch;
322
+ for (const match of rerender.matches) {
323
+ globalVar.__reactRouterDataRouter.patchRoutes(
324
+ _nullishCoalesce(_optionalChain([lastMatch, 'optionalAccess', _21 => _21.id]), () => ( null)),
325
+ [createRouteFromServerManifest(match)],
326
+ true
327
+ );
328
+ lastMatch = match;
329
+ }
330
+ window.__reactRouterDataRouter._internalSetStateDoNotUseOrYouWillBreakYourApp(
331
+ {
332
+ loaderData: Object.assign(
333
+ {},
334
+ globalVar.__reactRouterDataRouter.state.loaderData,
335
+ rerender.loaderData
336
+ ),
337
+ errors: rerender.errors ? Object.assign(
338
+ {},
339
+ globalVar.__reactRouterDataRouter.state.errors,
340
+ rerender.errors
341
+ ) : null
342
+ }
343
+ );
344
+ };
345
+ }
346
+ return () => {
347
+ };
348
+ }).catch(() => {
349
+ })
350
+ );
351
+ return payloadPromise.then((payload) => {
352
+ if (payload.type !== "action" && payload.type !== "redirect") {
353
+ throw new Error("Unexpected payload type");
354
+ }
355
+ return payload.actionResult;
356
+ });
357
+ };
358
+ }
359
+ function createRouterFromPayload({
360
+ fetchImplementation,
361
+ createFromReadableStream,
362
+ getContext,
363
+ payload
364
+ }) {
365
+ const globalVar = window;
366
+ if (globalVar.__reactRouterDataRouter && globalVar.__reactRouterRouteModules)
367
+ return {
368
+ router: globalVar.__reactRouterDataRouter,
369
+ routeModules: globalVar.__reactRouterRouteModules
370
+ };
371
+ if (payload.type !== "render") throw new Error("Invalid payload type");
372
+ globalVar.__reactRouterRouteModules = _nullishCoalesce(globalVar.__reactRouterRouteModules, () => ( {}));
373
+ _chunkUPBUMW2Mjs.populateRSCRouteModules.call(void 0, globalVar.__reactRouterRouteModules, payload.matches);
374
+ let patches = /* @__PURE__ */ new Map();
375
+ _optionalChain([payload, 'access', _22 => _22.patches, 'optionalAccess', _23 => _23.forEach, 'call', _24 => _24((patch) => {
376
+ _chunkK3XLKYJIjs.invariant.call(void 0, patch.parentId, "Invalid patch parentId");
377
+ if (!patches.has(patch.parentId)) {
378
+ patches.set(patch.parentId, []);
379
+ }
380
+ _optionalChain([patches, 'access', _25 => _25.get, 'call', _26 => _26(patch.parentId), 'optionalAccess', _27 => _27.push, 'call', _28 => _28(patch)]);
381
+ })]);
382
+ let routes = payload.matches.reduceRight((previous, match) => {
383
+ const route = createRouteFromServerManifest(
384
+ match,
385
+ payload
386
+ );
387
+ if (previous.length > 0) {
388
+ route.children = previous;
389
+ let childrenToPatch = patches.get(match.id);
390
+ if (childrenToPatch) {
391
+ route.children.push(
392
+ ...childrenToPatch.map((r) => createRouteFromServerManifest(r))
393
+ );
394
+ }
395
+ }
396
+ return [route];
397
+ }, []);
398
+ globalVar.__reactRouterDataRouter = _chunkK3XLKYJIjs.createRouter.call(void 0, {
399
+ routes,
400
+ getContext,
401
+ basename: payload.basename,
402
+ history: _chunkK3XLKYJIjs.createBrowserHistory.call(void 0, ),
403
+ hydrationData: _chunkUPBUMW2Mjs.getHydrationData.call(void 0, {
404
+ state: {
405
+ loaderData: payload.loaderData,
406
+ actionData: payload.actionData,
407
+ errors: payload.errors
408
+ },
409
+ routes,
410
+ getRouteInfo: (routeId) => {
411
+ let match = payload.matches.find((m) => m.id === routeId);
412
+ _chunkK3XLKYJIjs.invariant.call(void 0, match, "Route not found in payload");
413
+ return {
414
+ clientLoader: match.clientLoader,
415
+ hasLoader: match.hasLoader,
416
+ hasHydrateFallback: match.hydrateFallbackElement != null
417
+ };
418
+ },
419
+ location: payload.location,
420
+ basename: payload.basename,
421
+ isSpaMode: false
422
+ }),
423
+ async patchRoutesOnNavigation({ path, signal }) {
424
+ if (discoveredPaths.has(path)) {
425
+ return;
426
+ }
427
+ await fetchAndApplyManifestPatches(
428
+ [path],
429
+ createFromReadableStream,
430
+ fetchImplementation,
431
+ signal
432
+ );
433
+ },
434
+ // FIXME: Pass `build.ssr` into this function
435
+ dataStrategy: getRSCSingleFetchDataStrategy(
436
+ () => globalVar.__reactRouterDataRouter,
437
+ true,
438
+ payload.basename,
439
+ createFromReadableStream,
440
+ fetchImplementation
441
+ )
442
+ });
443
+ if (globalVar.__reactRouterDataRouter.state.initialized) {
444
+ globalVar.__routerInitialized = true;
445
+ globalVar.__reactRouterDataRouter.initialize();
446
+ } else {
447
+ globalVar.__routerInitialized = false;
448
+ }
449
+ let lastLoaderData = void 0;
450
+ globalVar.__reactRouterDataRouter.subscribe(({ loaderData, actionData }) => {
451
+ if (lastLoaderData !== loaderData) {
452
+ globalVar.__routerActionID = (_nullishCoalesce(globalVar.__routerActionID, () => ( (globalVar.__routerActionID = 0)))) + 1;
453
+ }
454
+ });
455
+ globalVar.__reactRouterDataRouter._updateRoutesForHMR = (routeUpdateByRouteId) => {
456
+ const oldRoutes = window.__reactRouterDataRouter.routes;
457
+ const newRoutes = [];
458
+ function walkRoutes(routes2, parentId) {
459
+ return routes2.map((route) => {
460
+ const routeUpdate = routeUpdateByRouteId.get(route.id);
461
+ if (routeUpdate) {
462
+ const {
463
+ routeModule,
464
+ hasAction,
465
+ hasComponent,
466
+ hasErrorBoundary,
467
+ hasLoader
468
+ } = routeUpdate;
469
+ const newRoute = createRouteFromServerManifest({
470
+ clientAction: routeModule.clientAction,
471
+ clientLoader: routeModule.clientLoader,
472
+ element: route.element,
473
+ errorElement: route.errorElement,
474
+ handle: route.handle,
475
+ hasAction,
476
+ hasComponent,
477
+ hasErrorBoundary,
478
+ hasLoader,
479
+ hydrateFallbackElement: route.hydrateFallbackElement,
480
+ id: route.id,
481
+ index: route.index,
482
+ links: routeModule.links,
483
+ meta: routeModule.meta,
484
+ parentId,
485
+ path: route.path,
486
+ shouldRevalidate: routeModule.shouldRevalidate
487
+ });
488
+ if (route.children) {
489
+ newRoute.children = walkRoutes(route.children, route.id);
490
+ }
491
+ return newRoute;
492
+ }
493
+ const updatedRoute = { ...route };
494
+ if (route.children) {
495
+ updatedRoute.children = walkRoutes(route.children, route.id);
496
+ }
497
+ return updatedRoute;
498
+ });
499
+ }
500
+ newRoutes.push(
501
+ ...walkRoutes(oldRoutes, void 0)
502
+ );
503
+ window.__reactRouterDataRouter._internalSetRoutes(newRoutes);
504
+ };
505
+ return {
506
+ router: globalVar.__reactRouterDataRouter,
507
+ routeModules: globalVar.__reactRouterRouteModules
508
+ };
509
+ }
510
+ var renderedRoutesContext = _chunkK3XLKYJIjs.createContext.call(void 0, );
511
+ function getRSCSingleFetchDataStrategy(getRouter, ssr, basename, createFromReadableStream, fetchImplementation) {
512
+ let dataStrategy = _chunkK3XLKYJIjs.getSingleFetchDataStrategyImpl.call(void 0,
513
+ getRouter,
514
+ (match) => {
515
+ let M = match;
516
+ return {
517
+ hasLoader: M.route.hasLoader,
518
+ hasClientLoader: M.route.hasClientLoader,
519
+ hasComponent: M.route.hasComponent,
520
+ hasAction: M.route.hasAction,
521
+ hasClientAction: M.route.hasClientAction,
522
+ hasShouldRevalidate: M.route.hasShouldRevalidate
523
+ };
524
+ },
525
+ // pass map into fetchAndDecode so it can add payloads
526
+ getFetchAndDecodeViaRSC(createFromReadableStream, fetchImplementation),
527
+ ssr,
528
+ basename,
529
+ // If the route has a component but we don't have an element, we need to hit
530
+ // the server loader flow regardless of whether the client loader calls
531
+ // `serverLoader` or not, otherwise we'll have nothing to render.
532
+ (match) => {
533
+ let M = match;
534
+ return M.route.hasComponent && !M.route.element;
535
+ }
536
+ );
537
+ return async (args) => args.runClientMiddleware(async () => {
538
+ let context = args.context;
539
+ context.set(renderedRoutesContext, []);
540
+ let results = await dataStrategy(args);
541
+ const renderedRoutesById = /* @__PURE__ */ new Map();
542
+ for (const route of context.get(renderedRoutesContext)) {
543
+ if (!renderedRoutesById.has(route.id)) {
544
+ renderedRoutesById.set(route.id, []);
545
+ }
546
+ renderedRoutesById.get(route.id).push(route);
547
+ }
548
+ for (const match of args.matches) {
549
+ const renderedRoutes = renderedRoutesById.get(match.route.id);
550
+ if (renderedRoutes) {
551
+ for (const rendered of renderedRoutes) {
552
+ window.__reactRouterDataRouter.patchRoutes(
553
+ _nullishCoalesce(rendered.parentId, () => ( null)),
554
+ [createRouteFromServerManifest(rendered)],
555
+ true
556
+ );
557
+ }
558
+ }
559
+ }
560
+ return results;
561
+ });
562
+ }
563
+ function getFetchAndDecodeViaRSC(createFromReadableStream, fetchImplementation) {
564
+ return async (args, basename, targetRoutes) => {
565
+ let { request, context } = args;
566
+ let url = _chunkK3XLKYJIjs.singleFetchUrl.call(void 0, request.url, basename, "rsc");
567
+ if (request.method === "GET") {
568
+ url = _chunkK3XLKYJIjs.stripIndexParam.call(void 0, url);
569
+ if (targetRoutes) {
570
+ url.searchParams.set("_routes", targetRoutes.join(","));
571
+ }
572
+ }
573
+ let res = await fetchImplementation(
574
+ new Request(url, await _chunkK3XLKYJIjs.createRequestInit.call(void 0, request))
575
+ );
576
+ if (res.status >= 400 && !res.headers.has("X-Remix-Response")) {
577
+ throw new (0, _chunkK3XLKYJIjs.ErrorResponseImpl)(res.status, res.statusText, await res.text());
578
+ }
579
+ _chunkK3XLKYJIjs.invariant.call(void 0, res.body, "No response body to decode");
580
+ try {
581
+ const payload = await createFromReadableStream(res.body, {
582
+ temporaryReferences: void 0
583
+ });
584
+ if (payload.type === "redirect") {
585
+ return {
586
+ status: res.status,
587
+ data: {
588
+ redirect: {
589
+ redirect: payload.location,
590
+ reload: payload.reload,
591
+ replace: payload.replace,
592
+ revalidate: false,
593
+ status: payload.status
594
+ }
595
+ }
596
+ };
597
+ }
598
+ if (payload.type !== "render") {
599
+ throw new Error("Unexpected payload type");
600
+ }
601
+ context.get(renderedRoutesContext).push(...payload.matches);
602
+ let results = { routes: {} };
603
+ const dataKey = _chunkK3XLKYJIjs.isMutationMethod.call(void 0, request.method) ? "actionData" : "loaderData";
604
+ for (let [routeId, data] of Object.entries(payload[dataKey] || {})) {
605
+ results.routes[routeId] = { data };
606
+ }
607
+ if (payload.errors) {
608
+ for (let [routeId, error] of Object.entries(payload.errors)) {
609
+ results.routes[routeId] = { error };
610
+ }
611
+ }
612
+ return { status: res.status, data: results };
613
+ } catch (e) {
614
+ throw new Error("Unable to decode RSC response");
615
+ }
616
+ };
617
+ }
618
+ function RSCHydratedRouter({
619
+ createFromReadableStream,
620
+ fetch: fetchImplementation = fetch,
621
+ payload,
622
+ routeDiscovery = "eager",
623
+ getContext
624
+ }) {
625
+ if (payload.type !== "render") throw new Error("Invalid payload type");
626
+ let { router: router2, routeModules } = React3.useMemo(
627
+ () => createRouterFromPayload({
628
+ payload,
629
+ fetchImplementation,
630
+ getContext,
631
+ createFromReadableStream
632
+ }),
633
+ [createFromReadableStream, payload, fetchImplementation, getContext]
634
+ );
635
+ React3.useEffect(() => {
636
+ _chunkK3XLKYJIjs.setIsHydrated.call(void 0, );
637
+ }, []);
638
+ React3.useLayoutEffect(() => {
639
+ const globalVar = window;
640
+ if (!globalVar.__routerInitialized) {
641
+ globalVar.__routerInitialized = true;
642
+ globalVar.__reactRouterDataRouter.initialize();
643
+ }
644
+ }, []);
645
+ let [location2, setLocation] = React3.useState(router2.state.location);
646
+ React3.useLayoutEffect(
647
+ () => router2.subscribe((newState) => {
648
+ if (newState.location !== location2) {
649
+ setLocation(newState.location);
650
+ }
651
+ }),
652
+ [router2, location2]
653
+ );
654
+ React3.useEffect(() => {
655
+ if (routeDiscovery === "lazy" || // @ts-expect-error - TS doesn't know about this yet
656
+ _optionalChain([window, 'access', _29 => _29.navigator, 'optionalAccess', _30 => _30.connection, 'optionalAccess', _31 => _31.saveData]) === true) {
657
+ return;
658
+ }
659
+ function registerElement(el) {
660
+ let path = el.tagName === "FORM" ? el.getAttribute("action") : el.getAttribute("href");
661
+ if (!path) {
662
+ return;
663
+ }
664
+ let pathname = el.tagName === "A" ? el.pathname : new URL(path, window.location.origin).pathname;
665
+ if (!discoveredPaths.has(pathname)) {
666
+ nextPaths.add(pathname);
667
+ }
668
+ }
669
+ async function fetchPatches() {
670
+ document.querySelectorAll("a[data-discover], form[data-discover]").forEach(registerElement);
671
+ let paths = Array.from(nextPaths.keys()).filter((path) => {
672
+ if (discoveredPaths.has(path)) {
673
+ nextPaths.delete(path);
674
+ return false;
675
+ }
676
+ return true;
677
+ });
678
+ if (paths.length === 0) {
679
+ return;
680
+ }
681
+ try {
682
+ await fetchAndApplyManifestPatches(
683
+ paths,
684
+ createFromReadableStream,
685
+ fetchImplementation
686
+ );
687
+ } catch (e) {
688
+ console.error("Failed to fetch manifest patches", e);
689
+ }
690
+ }
691
+ let debouncedFetchPatches = debounce(fetchPatches, 100);
692
+ fetchPatches();
693
+ let observer = new MutationObserver(() => debouncedFetchPatches());
694
+ observer.observe(document.documentElement, {
695
+ subtree: true,
696
+ childList: true,
697
+ attributes: true,
698
+ attributeFilter: ["data-discover", "href", "action"]
699
+ });
700
+ }, [routeDiscovery, createFromReadableStream, fetchImplementation]);
701
+ const frameworkContext = {
702
+ future: {
703
+ // These flags have no runtime impact so can always be false. If we add
704
+ // flags that drive runtime behavior they'll need to be proxied through.
705
+ v8_middleware: false,
706
+ unstable_subResourceIntegrity: false
707
+ },
708
+ isSpaMode: false,
709
+ ssr: true,
710
+ criticalCss: "",
711
+ manifest: {
712
+ routes: {},
713
+ version: "1",
714
+ url: "",
715
+ entry: {
716
+ module: "",
717
+ imports: []
718
+ }
719
+ },
720
+ routeDiscovery: { mode: "lazy", manifestPath: "/__manifest" },
721
+ routeModules
722
+ };
723
+ return /* @__PURE__ */ React3.createElement(_chunkK3XLKYJIjs.RSCRouterContext.Provider, { value: true }, /* @__PURE__ */ React3.createElement(_chunkUPBUMW2Mjs.RSCRouterGlobalErrorBoundary, { location: location2 }, /* @__PURE__ */ React3.createElement(_chunkK3XLKYJIjs.FrameworkContext.Provider, { value: frameworkContext }, /* @__PURE__ */ React3.createElement(_chunkK3XLKYJIjs.UNSTABLE_TransitionEnabledRouterProvider, { router: router2, flushSync: ReactDOM2.flushSync }))));
724
+ }
725
+ function createRouteFromServerManifest(match, payload) {
726
+ let hasInitialData = payload && match.id in payload.loaderData;
727
+ let initialData = _optionalChain([payload, 'optionalAccess', _32 => _32.loaderData, 'access', _33 => _33[match.id]]);
728
+ let hasInitialError = _optionalChain([payload, 'optionalAccess', _34 => _34.errors]) && match.id in payload.errors;
729
+ let initialError = _optionalChain([payload, 'optionalAccess', _35 => _35.errors, 'optionalAccess', _36 => _36[match.id]]);
730
+ let isHydrationRequest = _optionalChain([match, 'access', _37 => _37.clientLoader, 'optionalAccess', _38 => _38.hydrate]) === true || !match.hasLoader || // If the route has a component but we don't have an element, we need to hit
731
+ // the server loader flow regardless of whether the client loader calls
732
+ // `serverLoader` or not, otherwise we'll have nothing to render.
733
+ match.hasComponent && !match.element;
734
+ _chunkK3XLKYJIjs.invariant.call(void 0, window.__reactRouterRouteModules);
735
+ _chunkUPBUMW2Mjs.populateRSCRouteModules.call(void 0, window.__reactRouterRouteModules, match);
736
+ let dataRoute = {
737
+ id: match.id,
738
+ element: match.element,
739
+ errorElement: match.errorElement,
740
+ handle: match.handle,
741
+ hasErrorBoundary: match.hasErrorBoundary,
742
+ hydrateFallbackElement: match.hydrateFallbackElement,
743
+ index: match.index,
744
+ loader: match.clientLoader ? async (args, singleFetch) => {
745
+ try {
746
+ let result = await match.clientLoader({
747
+ ...args,
748
+ serverLoader: () => {
749
+ preventInvalidServerHandlerCall(
750
+ "loader",
751
+ match.id,
752
+ match.hasLoader
753
+ );
754
+ if (isHydrationRequest) {
755
+ if (hasInitialData) {
756
+ return initialData;
757
+ }
758
+ if (hasInitialError) {
759
+ throw initialError;
760
+ }
761
+ }
762
+ return callSingleFetch(singleFetch);
763
+ }
764
+ });
765
+ return result;
766
+ } finally {
767
+ isHydrationRequest = false;
768
+ }
769
+ } : (
770
+ // We always make the call in this RSC world since even if we don't
771
+ // have a `loader` we may need to get the `element` implementation
772
+ (_, singleFetch) => callSingleFetch(singleFetch)
773
+ ),
774
+ action: match.clientAction ? (args, singleFetch) => match.clientAction({
775
+ ...args,
776
+ serverAction: async () => {
777
+ preventInvalidServerHandlerCall(
778
+ "action",
779
+ match.id,
780
+ match.hasLoader
781
+ );
782
+ return await callSingleFetch(singleFetch);
783
+ }
784
+ }) : match.hasAction ? (_, singleFetch) => callSingleFetch(singleFetch) : () => {
785
+ throw _chunkK3XLKYJIjs.noActionDefinedError.call(void 0, "action", match.id);
786
+ },
787
+ path: match.path,
788
+ shouldRevalidate: match.shouldRevalidate,
789
+ // We always have a "loader" in this RSC world since even if we don't
790
+ // have a `loader` we may need to get the `element` implementation
791
+ hasLoader: true,
792
+ hasClientLoader: match.clientLoader != null,
793
+ hasAction: match.hasAction,
794
+ hasClientAction: match.clientAction != null,
795
+ hasShouldRevalidate: match.shouldRevalidate != null
796
+ };
797
+ if (typeof dataRoute.loader === "function") {
798
+ dataRoute.loader.hydrate = _chunkK3XLKYJIjs.shouldHydrateRouteLoader.call(void 0,
799
+ match.id,
800
+ match.clientLoader,
801
+ match.hasLoader,
802
+ false
803
+ );
804
+ }
805
+ return dataRoute;
806
+ }
807
+ function callSingleFetch(singleFetch) {
808
+ _chunkK3XLKYJIjs.invariant.call(void 0, typeof singleFetch === "function", "Invalid singleFetch parameter");
809
+ return singleFetch();
810
+ }
811
+ function preventInvalidServerHandlerCall(type, routeId, hasHandler) {
812
+ if (!hasHandler) {
813
+ let fn = type === "action" ? "serverAction()" : "serverLoader()";
814
+ let msg = `You are trying to call ${fn} on a route that does not have a server ${type} (routeId: "${routeId}")`;
815
+ console.error(msg);
816
+ throw new (0, _chunkK3XLKYJIjs.ErrorResponseImpl)(400, "Bad Request", new Error(msg), true);
817
+ }
818
+ }
819
+ var nextPaths = /* @__PURE__ */ new Set();
820
+ var discoveredPathsMaxSize = 1e3;
821
+ var discoveredPaths = /* @__PURE__ */ new Set();
822
+ var URL_LIMIT = 7680;
823
+ function getManifestUrl(paths) {
824
+ if (paths.length === 0) {
825
+ return null;
826
+ }
827
+ if (paths.length === 1) {
828
+ return new URL(`${paths[0]}.manifest`, window.location.origin);
829
+ }
830
+ const globalVar = window;
831
+ let basename = (_nullishCoalesce(globalVar.__reactRouterDataRouter.basename, () => ( ""))).replace(
832
+ /^\/|\/$/g,
833
+ ""
834
+ );
835
+ let url = new URL(`${basename}/.manifest`, window.location.origin);
836
+ url.searchParams.set("paths", paths.sort().join(","));
837
+ return url;
838
+ }
839
+ async function fetchAndApplyManifestPatches(paths, createFromReadableStream, fetchImplementation, signal) {
840
+ let url = getManifestUrl(paths);
841
+ if (url == null) {
842
+ return;
843
+ }
844
+ if (url.toString().length > URL_LIMIT) {
845
+ nextPaths.clear();
846
+ return;
847
+ }
848
+ let response = await fetchImplementation(new Request(url, { signal }));
849
+ if (!response.body || response.status < 200 || response.status >= 300) {
850
+ throw new Error("Unable to fetch new route matches from the server");
851
+ }
852
+ let payload = await createFromReadableStream(response.body, {
853
+ temporaryReferences: void 0
854
+ });
855
+ if (payload.type !== "manifest") {
856
+ throw new Error("Failed to patch routes");
857
+ }
858
+ paths.forEach((p) => addToFifoQueue(p, discoveredPaths));
859
+ payload.patches.forEach((p) => {
860
+ window.__reactRouterDataRouter.patchRoutes(
861
+ _nullishCoalesce(p.parentId, () => ( null)),
862
+ [createRouteFromServerManifest(p)]
863
+ );
864
+ });
865
+ }
866
+ function addToFifoQueue(path, queue) {
867
+ if (queue.size >= discoveredPathsMaxSize) {
868
+ let first = queue.values().next().value;
869
+ queue.delete(first);
870
+ }
871
+ queue.add(path);
872
+ }
873
+ function debounce(callback, wait) {
874
+ let timeoutId;
875
+ return (...args) => {
876
+ window.clearTimeout(timeoutId);
877
+ timeoutId = window.setTimeout(() => callback(...args), wait);
878
+ };
879
+ }
880
+ function isExternalLocation(location2) {
881
+ const newLocation = new URL(location2, window.location.href);
882
+ return newLocation.origin !== window.location.origin;
883
+ }
884
+
885
+ // lib/rsc/html-stream/browser.ts
886
+ function getRSCStream() {
887
+ let encoder = new TextEncoder();
888
+ let streamController = null;
889
+ let rscStream = new ReadableStream({
890
+ start(controller) {
891
+ if (typeof window === "undefined") {
892
+ return;
893
+ }
894
+ let handleChunk = (chunk) => {
895
+ if (typeof chunk === "string") {
896
+ controller.enqueue(encoder.encode(chunk));
897
+ } else {
898
+ controller.enqueue(chunk);
899
+ }
900
+ };
901
+ window.__FLIGHT_DATA || (window.__FLIGHT_DATA = []);
902
+ window.__FLIGHT_DATA.forEach(handleChunk);
903
+ window.__FLIGHT_DATA.push = (chunk) => {
904
+ handleChunk(chunk);
905
+ return 0;
906
+ };
907
+ streamController = controller;
908
+ }
909
+ });
910
+ if (typeof document !== "undefined" && document.readyState === "loading") {
911
+ document.addEventListener("DOMContentLoaded", () => {
912
+ _optionalChain([streamController, 'optionalAccess', _39 => _39.close, 'call', _40 => _40()]);
913
+ });
914
+ } else {
915
+ _optionalChain([streamController, 'optionalAccess', _41 => _41.close, 'call', _42 => _42()]);
916
+ }
917
+ return rscStream;
918
+ }
919
+
920
+
921
+
922
+
241
923
 
242
924
 
243
- exports.HydratedRouter = HydratedRouter; exports.RouterProvider = RouterProvider;
925
+ exports.HydratedRouter = HydratedRouter; exports.RouterProvider = RouterProvider; exports.unstable_RSCHydratedRouter = RSCHydratedRouter; exports.unstable_createCallServer = createCallServer; exports.unstable_getRSCStream = getRSCStream;