@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/dist/router.js CHANGED
@@ -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
  *
@@ -1428,6 +1428,7 @@ const IDLE_BLOCKER = {
1428
1428
  reset: undefined,
1429
1429
  location: undefined
1430
1430
  };
1431
+ const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1431
1432
  const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
1432
1433
  const isServer = !isBrowser; //#endregion
1433
1434
  ////////////////////////////////////////////////////////////////////////////////
@@ -1535,10 +1536,7 @@ function createRouter(init) {
1535
1536
  // promise resolves we update loaderData. If a new navigation starts we
1536
1537
  // cancel active deferreds for eliminated routes.
1537
1538
 
1538
- let activeDeferreds = new Map(); // We ony support a single active blocker at the moment since we don't have
1539
- // any compelling use cases for multi-blocker yet
1540
-
1541
- let activeBlocker = null; // Store blocker functions in a separate Map outside of router state since
1539
+ let activeDeferreds = new Map(); // Store blocker functions in a separate Map outside of router state since
1542
1540
  // we don't need to update UI state if they change
1543
1541
 
1544
1542
  let blockerFunctions = new Map(); // Flag to ignore the next history update, so we can revert the URL change on
@@ -1565,7 +1563,7 @@ function createRouter(init) {
1565
1563
  return;
1566
1564
  }
1567
1565
 
1568
- 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.");
1566
+ 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.");
1569
1567
  let blockerKey = shouldBlockNavigation({
1570
1568
  currentLocation: state.location,
1571
1569
  nextLocation: location,
@@ -2498,9 +2496,9 @@ function createRouter(init) {
2498
2496
  }, isFetchActionRedirect ? {
2499
2497
  _isFetchActionRedirect: true
2500
2498
  } : {}));
2501
- invariant(redirectLocation, "Expected a location on the redirect navigation"); // Check if this an external redirect that goes to a new origin
2499
+ invariant(redirectLocation, "Expected a location on the redirect navigation"); // Check if this an absolute external redirect that goes to a new origin
2502
2500
 
2503
- if (isBrowser && typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {
2501
+ if (ABSOLUTE_URL_REGEX.test(redirect.location) && isBrowser && typeof ((_window = window) == null ? void 0 : _window.location) !== "undefined") {
2504
2502
  let newOrigin = init.history.createURL(redirect.location).origin;
2505
2503
 
2506
2504
  if (window.location.origin !== newOrigin) {
@@ -2678,13 +2676,6 @@ function createRouter(init) {
2678
2676
 
2679
2677
  if (blockerFunctions.get(key) !== fn) {
2680
2678
  blockerFunctions.set(key, fn);
2681
-
2682
- if (activeBlocker == null) {
2683
- // This is now the active blocker
2684
- activeBlocker = key;
2685
- } else if (key !== activeBlocker) {
2686
- warning(false, "A router only supports one blocker at a time");
2687
- }
2688
2679
  }
2689
2680
 
2690
2681
  return blocker;
@@ -2693,10 +2684,6 @@ function createRouter(init) {
2693
2684
  function deleteBlocker(key) {
2694
2685
  state.blockers.delete(key);
2695
2686
  blockerFunctions.delete(key);
2696
-
2697
- if (activeBlocker === key) {
2698
- activeBlocker = null;
2699
- }
2700
2687
  } // Utility function to update blockers, ensuring valid state transitions
2701
2688
 
2702
2689
 
@@ -2718,15 +2705,19 @@ function createRouter(init) {
2718
2705
  historyAction
2719
2706
  } = _ref2;
2720
2707
 
2721
- if (activeBlocker == null) {
2708
+ if (blockerFunctions.size === 0) {
2722
2709
  return;
2723
- } // We only allow a single blocker at the moment. This will need to be
2724
- // updated if we enhance to support multiple blockers in the future
2710
+ } // We ony support a single active blocker at the moment since we don't have
2711
+ // any compelling use cases for multi-blocker yet
2712
+
2725
2713
 
2714
+ if (blockerFunctions.size > 1) {
2715
+ warning(false, "A router only supports one blocker at a time");
2716
+ }
2726
2717
 
2727
- let blockerFunction = blockerFunctions.get(activeBlocker);
2728
- invariant(blockerFunction, "Could not find a function for the active blocker");
2729
- let blocker = state.blockers.get(activeBlocker);
2718
+ let entries = Array.from(blockerFunctions.entries());
2719
+ let [blockerKey, blockerFunction] = entries[entries.length - 1];
2720
+ let blocker = state.blockers.get(blockerKey);
2730
2721
 
2731
2722
  if (blocker && blocker.state === "proceeding") {
2732
2723
  // If the blocker is currently proceeding, we don't need to re-check
@@ -2741,7 +2732,7 @@ function createRouter(init) {
2741
2732
  nextLocation,
2742
2733
  historyAction
2743
2734
  })) {
2744
- return activeBlocker;
2735
+ return blockerKey;
2745
2736
  }
2746
2737
  }
2747
2738
 
@@ -3491,10 +3482,9 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
3491
3482
 
3492
3483
  if (redirectStatusCodes.has(status)) {
3493
3484
  let location = result.headers.get("Location");
3494
- invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
3495
- let isAbsolute = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(location); // Support relative routing in internal redirects
3485
+ invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header"); // Support relative routing in internal redirects
3496
3486
 
3497
- if (!isAbsolute) {
3487
+ if (!ABSOLUTE_URL_REGEX.test(location)) {
3498
3488
  let activeMatches = matches.slice(0, matches.indexOf(match) + 1);
3499
3489
  let routePathnames = getPathContributingMatches(activeMatches).map(match => match.pathnameBase);
3500
3490
  let resolvedLocation = resolveTo(location, routePathnames, new URL(request.url).pathname);