Skip to content

Instantly share code, notes, and snippets.

@depoulo
Last active April 10, 2025 07:37
Show Gist options
  • Save depoulo/f2c6ce4c4317051ecfd1c71152c01e8a to your computer and use it in GitHub Desktop.
Save depoulo/f2c6ce4c4317051ecfd1c71152c01e8a to your computer and use it in GitHub Desktop.
diff --git a/dist/router.js b/dist/router.js
index 23eae779e3ec2ea51933436ed18c9dbe43444797..013fb497f01728cdd3e3eb9b851ef4745bcfdad8 100644
--- a/dist/router.js
+++ b/dist/router.js
@@ -2981,28 +2981,30 @@ function createRouter(init) {
if (blockerFunctions.size === 0) {
return;
}
- // We ony support a single active blocker at the moment since we don't have
- // any compelling use cases for multi-blocker yet
- if (blockerFunctions.size > 1) {
- warning(false, "A router only supports one blocker at a time");
- }
+
let entries = Array.from(blockerFunctions.entries());
- let [blockerKey, blockerFunction] = entries[entries.length - 1];
- let blocker = state.blockers.get(blockerKey);
- if (blocker && blocker.state === "proceeding") {
- // If the blocker is currently proceeding, we don't need to re-check
- // it and can let this navigation continue
- return;
- }
- // At this point, we know we're unblocked/blocked so we need to check the
- // user-provided blocker function
- if (blockerFunction({
- currentLocation,
- nextLocation,
- historyAction
- })) {
- return blockerKey;
- }
+
+ let blockingKey = undefined;
+
+ entries.some(entry => {
+ let [blockerKey, blockerFunction] = entry;
+ let blocker = state.blockers.get(blockerKey);
+
+ if (blocker && blocker.state === "proceeding") {
+ // If the blocker is currently proceeding, we don't need to re-check
+ // it and can let this navigation continue
+ return;
+ }
+
+ // At this point, we know we're unblocked/blocked so we need to check the
+ // user-provided blocker function
+ if (blockerFunction({ currentLocation, nextLocation, historyAction })) {
+ blockingKey = blockerKey;
+ return blockerKey;
+ }
+ })
+
+ return blockingKey;
}
function handleNavigational404(pathname) {
let error = getInternalRouterError(404, {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment