Skip to content

Commit 6e8252e

Browse files
fix: prevent false Save Changes prompt
1 parent dc67877 commit 6e8252e

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/modules/Builder/features/SaveAndPublish/SaveAndPublish.hooks.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,20 @@ export const useSaveAndPublishSetup = (): SaveAndPublishSetup => {
315315
const hasAccessDeniedError =
316316
Array.isArray(responseError) &&
317317
responseError.some((error) => error.type === ErrorResponseType.AccessDenied);
318+
// Use `dirtyFields` (fields the user actually edited) rather than RHF's `isDirty`.
319+
// `isDirty` is a structural deep-compare of the form values against the form defaults,
320+
// so empty arrays that field arrays (e.g. `responseValues.rows`) inject into the form
321+
// values on mount — but never into the defaults — make `isDirty` permanently `true`
322+
// even with no real changes. `dirtyFields` stays empty in that case, so it accurately
323+
// reflects whether there are unsaved user changes worth prompting about.
324+
const hasFormChanges = !!Object.keys(dirtyFields ?? {}).length;
318325
const {
319326
cancelNavigation: onCancelNavigation,
320327
confirmNavigation,
321328
promptVisible,
322329
setPromptVisible,
323330
isLogoutInProgress,
324-
} = usePrompt(isDirty && !hasAccessDeniedError);
331+
} = usePrompt(hasFormChanges && !hasAccessDeniedError);
325332
const shouldNavigateRef = useRef(false);
326333
const appletUniqueNameRef = useRef<string | null>(null);
327334
const { ownerId } = workspaces.useData() || {};

0 commit comments

Comments
 (0)