wordpress-playground icon indicating copy to clipboard operation
wordpress-playground copied to clipboard

Give user alert to confirm browser refresh

Open hlashbrooke opened this issue 4 years ago • 6 comments

To prevent accidental page refreshes that will lose the user's data and progress, it would be great to have a basic browser alert that confirms if the user does want to refresh before it actually happens.

hlashbrooke avatar Nov 27 '22 22:11 hlashbrooke

Hey @hlashbrooke , Please assign this issue to me.

akansjain avatar Jun 02 '23 21:06 akansjain

@akansjain there you go!

adamziel avatar Jun 02 '23 22:06 adamziel

Thanks for sending us a PR @jnealey88, I will review it.

fellyph avatar Aug 27 '25 08:08 fellyph

Hi @hlashbrooke @fellyph ,

Please use below code to Prevents accidental data loss that works for local WordPress Playground (website)

What this does

  • Shows a browser confirmation dialog when the user:
  1. Refreshes the page
  2. Closes the tab
  3. Navigates away

file path (WordPress Playground – local)

  • packages/playground/website/src/main.tsx

Add this near the top, before React renders:

  • window.addEventListener('beforeunload', (event) => { event.preventDefault(); event.returnValue = ''; });

iamsohilvahora avatar Jan 06 '26 06:01 iamsohilvahora

Hi, I’d like to work on this issue. Can you assign it to me?

amannex avatar Apr 02 '26 16:04 amannex

Closing this issue now that the Playground autosave feature has landed.

mho22 avatar Jul 08 '26 09:07 mho22