@remix-run/router 1.3.1-pre.0 → 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-pre.0
2
+ * @remix-run/router v1.3.2-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -402,23 +402,17 @@ function getUrlBasedHistory(getLocation, createHref, validateLocation, options)
402
402
  }
403
403
 
404
404
  function handlePop() {
405
- let nextAction = Action.Pop;
405
+ action = Action.Pop;
406
406
  let nextIndex = getIndex();
407
+ let delta = nextIndex == null ? null : nextIndex - index;
408
+ index = nextIndex;
407
409
 
408
- if (nextIndex != null) {
409
- let delta = nextIndex - index;
410
- action = nextAction;
411
- index = nextIndex;
412
-
413
- if (listener) {
414
- listener({
415
- action,
416
- location: history.location,
417
- delta
418
- });
419
- }
420
- } else {
421
- warning$1(false, "You are trying to perform a POP navigation to a location that was not " + "created by @remix-run/router. This will fail silently in production. " + "You should navigate via the router to avoid this situation (instead of " + "using window.history.pushState/window.location.hash).");
410
+ if (listener) {
411
+ listener({
412
+ action,
413
+ location: history.location,
414
+ delta
415
+ });
422
416
  }
423
417
  }
424
418
 
@@ -1434,6 +1428,7 @@ const IDLE_BLOCKER = {
1434
1428
  reset: undefined,
1435
1429
  location: undefined
1436
1430
  };
1431
+ const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1437
1432
  const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
1438
1433
  const isServer = !isBrowser; //#endregion
1439
1434
  ////////////////////////////////////////////////////////////////////////////////
@@ -1541,10 +1536,7 @@ function createRouter(init) {
1541
1536
  // promise resolves we update loaderData. If a new navigation starts we
1542
1537
  // cancel active deferreds for eliminated routes.
1543
1538
 
1544
- let activeDeferreds = new Map(); // We ony support a single active blocker at the moment since we don't have
1545
- // any compelling use cases for multi-blocker yet
1546
-
1547
- 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
1548
1540
  // we don't need to update UI state if they change
1549
1541
 
1550
1542
  let blockerFunctions = new Map(); // Flag to ignore the next history update, so we can revert the URL change on
@@ -1571,13 +1563,14 @@ function createRouter(init) {
1571
1563
  return;
1572
1564
  }
1573
1565
 
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.");
1574
1567
  let blockerKey = shouldBlockNavigation({
1575
1568
  currentLocation: state.location,
1576
1569
  nextLocation: location,
1577
1570
  historyAction
1578
1571
  });
1579
1572
 
1580
- if (blockerKey) {
1573
+ if (blockerKey && delta != null) {
1581
1574
  // Restore the URL to match the current UI, but don't update router state
1582
1575
  ignoreNextHistoryUpdate = true;
1583
1576
  init.history.go(delta * -1); // Put the blocker into a blocked state
@@ -2503,9 +2496,9 @@ function createRouter(init) {
2503
2496
  }, isFetchActionRedirect ? {
2504
2497
  _isFetchActionRedirect: true
2505
2498
  } : {}));
2506
- 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
2507
2500
 
2508
- 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") {
2509
2502
  let newOrigin = init.history.createURL(redirect.location).origin;
2510
2503
 
2511
2504
  if (window.location.origin !== newOrigin) {
@@ -2683,13 +2676,6 @@ function createRouter(init) {
2683
2676
 
2684
2677
  if (blockerFunctions.get(key) !== fn) {
2685
2678
  blockerFunctions.set(key, fn);
2686
-
2687
- if (activeBlocker == null) {
2688
- // This is now the active blocker
2689
- activeBlocker = key;
2690
- } else if (key !== activeBlocker) {
2691
- warning(false, "A router only supports one blocker at a time");
2692
- }
2693
2679
  }
2694
2680
 
2695
2681
  return blocker;
@@ -2698,10 +2684,6 @@ function createRouter(init) {
2698
2684
  function deleteBlocker(key) {
2699
2685
  state.blockers.delete(key);
2700
2686
  blockerFunctions.delete(key);
2701
-
2702
- if (activeBlocker === key) {
2703
- activeBlocker = null;
2704
- }
2705
2687
  } // Utility function to update blockers, ensuring valid state transitions
2706
2688
 
2707
2689
 
@@ -2723,15 +2705,19 @@ function createRouter(init) {
2723
2705
  historyAction
2724
2706
  } = _ref2;
2725
2707
 
2726
- if (activeBlocker == null) {
2708
+ if (blockerFunctions.size === 0) {
2727
2709
  return;
2728
- } // We only allow a single blocker at the moment. This will need to be
2729
- // 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
2730
2712
 
2731
2713
 
2732
- let blockerFunction = blockerFunctions.get(activeBlocker);
2733
- invariant(blockerFunction, "Could not find a function for the active blocker");
2734
- let blocker = state.blockers.get(activeBlocker);
2714
+ if (blockerFunctions.size > 1) {
2715
+ warning(false, "A router only supports one blocker at a time");
2716
+ }
2717
+
2718
+ let entries = Array.from(blockerFunctions.entries());
2719
+ let [blockerKey, blockerFunction] = entries[entries.length - 1];
2720
+ let blocker = state.blockers.get(blockerKey);
2735
2721
 
2736
2722
  if (blocker && blocker.state === "proceeding") {
2737
2723
  // If the blocker is currently proceeding, we don't need to re-check
@@ -2746,7 +2732,7 @@ function createRouter(init) {
2746
2732
  nextLocation,
2747
2733
  historyAction
2748
2734
  })) {
2749
- return activeBlocker;
2735
+ return blockerKey;
2750
2736
  }
2751
2737
  }
2752
2738
 
@@ -3496,10 +3482,9 @@ async function callLoaderOrAction(type, request, match, matches, basename, isSta
3496
3482
 
3497
3483
  if (redirectStatusCodes.has(status)) {
3498
3484
  let location = result.headers.get("Location");
3499
- invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
3500
- 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
3501
3486
 
3502
- if (!isAbsolute) {
3487
+ if (!ABSOLUTE_URL_REGEX.test(location)) {
3503
3488
  let activeMatches = matches.slice(0, matches.indexOf(match) + 1);
3504
3489
  let routePathnames = getPathContributingMatches(activeMatches).map(match => match.pathnameBase);
3505
3490
  let resolvedLocation = resolveTo(location, routePathnames, new URL(request.url).pathname);