From 4f03d7af3c442a446844f696b1ea18b4c4474b9d Mon Sep 17 00:00:00 2001 From: Gauvain Date: Fri, 17 Jul 2026 17:42:34 +0200 Subject: [PATCH] fix(nav): release rapid-push guard when the push throws --- hooks/useAppRouter.ts | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/hooks/useAppRouter.ts b/hooks/useAppRouter.ts index a9368b6bd..d9c04827a 100644 --- a/hooks/useAppRouter.ts +++ b/hooks/useAppRouter.ts @@ -55,19 +55,26 @@ export function useAppRouter() { return; pushInFlightRef.current = true; } - if (typeof href === "string") { - router.push(href as any); - } else { - const callerParams = (href.params ?? {}) as Record; - const hasExplicitOffline = "offline" in callerParams; - router.push({ - ...href, - params: { - // Only add offline if caller hasn't explicitly set it - ...(isOffline && !hasExplicitOffline && { offline: "true" }), - ...callerParams, - }, - } as any); + try { + if (typeof href === "string") { + router.push(href as any); + } else { + const callerParams = (href.params ?? {}) as Record; + const hasExplicitOffline = "offline" in callerParams; + router.push({ + ...href, + params: { + // Only add offline if caller hasn't explicitly set it + ...(isOffline && !hasExplicitOffline && { offline: "true" }), + ...callerParams, + }, + } as any); + } + } catch (e) { + // A push that throws never blurs the screen, so the focus listener + // would never reset the guard — release it here to avoid a stuck lock. + pushInFlightRef.current = false; + throw e; } }, [router, isOffline, navigation],