@remix-run/router 1.3.1 → 1.3.2-pre.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # `@remix-run/router`
2
2
 
3
+ ## 1.3.2-pre.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Remove inaccurate console warning for POP navigations ([#10030](https://github.com/remix-run/react-router/pull/10030))
8
+ - Only check for differing origin on absolute URL redirects ([#10033](https://github.com/remix-run/react-router/pull/10033))
9
+
3
10
  ## 1.3.1
4
11
 
5
12
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.3.1
2
+ * @remix-run/router v1.3.2-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1476,6 +1476,7 @@ const IDLE_BLOCKER = {
1476
1476
  reset: undefined,
1477
1477
  location: undefined
1478
1478
  };
1479
+ const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1479
1480
  const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
1480
1481
  const isServer = !isBrowser; //#endregion
1481
1482
  ////////////////////////////////////////////////////////////////////////////////
@@ -1583,10 +1584,7 @@ function createRouter(init) {
1583
1584
  // promise resolves we update loaderData. If a new navigation starts we
1584
1585
  // cancel active deferreds for eliminated routes.
1585
1586
 
1586
- let activeDeferreds = new Map(); // We ony support a single active blocker at the moment since we don't have
1587
- // any compelling use cases for multi-blocker yet
1588
-
1589
- let activeBlocker = null; // Store blocker functions in a separate Map outside of router state since
1587
+ let activeDeferreds = new Map(); // Store blocker functions in a separate Map outside of router state since
1590
1588
  // we don't need to update UI state if they change
1591
1589
 
1592
1590
  let blockerFunctions = new Map(); // Flag to ignore the next history update, so we can revert the URL change on
@@ -1613,7 +1611,7 @@ function createRouter(init) {
1613
1611
  return;
1614
1612
  }
1615
1613
 
1616
- warning(activeBlocker != null && delta === null, "You are trying to use a blocker on a POP navigation to a location " + "that was not created by @remix-run/router. This will fail silently in " + "production. This can happen if you are navigating outside the router " + "via `window.history.pushState`/`window.location.hash` instead of using " + "router navigation APIs. This can also happen if you are using " + "createHashRouter and the user manually changes the URL.");
1614
+ warning(blockerFunctions.size === 0 || delta != null, "You are trying to use a blocker on a POP navigation to a location " + "that was not created by @remix-run/router. This will fail silently in " + "production. This can happen if you are navigating outside the router " + "via `window.history.pushState`/`window.location.hash` instead of using " + "router navigation APIs. This can also happen if you are using " + "createHashRouter and the user manually changes the URL.");
1617
1615
  let blockerKey = shouldBlockNavigation({
1618
1616
  currentLocation: state.location,
1619
1617
  nextLocation: location,
@@ -2547,9 +2545,9 @@ function createRouter(init) {
2547
2545
  }, isFetchActionRedirect ? {
2548
2546
  _isFetchActionRedirect: true
2549
2547
  } : {}));
2550
- invariant(redirectLocation, "Expected a location on the redirect navigation"); // Check if this an external redirect that goes to a new origin
2548
+ invariant(redirectLocation, "Expected a location on the redirect navigation"); // Check if this an absolute external redirect that goes to a new origin
2551
2549
 
2552
- if (isBrowser && typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {
2550
+ if (ABSOLUTE_URL_REGEX.test(redirect.location) && isBrowser && typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {
2553
2551
  let newOrigin = init.history.createURL(redirect.location).origin;
2554
2552
 
2555
2553
  if (window.location.origin !== newOrigin) {
@@ -2727,13 +2725,6 @@ function createRouter(init) {
2727
2725
 
2728
2726
  if (blockerFunctions.get(key) !== fn) {
2729
2727
  blockerFunctions.set(key, fn);
2730
-
2731
- if (activeBlocker == null) {
2732
- // This is now the active blocker
2733
- activeBlocker = key;
2734
- } else if (key !== activeBlocker) {
2735
- warning(false, "A router only supports one blocker at a time");
2736
- }
2737
2728
  }
2738
2729
 
2739
2730
  return blocker;
@@ -2742,10 +2733,6 @@ function createRouter(init) {
2742
2733
  function deleteBlocker(key) {
2743
2734
  state.blockers.delete(key);
2744
2735
  blockerFunctions.delete(key);
2745
-
2746
- if (activeBlocker === key) {
2747
- activeBlocker = null;
2748
- }
2749
2736
  } // Utility function to update blockers, ensuring valid state transitions
2750
2737
 
2751
2738
 
@@ -2767,15 +2754,19 @@ function createRouter(init) {
2767
2754
  historyAction
2768
2755
  } = _ref2;
2769
2756
 
2770
- if (activeBlocker == null) {
2757
+ if (blockerFunctions.size === 0) {
2771
2758
  return;
2772
- } // We only allow a single blocker at the moment. This will need to be
2773
- // updated if we enhance to support multiple blockers in the future
2759
+ } // We ony support a single active blocker at the moment since we don't have
2760
+ // any compelling use cases for multi-blocker yet
2761
+
2774
2762
 
2763
+ if (blockerFunctions.size > 1) {
2764
+ warning(false, "A router only supports one blocker at a time");
2765
+ }
2775
2766
 
2776
- let blockerFunction = blockerFunctions.get(activeBlocker);
2777
- invariant(blockerFunction, "Could not find a function for the active blocker");
2778
- let blocker = state.blockers.get(activeBlocker);
2767
+ let entries = Array.from(blockerFunctions.entries());
2768
+ let [blockerKey, blockerFunction] = entries[entries.length - 1];
2769
+ let blocker = state.blockers.get(blockerKey);
2779
2770
 
2780
2771
  if (blocker && blocker.state === "proceeding") {
2781
2772
  // If the blocker is currently proceeding, we don't need to re-check
@@ -2790,7 +2781,7 @@ function createRouter(init) {
2790
2781
  nextLocation,
2791
2782
  historyAction
2792
2783
  })) {
2793
- return activeBlocker;
2784
+ return blockerKey;
2794
2785
  }
2795
2786
  }
2796
2787
 
@@ -3540,10 +3531,9 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
3540
3531
 
3541
3532
  if (redirectStatusCodes.has(status)) {
3542
3533
  let location = result.headers.get("Location");
3543
- invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
3544
- let isAbsolute = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(location); // Support relative routing in internal redirects
3534
+ invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header"); // Support relative routing in internal redirects
3545
3535
 
3546
- if (!isAbsolute) {
3536
+ if (!ABSOLUTE_URL_REGEX.test(location)) {
3547
3537
  let activeMatches = matches.slice(0, matches.indexOf(match) + 1);
3548
3538
  let routePathnames = getPathContributingMatches(activeMatches).map(match => match.pathnameBase);
3549
3539
  let resolvedLocation = resolveTo(location, routePathnames, new URL(request.url).pathname);