react-router 7.18.5 → 7.18.6

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 (36) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/{production/chunk-K3NA4NUH.js → development/chunk-3QTLHDUO.js} +7 -7
  3. package/dist/{production/chunk-IAM5GYT3.mjs → development/chunk-E2PF4K4Z.mjs} +14 -5
  4. package/dist/development/{chunk-NDF5KBLP.js → chunk-QM7ETCUK.js} +109 -104
  5. package/dist/development/{chunk-2ZBLYC7V.js → chunk-S47XUPN5.js} +105 -65
  6. package/dist/development/{chunk-6KYCQHYJ.mjs → chunk-YDNE64FV.mjs} +107 -63
  7. package/dist/development/dom-export.js +37 -35
  8. package/dist/development/dom-export.mjs +6 -4
  9. package/dist/development/index-react-server-client.js +4 -4
  10. package/dist/development/index-react-server-client.mjs +2 -2
  11. package/dist/development/index-react-server.js +72 -3
  12. package/dist/development/index-react-server.mjs +72 -3
  13. package/dist/development/index.d.mts +1 -1
  14. package/dist/development/index.d.ts +1 -1
  15. package/dist/development/index.js +111 -102
  16. package/dist/development/index.mjs +3 -3
  17. package/dist/development/lib/types/internal.js +1 -1
  18. package/dist/development/lib/types/internal.mjs +1 -1
  19. package/dist/production/{chunk-75HN637G.js → chunk-2WUBOUFU.js} +109 -104
  20. package/dist/{development/chunk-IFHLIXZW.js → production/chunk-3IBQ4CTZ.js} +7 -7
  21. package/dist/production/{chunk-HNBICOIU.js → chunk-AC65NKOP.js} +105 -65
  22. package/dist/production/{chunk-7RTFRKQW.mjs → chunk-HEAXLYUI.mjs} +107 -63
  23. package/dist/{development/chunk-JAHXRPFV.mjs → production/chunk-JRCXCPLA.mjs} +14 -5
  24. package/dist/production/dom-export.js +37 -35
  25. package/dist/production/dom-export.mjs +6 -4
  26. package/dist/production/index-react-server-client.js +4 -4
  27. package/dist/production/index-react-server-client.mjs +2 -2
  28. package/dist/production/index-react-server.js +72 -3
  29. package/dist/production/index-react-server.mjs +72 -3
  30. package/dist/production/index.d.mts +1 -1
  31. package/dist/production/index.d.ts +1 -1
  32. package/dist/production/index.js +111 -102
  33. package/dist/production/index.mjs +3 -3
  34. package/dist/production/lib/types/internal.js +1 -1
  35. package/dist/production/lib/types/internal.mjs +1 -1
  36. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
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 v7.18.5
2
+ * react-router v7.18.6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -386,6 +386,67 @@ function createBrowserURLImpl(windowImpl, to, isAbsolute = false) {
386
386
  return new URL(href, base);
387
387
  }
388
388
 
389
+ // lib/router/navigation.ts
390
+ var DEFAULT_NAVIGATION_URL = new URL("http://localhost");
391
+ function getNavigatorCurrentUrl(navigator) {
392
+ if (navigator.createURL) {
393
+ return navigator.createURL("/");
394
+ }
395
+ try {
396
+ return new URL(navigator.createHref("/"), DEFAULT_NAVIGATION_URL);
397
+ } catch (e2) {
398
+ return DEFAULT_NAVIGATION_URL;
399
+ }
400
+ }
401
+ function isSameOrigin(a, b) {
402
+ return a.origin === b.origin && (a.origin !== "null" || a.protocol === b.protocol && a.host === b.host);
403
+ }
404
+ function isExplicitUrl(destination, target) {
405
+ if (destination.startsWith("//")) {
406
+ return true;
407
+ }
408
+ let protocol = target.protocol.toLowerCase();
409
+ if (!destination.toLowerCase().startsWith(protocol)) {
410
+ return false;
411
+ }
412
+ return target.host === "" || destination.slice(protocol.length).startsWith("//");
413
+ }
414
+ function validateDocumentNavigationTarget(destination) {
415
+ let normalized = destination.replace(/[\t\n\r]/g, "");
416
+ let start = 0;
417
+ while (normalized.charCodeAt(start) <= 32) start++;
418
+ normalized = normalized.slice(start);
419
+ if (!ABSOLUTE_URL_REGEX.test(normalized)) return;
420
+ let target;
421
+ try {
422
+ target = new URL(destination, DEFAULT_NAVIGATION_URL);
423
+ } catch (e3) {
424
+ return;
425
+ }
426
+ if (!isExplicitUrl(destination, target)) {
427
+ throw new Error("External navigation is not allowed");
428
+ }
429
+ }
430
+ function validateNavigationTarget(original, resolved, currentUrl, externalPolicy) {
431
+ let originalUrl = null;
432
+ try {
433
+ originalUrl = original == null ? null : new URL(original, currentUrl);
434
+ } catch (e4) {
435
+ }
436
+ let resolvedUrl = new URL(resolved, currentUrl);
437
+ let originalIsExternal = originalUrl != null && !isSameOrigin(originalUrl, currentUrl);
438
+ let resolvedIsExternal = !isSameOrigin(resolvedUrl, currentUrl);
439
+ if (externalPolicy === "reject") {
440
+ if (originalIsExternal || resolvedIsExternal) {
441
+ throw new Error("External navigation is not allowed");
442
+ }
443
+ } else if (resolvedIsExternal) {
444
+ if (originalUrl == null || !isExplicitUrl(original, originalUrl) || !isSameOrigin(originalUrl, resolvedUrl)) {
445
+ throw new Error("External navigation is not allowed");
446
+ }
447
+ }
448
+ }
449
+
389
450
  // lib/router/utils.ts
