Skip to content

Commit

Permalink
fix: Refreshing wizard causes loss of progress (typehero#791)
Browse files Browse the repository at this point in the history
Added an eventListener to listen for beforeunload event. Pops up a
confirmation dialog box

Co-authored-by: bautistaaa <chrisbautistaaa@gmail.com>
  • Loading branch information
MrVSiK and bautistaaa authored Oct 7, 2023
1 parent cdf7884 commit 4185dc5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/web/src/app/[locale]/wizard/_components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ export function Wizard() {

useEffect(() => {
setRendered(true);

const handleBeforeUnload: EventListenerOrEventListenerObject = (event) => {
event.preventDefault();
event.returnValue = false;
};

window.addEventListener('beforeunload', handleBeforeUnload, { capture: true });

return () => {
// Clean up the event listener when the component unmounts
window.removeEventListener('beforeunload', handleBeforeUnload);
};
}, []);

const handleNextClick = async () => {
Expand Down

0 comments on commit 4185dc5

Please sign in to comment.