From 9dd19f1da578e4c9570d2289823671a4e555908a Mon Sep 17 00:00:00 2001 From: Gildas Garcia <1122076+djhi@users.noreply.github.com> Date: Tue, 17 Mar 2026 12:27:44 +0100 Subject: [PATCH] fix: prevent unnecessary dialog after saving a new edge function (#43854) ## Problem After deploying a new edge function where you actually modified the code from the initial template, a dialog appears about unsaved changes. ## Solution We must check that even though the files have changed from the initial ones, we actually saved them by deploying the function. However, because we trigger the navigation in the mutation `onSuccess` side effect, it happens before react can update the state that would prevent the dialog from appearing. --- .../pages/project/[ref]/functions/new.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/studio/pages/project/[ref]/functions/new.tsx b/apps/studio/pages/project/[ref]/functions/new.tsx index 42d0b7bd125..0897ffd42a0 100644 --- a/apps/studio/pages/project/[ref]/functions/new.tsx +++ b/apps/studio/pages/project/[ref]/functions/new.tsx @@ -143,14 +143,22 @@ const NewFunctionPage = () => { }, }) - const { mutate: deployFunction, isPending: isDeploying } = useEdgeFunctionDeployMutation({ + const { + mutate: deployFunction, + isPending: isDeploying, + isSuccess: hasDeployed, + } = useEdgeFunctionDeployMutation({ // [Joshen] To investigate: For some reason, the invalidation for list of edge functions isn't triggering onSuccess: () => { toast.success('Successfully deployed edge function') const functionName = form.getValues('functionName') - if (ref && functionName) { - router.push(`/project/${ref}/functions/${functionName}/details`) - } + // Allow the mutation state (isSuccess) to propagate before navigating + // to prevent unnecessary dialog about unsaved changes + setTimeout(() => { + if (ref && functionName) { + router.push(`/project/${ref}/functions/${functionName}/details`) + } + }, 150) }, }) @@ -415,7 +423,7 @@ const NewFunctionPage = () => { - + ) }