390
451
  function createContext(defaultValue) {
391
452
  return { defaultValue };
@@ -767,7 +828,12 @@ function generatePath(originalPath, params = {}) {
767
828
  }
768
829
  return segment.replace(/\?$/g, "");
769
830
  }).filter((segment) => !!segment);
770
- return prefix + segments.join("/");
831
+ let result = (prefix + segments.join("/")).replace(/^[\\/]{2,}/, "/");
832
+ if (!prefix && (path.startsWith(":") || path === "*")) {
833
+ result = result.replace(/^([a-z][a-z0-9+.-]*):/i, "$1%3A");
834
+ }
835
+ validateDocumentNavigationTarget(result);
836
+ return result;
771
837
  }
772
838
  function matchPath(pattern, pathname) {
773
839
  if (typeof pattern === "string") {
@@ -995,6 +1061,7 @@ function data(data2, init) {
995
1061
  );
996
1062
  }
997
1063
  var redirect = (url, init = 302) => {
1064
+ validateDocumentNavigationTarget(url);
998
1065
  let responseInit = init;
999
1066
  if (typeof responseInit === "number") {
1000
1067
  responseInit = { status: responseInit };
@@ -1350,51 +1417,6 @@ function isPlainObject(thing) {
1350
1417
  return proto === Object.prototype || proto === null || Object.getOwnPropertyNames(proto).sort().join("\0") === objectProtoNames;
1351
1418
  }
1352
1419
 
1353
- // lib/router/navigation.ts
1354
- var DEFAULT_NAVIGATION_URL = new URL("http://localhost");
1355
- function getNavigatorCurrentUrl(navigator) {
1356
- if (navigator.createURL) {
1357
- return navigator.createURL("/");
1358
- }
1359
- try {
1360
- return new URL(navigator.createHref("/"), DEFAULT_NAVIGATION_URL);
1361
- } catch (e2) {
1362
- return DEFAULT_NAVIGATION_URL;
1363
- }
1364
- }
1365
- function isSameOrigin(a, b) {
1366
- return a.origin === b.origin && (a.origin !== "null" || a.protocol === b.protocol && a.host === b.host);
1367
- }
1368
- function isExplicitUrl(destination, target) {
1369
- if (destination.startsWith("//")) {
1370
- return true;
1371
- }
1372
- let protocol = target.protocol.toLowerCase();
1373
- if (!destination.toLowerCase().startsWith(protocol)) {
1374
- return false;
1375
- }
1376
- return target.host === "" || destination.slice(protocol.length).startsWith("//");
1377
- }
1378
- function validateNavigationTarget(original, resolved, currentUrl, externalPolicy) {
1379
- let originalUrl = null;
1380
- try {
1381
- originalUrl = original == null ? null : new URL(original, currentUrl);
1382
- } catch (e3) {
1383
- }
1384
- let resolvedUrl = new URL(resolved, currentUrl);
1385
- let originalIsExternal = originalUrl != null && !isSameOrigin(originalUrl, currentUrl);
1386
- let resolvedIsExternal = !isSameOrigin(resolvedUrl, currentUrl);
1387
- if (externalPolicy === "reject") {
1388
- if (originalIsExternal || resolvedIsExternal) {
1389
- throw new Error("External navigation is not allowed");
1390
- }
1391
- } else if (resolvedIsExternal) {
1392
- if (originalUrl == null || !isExplicitUrl(original, originalUrl) || !isSameOrigin(originalUrl, resolvedUrl)) {
1393
- throw new Error("External navigation is not allowed");
1394
- }
1395
- }
1396
- }
1397
-
1398
1420
  // lib/router/router.ts
1399
1421
  var validMutationMethodsArr = [
1400
1422
  "POST",
@@ -2527,6 +2549,12 @@ function createRouter(init) {
2527
2549
  routeId,
2528
2550
  _optionalChain([opts, 'optionalAccess', _23 => _23.relative])
2529
2551
  );
2552
+ validateNavigationTarget(
2553
+ null,
2554
+ normalizedPath,
2555
+ init.history.createURL("/"),
2556
+ "reject"
2557
+ );
2530
2558
  let matches = matchRoutesImpl(
2531
2559
  routesToUse,
2532
2560
  normalizedPath,
@@ -5297,6 +5325,12 @@ function normalizeRelativeRoutingRedirectResponse(response, request, routeId, ma
5297
5325
  location,
5298
5326
  "Redirects returned/thrown from loaders/actions must have a Location header"
5299
5327
  );
5328
+ validateNavigationTarget(
5329
+ location,
5330
+ location,
5331
+ new URL(request.url),
5332
+ "allow-explicit"
5333
+ );
5300
5334
  if (!isAbsoluteUrl(location)) {
5301
5335
  let trimmedMatches = matches.slice(
5302
5336
  0,
@@ -5328,7 +5362,7 @@ var invalidProtocols = [
5328
5362
  function hasInvalidProtocol(location) {
5329
5363
  try {
5330
5364
  return invalidProtocols.includes(new URL(location).protocol);
5331
- } catch (e4) {
5365
+ } catch (e5) {
5332
5366
  return false;
5333
5367
  }
5334
5368
  }
@@ -6449,20 +6483,22 @@ function encode(input, options) {
6449
6483
  };
6450
6484
  const textEncoder = new TextEncoder();
6451
6485
  let lastSentIndex = 0;
6486
+ let cancelled = false;
6452
6487
  const readable = new ReadableStream({
6453
6488
  async start(controller) {
6489
+ const enqueue = (chunk) => {
6490
+ if (!cancelled) controller.enqueue(chunk);
6491
+ };
6454
6492
  const id = await flatten.call(encoder, input);
6455
6493
  if (Array.isArray(id)) {
6456
6494
  throw new Error("This should never happen");
6457
6495
  }
6458
6496
  if (id < 0) {
6459
- controller.enqueue(textEncoder.encode(`${id}
6497
+ enqueue(textEncoder.encode(`${id}
6460
6498
  `));
6461
6499
  } else {
6462
- controller.enqueue(
6463
- textEncoder.encode(`[${encoder.stringified.join(",")}]
6464
- `)
6465
- );
6500
+ enqueue(textEncoder.encode(`[${encoder.stringified.join(",")}]
6501
+ `));
6466
6502
  lastSentIndex = encoder.stringified.length - 1;
6467
6503
  }
6468
6504
  const seenPromises = /* @__PURE__ */ new WeakSet();
@@ -6497,7 +6533,7 @@ function encode(input, options) {
6497
6533
  processingChain = processingChain.then(async () => {
6498
6534
  const id2 = await flatten.call(encoder, resolved);
6499
6535
  if (Array.isArray(id2)) {
6500
- controller.enqueue(
6536
+ enqueue(
6501
6537
  textEncoder.encode(
6502
6538
  `${TYPE_PROMISE}${deferredId}:[["${TYPE_PREVIOUS_RESOLVED}",${id2[0]}]]
6503
6539
  `
@@ -6506,7 +6542,7 @@ function encode(input, options) {
6506
6542
  encoder.index++;
6507
6543
  lastSentIndex++;
6508
6544
  } else if (id2 < 0) {
6509
- controller.enqueue(
6545
+ enqueue(
6510
6546
  textEncoder.encode(
6511
6547
  `${TYPE_PROMISE}${deferredId}:${id2}
6512
6548
  `
@@ -6514,7 +6550,7 @@ function encode(input, options) {
6514
6550
  );
6515
6551
  } else {
6516
6552
  const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
6517
- controller.enqueue(
6553
+ enqueue(
6518
6554
  textEncoder.encode(
6519
6555
  `${TYPE_PROMISE}${deferredId}:[${values}]
6520
6556
  `
@@ -6532,7 +6568,7 @@ function encode(input, options) {
6532
6568
  }
6533
6569
  const id2 = await flatten.call(encoder, reason);
6534
6570
  if (Array.isArray(id2)) {
6535
- controller.enqueue(
6571
+ enqueue(
6536
6572
  textEncoder.encode(
6537
6573
  `${TYPE_ERROR}${deferredId}:[["${TYPE_PREVIOUS_RESOLVED}",${id2[0]}]]
6538
6574
  `
@@ -6541,7 +6577,7 @@ function encode(input, options) {
6541
6577
  encoder.index++;
6542
6578
  lastSentIndex++;
6543
6579
  } else if (id2 < 0) {
6544
- controller.enqueue(
6580
+ enqueue(
6545
6581
  textEncoder.encode(
6546
6582
  `${TYPE_ERROR}${deferredId}:${id2}
6547
6583
  `
@@ -6549,7 +6585,7 @@ function encode(input, options) {
6549
6585
  );
6550
6586
  } else {
6551
6587
  const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
6552
- controller.enqueue(
6588
+ enqueue(
6553
6589
  textEncoder.encode(
6554
6590
  `${TYPE_ERROR}${deferredId}:[${values}]
6555
6591
  `
@@ -6571,8 +6607,11 @@ function encode(input, options) {
6571
6607
  }
6572
6608
  await Promise.all(Object.values(encoder.deferred));
6573
6609
  await processingChain;
6574
- controller.close();
6610
+ if (!cancelled) controller.close();
6575
6611
  _optionalChain([onComplete, 'optionalCall', _82 => _82()]);
6612
+ },
6613
+ cancel() {
6614
+ cancelled = true;
6576
6615
  }
6577
6616
  });
6578
6617
  return readable;
@@ -7185,7 +7224,7 @@ function decodeRedirectErrorDigest(digest) {
7185
7224
  if (typeof parsed === "object" && parsed && typeof parsed.status === "number" && typeof parsed.statusText === "string" && typeof parsed.location === "string" && typeof parsed.reloadDocument === "boolean" && typeof parsed.replace === "boolean") {
7186
7225
  return parsed;
7187
7226
  }
7188
- } catch (e5) {
7227
+ } catch (e6) {
7189
7228
  }
7190
7229
  }
7191
7230
  }
@@ -7202,7 +7241,7 @@ function decodeRouteErrorResponseDigest(digest) {
7202
7241
  parsed.data
7203
7242
  );
7204
7243
  }
7205
- } catch (e6) {
7244
+ } catch (e7) {
7206
7245
  }
7207
7246
  }
7208
7247
  }
@@ -8804,7 +8843,7 @@ async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, ro
8804
8843
  return;
8805
8844
  }
8806
8845
  sessionStorage.setItem(MANIFEST_VERSION_STORAGE_KEY, manifest.version);
8807
- } catch (e7) {
8846
+ } catch (e8) {
8808
8847
  }
8809
8848
  window.location.href = errorReloadPath;
8810
8849
  console.warn("Detected manifest version mismatch, reloading...");
@@ -8815,7 +8854,7 @@ async function fetchAndApplyManifestPatches(paths, errorReloadPath, manifest, ro
8815
8854
  }
8816
8855
  try {
8817
8856
  sessionStorage.removeItem(MANIFEST_VERSION_STORAGE_KEY);
8818
- } catch (e8) {
8857
+ } catch (e9) {
8819
8858
  }
8820
8859
  serverPatches = await res.json();
8821
8860
  } catch (e) {
@@ -10434,4 +10473,5 @@ function withErrorBoundaryProps(ErrorBoundary) {
10434
10473
 
10435
10474
 
10436
10475
 
10437
- exports.ABSOLUTE_URL_REGEX = ABSOLUTE_URL_REGEX; exports.PROTOCOL_RELATIVE_URL_REGEX = PROTOCOL_RELATIVE_URL_REGEX; exports.Action = Action; exports.createMemoryHistory = createMemoryHistory; exports.createBrowserHistory = createBrowserHistory; exports.createHashHistory = createHashHistory; exports.invariant = invariant; exports.warning = warning; exports.createPath = createPath; exports.parsePath = parsePath; exports.createContext = createContext; exports.RouterContextProvider = RouterContextProvider; exports.convertRoutesToDataRoutes = convertRoutesToDataRoutes; exports.matchRoutes = matchRoutes; exports.matchRoutesImpl = matchRoutesImpl; exports.generatePath = generatePath; exports.matchPath = matchPath; exports.stripBasename = stripBasename; exports.resolvePath = resolvePath; exports.resolveTo = resolveTo; exports.joinPaths = joinPaths; exports.data = data; exports.redirect = redirect; exports.redirectDocument = redirectDocument; exports.replace = replace; exports.SUPPORTED_ERROR_TYPES = SUPPORTED_ERROR_TYPES; exports.ErrorResponseImpl = ErrorResponseImpl; exports.isRouteErrorResponse = isRouteErrorResponse; exports.parseToInfo = parseToInfo; exports.escapeHtml = escapeHtml; exports.escapeAttribute = escapeAttribute; exports.encode = encode; exports.instrumentHandler = instrumentHandler; exports.validateNavigationTarget = validateNavigationTarget; exports.IDLE_NAVIGATION = IDLE_NAVIGATION; exports.IDLE_FETCHER = IDLE_FETCHER; exports.IDLE_BLOCKER = IDLE_BLOCKER; exports.createRouter = createRouter; exports.createStaticHandler = createStaticHandler; exports.getStaticContextFromError = getStaticContextFromError; exports.hasInvalidProtocol = hasInvalidProtocol; exports.isDataWithResponseInit = isDataWithResponseInit; exports.isResponse = isResponse; exports.isRedirectStatusCode = isRedirectStatusCode; exports.isRedirectResponse = isRedirectResponse; exports.isMutationMethod = isMutationMethod; exports.createRequestInit = createRequestInit; exports.SingleFetchRedirectSymbol = SingleFetchRedirectSymbol; exports.SINGLE_FETCH_REDIRECT_STATUS = SINGLE_FETCH_REDIRECT_STATUS; exports.NO_BODY_STATUS_CODES = NO_BODY_STATUS_CODES; exports.StreamTransfer = StreamTransfer; exports.getTurboStreamSingleFetchDataStrategy = getTurboStreamSingleFetchDataStrategy; exports.getSingleFetchDataStrategyImpl = getSingleFetchDataStrategyImpl; exports.stripIndexParam = stripIndexParam; exports.singleFetchUrl = singleFetchUrl; exports.decodeViaTurboStream = decodeViaTurboStream; exports.DataRouterContext = DataRouterContext; exports.DataRouterStateContext = DataRouterStateContext; exports.RSCRouterContext = RSCRouterContext; exports.ViewTransitionContext = ViewTransitionContext; exports.FetchersContext = FetchersContext; exports.AwaitContextProvider = AwaitContextProvider; exports.NavigationContext = NavigationContext; exports.LocationContext = LocationContext; exports.RouteContext = RouteContext; exports.ENABLE_DEV_WARNINGS = ENABLE_DEV_WARNINGS; exports.warnOnce = warnOnce; exports.decodeRedirectErrorDigest = decodeRedirectErrorDigest; exports.decodeRouteErrorResponseDigest = decodeRouteErrorResponseDigest; exports.useHref = useHref; exports.useInRouterContext = useInRouterContext; exports.useLocation = useLocation; exports.useNavigationType = useNavigationType; exports.useMatch = useMatch; exports.useNavigate = useNavigate; exports.useOutletContext = useOutletContext; exports.useOutlet = useOutlet; exports.useParams = useParams; exports.useResolvedPath = useResolvedPath; exports.useRoutes = useRoutes; exports.useRouteId = useRouteId; exports.useNavigation = useNavigation; exports.useRevalidator = useRevalidator; exports.useMatches = useMatches; exports.useLoaderData = useLoaderData; exports.useRouteLoaderData = useRouteLoaderData; exports.useActionData = useActionData; exports.useRouteError = useRouteError; exports.useAsyncValue = useAsyncValue; exports.useAsyncError = useAsyncError; exports.useBlocker = useBlocker; exports.useRoute = useRoute; exports.useRouterState = useRouterState; exports.RemixErrorBoundary = RemixErrorBoundary; exports.createServerRoutes = createServerRoutes; exports.createClientRoutesWithHMRRevalidationOptOut = createClientRoutesWithHMRRevalidationOptOut; exports.noActionDefinedError = noActionDefinedError; exports.createClientRoutes = createClientRoutes; exports.shouldHydrateRouteLoader = shouldHydrateRouteLoader; exports.URL_LIMIT = URL_LIMIT; exports.getPathsWithAncestors = getPathsWithAncestors; exports.isFogOfWarEnabled = isFogOfWarEnabled; exports.shouldUseInitialRouteDiscovery = shouldUseInitialRouteDiscovery; exports.getPatchRoutesOnNavigationFunction = getPatchRoutesOnNavigationFunction; exports.useFogOFWarDiscovery = useFogOFWarDiscovery; exports.getManifestPath = getManifestPath; exports.FrameworkContext = FrameworkContext; exports.usePrefetchBehavior = usePrefetchBehavior; exports.CRITICAL_CSS_DATA_ATTRIBUTE = CRITICAL_CSS_DATA_ATTRIBUTE; exports.Links = Links; exports.PrefetchPageLinks = PrefetchPageLinks; exports.Meta = Meta; exports.setIsHydrated = setIsHydrated; exports.Scripts = Scripts; exports.mergeRefs = mergeRefs; exports.mapRouteProperties = mapRouteProperties; exports.hydrationRouteProperties = hydrationRouteProperties; exports.createMemoryRouter = createMemoryRouter; exports.RouterProvider = RouterProvider; exports.DataRoutes = DataRoutes2; exports.MemoryRouter = MemoryRouter; exports.Navigate = Navigate; exports.Outlet = Outlet; exports.Route = Route; exports.Router = Router; exports.Routes = Routes; exports.Await = Await; exports.createRoutesFromChildren = createRoutesFromChildren; exports.createRoutesFromElements = createRoutesFromElements; exports.renderMatches = renderMatches; exports.WithComponentProps = WithComponentProps; exports.withComponentProps = withComponentProps; exports.WithHydrateFallbackProps = WithHydrateFallbackProps; exports.withHydrateFallbackProps = withHydrateFallbackProps; exports.WithErrorBoundaryProps = WithErrorBoundaryProps; exports.withErrorBoundaryProps = withErrorBoundaryProps;
10476
+
10477
+ exports.ABSOLUTE_URL_REGEX = ABSOLUTE_URL_REGEX; exports.PROTOCOL_RELATIVE_URL_REGEX = PROTOCOL_RELATIVE_URL_REGEX; exports.Action = Action; exports.createMemoryHistory = createMemoryHistory; exports.createBrowserHistory = createBrowserHistory; exports.createHashHistory = createHashHistory; exports.invariant = invariant; exports.warning = warning; exports.createPath = createPath; exports.parsePath = parsePath; exports.validateDocumentNavigationTarget = validateDocumentNavigationTarget; exports.validateNavigationTarget = validateNavigationTarget; exports.createContext = createContext; exports.RouterContextProvider = RouterContextProvider; exports.convertRoutesToDataRoutes = convertRoutesToDataRoutes; exports.matchRoutes = matchRoutes; exports.matchRoutesImpl = matchRoutesImpl; exports.generatePath = generatePath; exports.matchPath = matchPath; exports.stripBasename = stripBasename; exports.resolvePath = resolvePath; exports.resolveTo = resolveTo; exports.joinPaths = joinPaths; exports.data = data; exports.redirect = redirect; exports.redirectDocument = redirectDocument; exports.replace = replace; exports.SUPPORTED_ERROR_TYPES = SUPPORTED_ERROR_TYPES; exports.ErrorResponseImpl = ErrorResponseImpl; exports.isRouteErrorResponse = isRouteErrorResponse; exports.parseToInfo = parseToInfo; exports.escapeHtml = escapeHtml; exports.escapeAttribute = escapeAttribute; exports.encode = encode; exports.instrumentHandler = instrumentHandler; exports.IDLE_NAVIGATION = IDLE_NAVIGATION; exports.IDLE_FETCHER = IDLE_FETCHER; exports.IDLE_BLOCKER = IDLE_BLOCKER; exports.createRouter = createRouter; exports.createStaticHandler = createStaticHandler; exports.getStaticContextFromError = getStaticContextFromError; exports.hasInvalidProtocol = hasInvalidProtocol; exports.isDataWithResponseInit = isDataWithResponseInit; exports.isResponse = isResponse; exports.isRedirectStatusCode = isRedirectStatusCode; exports.isRedirectResponse = isRedirectResponse; exports.isMutationMethod = isMutationMethod; exports.createRequestInit = createRequestInit; exports.SingleFetchRedirectSymbol = SingleFetchRedirectSymbol; exports.SINGLE_FETCH_REDIRECT_STATUS = SINGLE_FETCH_REDIRECT_STATUS; exports.NO_BODY_STATUS_CODES = NO_BODY_STATUS_CODES; exports.StreamTransfer = StreamTransfer; exports.getTurboStreamSingleFetchDataStrategy = getTurboStreamSingleFetchDataStrategy; exports.getSingleFetchDataStrategyImpl = getSingleFetchDataStrategyImpl; exports.stripIndexParam = stripIndexParam; exports.singleFetchUrl = singleFetchUrl; exports.decodeViaTurboStream = decodeViaTurboStream; exports.DataRouterContext = DataRouterContext; exports.DataRouterStateContext = DataRouterStateContext; exports.RSCRouterContext = RSCRouterContext; exports.ViewTransitionContext = ViewTransitionContext; exports.FetchersContext = FetchersContext; exports.AwaitContextProvider = AwaitContextProvider; exports.NavigationContext = NavigationContext; exports.LocationContext = LocationContext; exports.RouteContext = RouteContext; exports.ENABLE_DEV_WARNINGS = ENABLE_DEV_WARNINGS; exports.warnOnce = warnOnce; exports.decodeRedirectErrorDigest = decodeRedirectErrorDigest; exports.decodeRouteErrorResponseDigest = decodeRouteErrorResponseDigest; exports.useHref = useHref; exports.useInRouterContext = useInRouterContext; exports.useLocation = useLocation; exports.useNavigationType = useNavigationType; exports.useMatch = useMatch; exports.useNavigate = useNavigate; exports.useOutletContext = useOutletContext; exports.useOutlet = useOutlet; exports.useParams = useParams; exports.useResolvedPath = useResolvedPath; exports.useRoutes = useRoutes; exports.useRouteId = useRouteId; exports.useNavigation = useNavigation; exports.useRevalidator = useRevalidator; exports.useMatches = useMatches; exports.useLoaderData = useLoaderData; exports.useRouteLoaderData = useRouteLoaderData; exports.useActionData = useActionData; exports.useRouteError = useRouteError; exports.useAsyncValue = useAsyncValue; exports.useAsyncError = useAsyncError; exports.useBlocker = useBlocker; exports.useRoute = useRoute; exports.useRouterState = useRouterState; exports.RemixErrorBoundary = RemixErrorBoundary; exports.createServerRoutes = createServerRoutes; exports.createClientRoutesWithHMRRevalidationOptOut = createClientRoutesWithHMRRevalidationOptOut; exports.noActionDefinedError = noActionDefinedError; exports.createClientRoutes = createClientRoutes; exports.shouldHydrateRouteLoader = shouldHydrateRouteLoader; exports.URL_LIMIT = URL_LIMIT; exports.getPathsWithAncestors = getPathsWithAncestors; exports.isFogOfWarEnabled = isFogOfWarEnabled; exports.shouldUseInitialRouteDiscovery = shouldUseInitialRouteDiscovery; exports.getPatchRoutesOnNavigationFunction = getPatchRoutesOnNavigationFunction; exports.useFogOFWarDiscovery = useFogOFWarDiscovery; exports.getManifestPath = getManifestPath; exports.FrameworkContext = FrameworkContext; exports.usePrefetchBehavior = usePrefetchBehavior; exports.CRITICAL_CSS_DATA_ATTRIBUTE = CRITICAL_CSS_DATA_ATTRIBUTE; exports.Links = Links; exports.PrefetchPageLinks = PrefetchPageLinks; exports.Meta = Meta; exports.setIsHydrated = setIsHydrated; exports.Scripts = Scripts; exports.mergeRefs = mergeRefs; exports.mapRouteProperties = mapRouteProperties; exports.hydrationRouteProperties = hydrationRouteProperties; exports.createMemoryRouter = createMemoryRouter; exports.RouterProvider = RouterProvider; exports.DataRoutes = DataRoutes2; exports.MemoryRouter = MemoryRouter; exports.Navigate = Navigate; exports.Outlet = Outlet; exports.Route = Route; exports.Router = Router; exports.Routes = Routes; exports.Await = Await; exports.createRoutesFromChildren = createRoutesFromChildren; exports.createRoutesFromElements = createRoutesFromElements; exports.renderMatches = renderMatches; exports.WithComponentProps = WithComponentProps; exports.withComponentProps = withComponentProps; exports.WithHydrateFallbackProps = WithHydrateFallbackProps; exports.withHydrateFallbackProps = withHydrateFallbackProps; exports.WithErrorBoundaryProps = WithErrorBoundaryProps; exports.withErrorBoundaryProps = withErrorBoundaryProps;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * react-router v7.18.5
2
+ * react-router v7.18.6
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -386,6 +386,67 @@ function createBrowserURLImpl(windowImpl, to, isAbsolute = false) {
386
386
  return new URL(href, base);
387
387
  }
388
388
 
389
+ // lib/router/navigation.ts
390
+ var DEFAULT_NAVIGATION_URL = new URL("http://localhost");
391
+ function getNavigatorCurrentUrl(navigator) {
392
+ if (navigator.createURL) {
393
+ return navigator.createURL("/");
394
+ }
395
+ try {
396
+ return new URL(navigator.createHref("/"), DEFAULT_NAVIGATION_URL);
397
+ } catch {
398
+ return DEFAULT_NAVIGATION_URL;
399
+ }
400
+ }
401
+ function isSameOrigin(a, b) {
402
+ return a.origin === b.origin && (a.origin !== "null" || a.protocol === b.protocol && a.host === b.host);
403
+ }
404
+ function isExplicitUrl(destination, target) {
405
+ if (destination.startsWith("//")) {
406
+ return true;
407
+ }
408
+ let protocol = target.protocol.toLowerCase();
409
+ if (!destination.toLowerCase().startsWith(protocol)) {
410
+ return false;
411
+ }
412
+ return target.host === "" || destination.slice(protocol.length).startsWith("//");
413
+ }
414
+ function validateDocumentNavigationTarget(destination) {
415
+ let normalized = destination.replace(/[\t\n\r]/g, "");
416
+ let start = 0;
417
+ while (normalized.charCodeAt(start) <= 32) start++;
418
+ normalized = normalized.slice(start);
419
+ if (!ABSOLUTE_URL_REGEX.test(normalized)) return;
420
+ let target;
421
+ try {
422
+ target = new URL(destination, DEFAULT_NAVIGATION_URL);
423
+ } catch {
424
+ return;
425
+ }
426
+ if (!isExplicitUrl(destination, target)) {
427
+ throw new Error("External navigation is not allowed");
428
+ }
429
+ }
430
+ function validateNavigationTarget(original, resolved, currentUrl, externalPolicy) {
431
+ let originalUrl = null;
432
+ try {
433
+ originalUrl = original == null ? null : new URL(original, currentUrl);
434
+ } catch {
435
+ }
436
+ let resolvedUrl = new URL(resolved, currentUrl);
437
+ let originalIsExternal = originalUrl != null && !isSameOrigin(originalUrl, currentUrl);
438
+ let resolvedIsExternal = !isSameOrigin(resolvedUrl, currentUrl);
439
+ if (externalPolicy === "reject") {
440
+ if (originalIsExternal || resolvedIsExternal) {
441
+ throw new Error("External navigation is not allowed");
442
+ }
443
+ } else if (resolvedIsExternal) {
444
+ if (originalUrl == null || !isExplicitUrl(original, originalUrl) || !isSameOrigin(originalUrl, resolvedUrl)) {
445
+ throw new Error("External navigation is not allowed");
446
+ }
447
+ }
448
+ }
449
+
389
450
  // lib/router/utils.ts
390
451
  function createContext(defaultValue) {
391
452
  return { defaultValue };
@@ -767,7 +828,12 @@ function generatePath(originalPath, params = {}) {
767
828
  }
768
829
  return segment.replace(/\?$/g, "");
769
830
  }).filter((segment) => !!segment);
770
- return prefix + segments.join("/");
831
+ let result = (prefix + segments.join("/")).replace(/^[\\/]{2,}/, "/");
832
+ if (!prefix && (path.startsWith(":") || path === "*")) {
833
+ result = result.replace(/^([a-z][a-z0-9+.-]*):/i, "$1%3A");
834
+ }
835
+ validateDocumentNavigationTarget(result);
836
+ return result;
771
837
  }
772
838
  function matchPath(pattern, pathname) {
773
839
  if (typeof pattern === "string") {
@@ -995,6 +1061,7 @@ function data(data2, init) {
995
1061
  );
996
1062
  }
997
1063
  var redirect = (url, init = 302) => {
1064
+ validateDocumentNavigationTarget(url);
998
1065
  let responseInit = init;
999
1066
  if (typeof responseInit === "number") {
1000
1067
  responseInit = { status: responseInit };
@@ -1350,51 +1417,6 @@ function isPlainObject(thing) {
1350
1417
  return proto === Object.prototype || proto === null || Object.getOwnPropertyNames(proto).sort().join("\0") === objectProtoNames;
1351
1418
  }
1352
1419
 
1353
- // lib/router/navigation.ts
1354
- var DEFAULT_NAVIGATION_URL = new URL("http://localhost");
1355
- function getNavigatorCurrentUrl(navigator) {
1356
- if (navigator.createURL) {
1357
- return navigator.createURL("/");
1358
- }
1359
- try {
1360
- return new URL(navigator.createHref("/"), DEFAULT_NAVIGATION_URL);
1361
- } catch {
1362
- return DEFAULT_NAVIGATION_URL;
1363
- }
1364
- }
1365
- function isSameOrigin(a, b) {
1366
- return a.origin === b.origin && (a.origin !== "null" || a.protocol === b.protocol && a.host === b.host);
1367
- }
1368
- function isExplicitUrl(destination, target) {
1369
- if (destination.startsWith("//")) {
1370
- return true;
1371
- }
1372
- let protocol = target.protocol.toLowerCase();
1373
- if (!destination.toLowerCase().startsWith(protocol)) {
1374
- return false;
1375
- }
1376
- return target.host === "" || destination.slice(protocol.length).startsWith("//");
1377
- }
1378
- function validateNavigationTarget(original, resolved, currentUrl, externalPolicy) {
1379
- let originalUrl = null;
1380
- try {
1381
- originalUrl = original == null ? null : new URL(original, currentUrl);
1382
- } catch {
1383
- }
1384
- let resolvedUrl = new URL(resolved, currentUrl);
1385
- let originalIsExternal = originalUrl != null && !isSameOrigin(originalUrl, currentUrl);
1386
- let resolvedIsExternal = !isSameOrigin(resolvedUrl, currentUrl);
1387
- if (externalPolicy === "reject") {
1388
- if (originalIsExternal || resolvedIsExternal) {
1389
- throw new Error("External navigation is not allowed");
1390
- }
1391
- } else if (resolvedIsExternal) {
1392
- if (originalUrl == null || !isExplicitUrl(original, originalUrl) || !isSameOrigin(originalUrl, resolvedUrl)) {
1393
- throw new Error("External navigation is not allowed");
1394
- }
1395
- }
1396
- }
1397
-
1398
1420
  // lib/router/router.ts
1399
1421
  var validMutationMethodsArr = [
1400
1422
  "POST",
@@ -2527,6 +2549,12 @@ function createRouter(init) {
2527
2549
  routeId,
2528
2550
  opts?.relative
2529
2551
  );
2552
+ validateNavigationTarget(
2553
+ null,
2554
+ normalizedPath,
2555
+ init.history.createURL("/"),
2556
+ "reject"
2557
+ );
2530
2558
  let matches = matchRoutesImpl(
2531
2559
  routesToUse,
2532
2560
  normalizedPath,
@@ -5297,6 +5325,12 @@ function normalizeRelativeRoutingRedirectResponse(response, request, routeId, ma
5297
5325
  location,
5298
5326
  "Redirects returned/thrown from loaders/actions must have a Location header"
5299
5327
  );
5328
+ validateNavigationTarget(
5329
+ location,
5330
+ location,
5331
+ new URL(request.url),
5332
+ "allow-explicit"
5333
+ );
5300
5334
  if (!isAbsoluteUrl(location)) {
5301
5335
  let trimmedMatches = matches.slice(
5302
5336
  0,
@@ -8126,20 +8160,22 @@ function encode(input, options) {
8126
8160
  };
8127
8161
  const textEncoder = new TextEncoder();
8128
8162
  let lastSentIndex = 0;
8163
+ let cancelled = false;
8129
8164
  const readable = new ReadableStream({
8130
8165
  async start(controller) {
8166
+ const enqueue = (chunk) => {
8167
+ if (!cancelled) controller.enqueue(chunk);
8168
+ };
8131
8169
  const id = await flatten.call(encoder, input);
8132
8170
  if (Array.isArray(id)) {
8133
8171
  throw new Error("This should never happen");
8134
8172
  }
8135
8173
  if (id < 0) {
8136
- controller.enqueue(textEncoder.encode(`${id}
8174
+ enqueue(textEncoder.encode(`${id}
8137
8175
  `));
8138
8176
  } else {
8139
- controller.enqueue(
8140
- textEncoder.encode(`[${encoder.stringified.join(",")}]
8141
- `)
8142
- );
8177
+ enqueue(textEncoder.encode(`[${encoder.stringified.join(",")}]
8178
+ `));
8143
8179
  lastSentIndex = encoder.stringified.length - 1;
8144
8180
  }
8145
8181
  const seenPromises = /* @__PURE__ */ new WeakSet();
@@ -8174,7 +8210,7 @@ function encode(input, options) {
8174
8210
  processingChain = processingChain.then(async () => {
8175
8211
  const id2 = await flatten.call(encoder, resolved);
8176
8212
  if (Array.isArray(id2)) {
8177
- controller.enqueue(
8213
+ enqueue(
8178
8214
  textEncoder.encode(
8179
8215
  `${TYPE_PROMISE}${deferredId}:[["${TYPE_PREVIOUS_RESOLVED}",${id2[0]}]]
8180
8216
  `
@@ -8183,7 +8219,7 @@ function encode(input, options) {
8183
8219
  encoder.index++;
8184
8220
  lastSentIndex++;
8185
8221
  } else if (id2 < 0) {
8186
- controller.enqueue(
8222
+ enqueue(
8187
8223
  textEncoder.encode(
8188
8224
  `${TYPE_PROMISE}${deferredId}:${id2}
8189
8225
  `
@@ -8191,7 +8227,7 @@ function encode(input, options) {
8191
8227
  );
8192
8228
  } else {
8193
8229
  const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
8194
- controller.enqueue(
8230
+ enqueue(
8195
8231
  textEncoder.encode(
8196
8232
  `${TYPE_PROMISE}${deferredId}:[${values}]
8197
8233
  `
@@ -8209,7 +8245,7 @@ function encode(input, options) {
8209
8245
  }
8210
8246
  const id2 = await flatten.call(encoder, reason);
8211
8247
  if (Array.isArray(id2)) {
8212
- controller.enqueue(
8248
+ enqueue(
8213
8249
  textEncoder.encode(
8214
8250
  `${TYPE_ERROR}${deferredId}:[["${TYPE_PREVIOUS_RESOLVED}",${id2[0]}]]
8215
8251
  `
@@ -8218,7 +8254,7 @@ function encode(input, options) {
8218
8254
  encoder.index++;
8219
8255
  lastSentIndex++;
8220
8256
  } else if (id2 < 0) {
8221
- controller.enqueue(
8257
+ enqueue(
8222
8258
  textEncoder.encode(
8223
8259
  `${TYPE_ERROR}${deferredId}:${id2}
8224
8260
  `
@@ -8226,7 +8262,7 @@ function encode(input, options) {
8226
8262
  );
8227
8263
  } else {
8228
8264
  const values = encoder.stringified.slice(lastSentIndex + 1).join(",");
8229
- controller.enqueue(
8265
+ enqueue(
8230
8266
  textEncoder.encode(
8231
8267
  `${TYPE_ERROR}${deferredId}:[${values}]
8232
8268
  `
@@ -8248,8 +8284,11 @@ function encode(input, options) {
8248
8284
  }
8249
8285
  await Promise.all(Object.values(encoder.deferred));
8250
8286
  await processingChain;
8251
- controller.close();
8287
+ if (!cancelled) controller.close();
8252
8288
  onComplete?.();
8289
+ },
8290
+ cancel() {
8291
+ cancelled = true;
8253
8292
  }
8254
8293
  });
8255
8294
  return readable;
@@ -10433,7 +10472,7 @@ var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "un
10433
10472
  try {
10434
10473
  if (isBrowser2) {
10435
10474
  window.__reactRouterVersion = // @ts-expect-error
10436
- "7.18.5";
10475
+ "7.18.6";
10437
10476
  }
10438
10477
  } catch (e) {
10439
10478
  }
@@ -10682,6 +10721,8 @@ var Link = React10.forwardRef(
10682
10721
  }
10683
10722
  }
10684
10723
  let isSpaLink = !(parsed.isExternal || reloadDocument);
10724
+ let renderedHref = (isSpaLink ? maskedHref : void 0) || parsed.absoluteURL || href;
10725
+ validateDocumentNavigationTarget(renderedHref);
10685
10726
  let link = (
10686
10727
  // eslint-disable-next-line jsx-a11y/anchor-has-content
10687
10728
  /* @__PURE__ */ React10.createElement(
@@ -10689,7 +10730,7 @@ var Link = React10.forwardRef(
10689
10730
  {
10690
10731
  ...rest,
10691
10732
  ...prefetchHandlers,
10692
- href: (isSpaLink ? maskedHref : void 0) || parsed.absoluteURL || href,
10733
+ href: renderedHref,
10693
10734
  onClick: isSpaLink ? handleClick : onClick,
10694
10735
  ref: mergeRefs(forwardedRef, prefetchRef),
10695
10736
  target,
@@ -11055,7 +11096,9 @@ function useFormAction(action, { relative } = {}) {
11055
11096
  if (basename !== "/") {
11056
11097
  path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
11057
11098
  }
11058
- return createPath(path);
11099
+ let formAction = createPath(path);
11100
+ validateDocumentNavigationTarget(formAction);
11101
+ return formAction;
11059
11102
  }
11060
11103
  function useFetcher({
11061
11104
  key
@@ -11591,6 +11634,8 @@ export {
11591
11634
  invariant,
11592
11635
  createPath,
11593
11636
  parsePath,
11637
+ validateDocumentNavigationTarget,
11638
+ validateNavigationTarget,
11594
11639
  createContext,
11595
11640
  RouterContextProvider,
11596
11641
  convertRoutesToDataRoutes,
@@ -11607,7 +11652,6 @@ export {
11607
11652
  ErrorResponseImpl,
11608
11653
  isRouteErrorResponse,
11609
11654
  instrumentHandler,
11610
- validateNavigationTarget,
11611
11655
  IDLE_NAVIGATION,
11612
11656
  IDLE_FETCHER,
11613
11657
  IDLE_BLOCKER,