Compare commits

...
Author SHA1 Message Date
Sonarly Claude Code ec8ffa0313 fix: reset form with saved values after object rename to fix consecutive edits
https://sonarly.com/issue/17321?type=bug

After renaming an object in Settings, the form's dirty tracking state is cleared without updating default values, causing subsequent rename attempts to be silently skipped due to a race condition between the async save and user input.

Fix: Replaced `formConfig.reset(undefined, { keepValues: true })` with a proper `formConfig.reset()` call that passes the saved values from the mutation response.

**Before:** The `else` branch (when `isLabelSyncedWithName` didn't change) called `formConfig.reset(undefined, { keepValues: true })`, which cleared `dirtyFields` without updating `defaultValues` to the saved state. This caused React Hook Form to lose track of which fields were dirty, making subsequent edits appear "clean" and silently skipping the save.

**After:** The form is always reset with explicit values from the mutation response (falling back to the current prop values). This synchronizes both `defaultValues` and form values to the saved state, so subsequent edits are correctly detected as dirty. This is consistent with how the `if` branch already handled the `isLabelSyncedWithName` toggle case.

Also extracted `updatedObjectData` to avoid repeated `updatedObject?.data?.updateOneObject` access, and simplified the `updatedObjectNamePlural` reference below.
2026-03-22 16:49:01 +00:00
@@ -85,26 +85,24 @@ export const SettingsUpdateDataModelObjectAboutForm = ({
const updatedObject = updateResult.response;
if (formValues.isLabelSyncedWithName !== isLabelSyncedWithName) {
formConfig.reset({
description,
icon: icon ?? undefined,
isLabelSyncedWithName: formValues.isLabelSyncedWithName,
labelPlural: updatedObject?.data?.updateOneObject.labelPlural,
labelSingular: updatedObject?.data?.updateOneObject.labelSingular,
namePlural: updatedObject?.data?.updateOneObject.namePlural,
nameSingular: updatedObject?.data?.updateOneObject.nameSingular,
});
} else {
formConfig.reset(undefined, { keepValues: true });
}
const updatedObjectData = updatedObject?.data?.updateOneObject;
formConfig.reset({
description: updatedObjectData?.description ?? description,
icon: updatedObjectData?.icon ?? icon ?? undefined,
isLabelSyncedWithName:
formValues.isLabelSyncedWithName ?? isLabelSyncedWithName,
labelPlural: updatedObjectData?.labelPlural ?? labelPlural,
labelSingular: updatedObjectData?.labelSingular ?? labelSingular,
namePlural: updatedObjectData?.namePlural ?? namePlural,
nameSingular: updatedObjectData?.nameSingular ?? nameSingular,
});
navigate(SettingsPath.ObjectDetail, {
objectNamePlural: objectNamePluralForRedirection,
});
const updatedObjectNamePlural =
updatedObject?.data?.updateOneObject.namePlural;
const updatedObjectNamePlural = updatedObjectData?.namePlural;
if (!isDefined(updatedObjectNamePlural)) {
return;