From b9b4ea31eba36da99a12a2dde2905c064f6ba020 Mon Sep 17 00:00:00 2001 From: karthick-murugan Date: Tue, 22 Apr 2025 15:55:23 +0530 Subject: [PATCH] Alert to confirm browser refresh --- packages/playground/client/src/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/playground/client/src/index.ts b/packages/playground/client/src/index.ts index 8741bb7db9..43ff114e2e 100644 --- a/packages/playground/client/src/index.ts +++ b/packages/playground/client/src/index.ts @@ -222,3 +222,12 @@ function setQueryParams(url: string, params: Record) { 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 +});