mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Add custom modal after browser refresh dialog
This commit is contained in:
parent
305216102e
commit
c31291e95a
3 changed files with 46 additions and 10 deletions
|
|
@ -32,14 +32,18 @@ export const useRefreshGuard = ({
|
|||
return;
|
||||
}
|
||||
|
||||
// DO NOT call onBeforeUnload here!
|
||||
// This fires before user chooses "Stay" or "Leave"
|
||||
// Calling disconnect here will log out the user even if they choose "Stay"
|
||||
|
||||
// DO NOT set React state during beforeunload - it causes state corruption
|
||||
// Only show browser's native dialog for page refresh/navigation
|
||||
// Show browser's native dialog first
|
||||
event.preventDefault();
|
||||
event.returnValue = ''; // Required for Chrome
|
||||
|
||||
// Schedule custom modal to show after browser dialog is dismissed
|
||||
// This only happens if user chooses "Stay" on the browser dialog
|
||||
setTimeout(() => {
|
||||
if (shouldGuard) {
|
||||
setShowModal(true);
|
||||
}
|
||||
}, 100);
|
||||
|
||||
return ''; // Required for other browsers
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue