Skip to content

Give user alert to confirm browser refresh #2196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/playground/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,12 @@ function setQueryParams(url: string, params: Record<string, unknown>) {
urlObject.search = qs.toString();
return urlObject.toString();
}

// Add beforeunload event listener to warn about unsaved changes
window.addEventListener('beforeunload', (event) => {
// You might want to add conditions here to only show when there are actual changes
// For now, we'll show it for all page exits
event.preventDefault();
event.returnValue = ''; // Required for Chrome
return ''; // Required for some other browsers
});