mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-23 06:45:27 +02:00
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user