Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Trigger native browser confirmation when exiting session if there's unsaved changes (#49465)

Joshen Lim63a6e27142ba
diff --git a/apps/studio/components/interfaces/Explorer/ExplorerNotebookTabCoordinator.tsx b/apps/studio/components/interfaces/Explorer/ExplorerNotebookTabCoordinator.tsx
index 63a15562aa8..ceccee89c71 100644
--- a/apps/studio/components/interfaces/Explorer/ExplorerNotebookTabCoordinator.tsx
+++ b/apps/studio/components/interfaces/Explorer/ExplorerNotebookTabCoordinator.tsx
@@ -35,6 +35,19 @@ export const ExplorerNotebookTabCoordinator = () => {
const queryClient = useQueryClient()
const tabs = useContext(TabsStateContext)
+ useEffect(() => {
+ const handleBeforeUnload = (event: BeforeUnloadEvent) => {
+ const hasUnsaved = Object.values(notebooksState.notebooks).some(hasDiscardableChanges)
+ if (hasUnsaved) {
+ event.preventDefault()
+ event.returnValue = true
+ }
+ }
+
+ window.addEventListener('beforeunload', handleBeforeUnload)
+ return () => window.removeEventListener('beforeunload', handleBeforeUnload)
+ }, [])
+
useEffect(() => {
return tabs.registerTabTypeHandler('notebook', {
onClose: (tab) => {