@@ -252,6 +236,7 @@ const CodePage = () => {
onConfirm={handleDeployConfirm}
isDeploying={isDeploying}
/>
+
)
}
diff --git a/apps/studio/pages/project/[ref]/functions/new.tsx b/apps/studio/pages/project/[ref]/functions/new.tsx
index b8bb08b7321..a6291c202db 100644
--- a/apps/studio/pages/project/[ref]/functions/new.tsx
+++ b/apps/studio/pages/project/[ref]/functions/new.tsx
@@ -45,6 +45,7 @@ import {
} from 'ui'
import * as z from 'zod'
+import { PreventNavigationOnUnsavedChanges } from '@/components/ui-patterns/Dialogs/PreventNavigationOnUnsavedChanges'
import { FileData } from '@/components/ui/FileExplorerAndEditor/FileExplorerAndEditor.types'
import { useLatest } from '@/hooks/misc/useLatest'
@@ -276,21 +277,7 @@ const NewFunctionPage = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [template])
- // [Joshen] Probably a candidate for useStaticEffectEvent
- const filesRef = useLatest(files)
- useEffect(() => {
- const handleBeforeUnload = (e: BeforeUnloadEvent) => {
- const hasUnsavedChanges = !isEqual(INITIAL_FILES, filesRef.current)
-
- if (hasUnsavedChanges) {
- e.preventDefault()
- e.returnValue = '' // deprecated, but older browsers still require this
- }
- }
- window.addEventListener('beforeunload', handleBeforeUnload)
- return () => window.removeEventListener('beforeunload', handleBeforeUnload)
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [])
+ const hasUnsavedChanges = useMemo(() => !isEqual(INITIAL_FILES, files), [files])
return (