From 86ea311714e2ccb057f59b2bef7ac962306acdc0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Sirois Date: Fri, 12 Jun 2026 20:28:02 -0400 Subject: [PATCH] fix: prevent environment form from resetting while editing The application environment editor shares the application.one query with its parent page, which polls every 5s. Each refetch pushed fresh data into a useEffect that called form.reset(), wiping any in-progress edits (e.g. while scrolling down to the Save button). Gate the reset on the form not being dirty so background refetches no longer clobber unsaved edits, and reset the dirty baseline after a successful save so the form re-syncs with the server normally. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../components/dashboard/application/environment/show.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/dokploy/components/dashboard/application/environment/show.tsx b/apps/dokploy/components/dashboard/application/environment/show.tsx index fb5fc18a7..665da88a8 100644 --- a/apps/dokploy/components/dashboard/application/environment/show.tsx +++ b/apps/dokploy/components/dashboard/application/environment/show.tsx @@ -60,14 +60,16 @@ export const ShowEnvironment = ({ applicationId }: Props) => { const currentBuildArgs = form.watch("buildArgs"); const currentBuildSecrets = form.watch("buildSecrets"); const currentCreateEnvFile = form.watch("createEnvFile"); + const { isDirty } = form.formState; const hasChanges = currentEnv !== (data?.env || "") || currentBuildArgs !== (data?.buildArgs || "") || currentBuildSecrets !== (data?.buildSecrets || "") || currentCreateEnvFile !== (data?.createEnvFile ?? true); + // Skip reset while editing so background refetches don't wipe edits useEffect(() => { - if (data) { + if (data && !isDirty) { form.reset({ env: data.env || "", buildArgs: data.buildArgs || "", @@ -75,7 +77,7 @@ export const ShowEnvironment = ({ applicationId }: Props) => { createEnvFile: data.createEnvFile ?? true, }); } - }, [data, form]); + }, [data, isDirty, form]); const onSubmit = async (formData: EnvironmentSchema) => { mutateAsync({ @@ -87,6 +89,7 @@ export const ShowEnvironment = ({ applicationId }: Props) => { }) .then(async () => { toast.success("Environments Added"); + form.reset(formData); await refetch(); }) .catch(() => {