From c054b18ad5d2ff31618257e20dc0ddfe478b3e22 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Fri, 17 May 2024 11:36:50 +0530 Subject: [PATCH] chore: prevent route change on canceling confirm dialog (#4493) --- web/hooks/use-reload-confirmation.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/hooks/use-reload-confirmation.tsx b/web/hooks/use-reload-confirmation.tsx index 6cf6d3e88..3489d600c 100644 --- a/web/hooks/use-reload-confirmation.tsx +++ b/web/hooks/use-reload-confirmation.tsx @@ -16,14 +16,15 @@ const useReloadConfirmations = (isActive = true) => { ); const handleRouteChangeStart = useCallback( - (url: string) => { + (url: string, { shallow }: { shallow: boolean }) => { if (!isActive || !showAlert) return; const leave = confirm("Are you sure you want to leave? Changes you made may not be saved."); if (!leave) { - router.events.emit("routeChangeError"); + router.events.emit("routeChangeError", new Error("Route change cancelled by user"), url, shallow); + throw "routeChange aborted."; } }, - [isActive, showAlert, router.events] + [isActive, router.events, showAlert] ); useEffect(() => {