-
Notifications
You must be signed in to change notification settings - Fork 327
Add browser refresh confirmation for temporary sites #2561
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
base: trunk
Are you sure you want to change the base?
Add browser refresh confirmation for temporary sites #2561
Conversation
) Implements a beforeunload event handler that warns users when they attempt to leave or refresh the page while using a temporary Playground site. This prevents accidental data loss by showing a browser confirmation dialog. Changes: - Add browserConfirmationMiddleware to handle beforeunload events - Check if the active site is temporary (storage === 'none') - Show confirmation only for temporary sites, not saved ones - Register middleware in the Redux store
Remove unnecessary comments and custom message strings. The handler now simply triggers the browser's confirmation dialog for temporary sites.
const state = store.getState() as any; | ||
// Access the active site directly from state structure | ||
const activeSiteSlug = state.ui?.activeSite?.slug; | ||
const activeSite = activeSiteSlug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the temporary site might still be opened in the background while a persisted site is also open and active. I'm not sure if that's something we need to worry about here but I just wanted to highlight it.
I wonder what happens when we have unsaved changes in the editor and then attempt to close the tab. Normally, the editor would try to display a confirmation dialog. What would the user see? One dialog? Or two dialogs? |
Also, I wanted to surface this comment from @dmsnell:
|
- Check ALL temporary sites, not just the active one - Track user interactions to avoid warning on quick open/close - Skip our confirmation if WordPress editor already has unsaved changes - Only warn users who have actually interacted with the site This addresses concerns about: - Multiple sites being open (temporary in background) - Double dialogs with WordPress editor - Harassing users who quickly open/close without editing
Perfect! I've updated PR #2561 with these improvements based on the feedback:
This addresses all main concerns and makes the warning logic much smarter. Thanks for the thoughtful review! 🚀 |
Summary
Fixes #81
This PR implements a browser confirmation dialog that warns users before they refresh or leave the page when using a temporary Playground site, preventing accidental data loss.
Changes
browserConfirmationMiddleware
inslice-ui.ts
that listens for thebeforeunload
event'none'
)Test Plan
Screenshots