fix(forms): 다시 마운트한 폼의 확인은 보내지 않은 입력을 저장됨으로 두지 않는다

문제: 1106/08-01(fbaaaee)은 제출한 값이 없는(저장 중에 떠났다 다시 마운트한)
폼에서 settleApplied가 화면의 지금 값으로 성공을 정한다. 그 값은 보낸 적이
없다. 사용자가 결과 불명 동안 새 항목을 입력하고 앞의 저장을 "변경됨으로
확인"하면 "저장했습니다"와 함께 입력이 지워진다(기본 resetOnSuccess).
resetOnSuccess: false인 폼은 그 값이 기준값이 되어 dirty와 이탈 확인이 꺼진다
(diff 리뷰 DR-03).

고른 방법: 리뷰의 최소 방향대로, 제출한 값이 없으면 결과(success)와 포커스
이동만 한다. 값·기준값·touched는 건드리지 않고, 오류 표시만 비운다. 08-01의
완료 기준(확인 뒤 "저장했습니다."가 보이고 포커스가 feedback 안)은 그대로다.
버린 대안: 지금 값이 기본값과 같을 때만 정리하기(같은 결과에 분기가 하나 더
는다).

위험·한계: 다시 마운트한 폼에서 확인한 뒤 입력이 남아 있으면 dirty가 남아,
생성 기능 작성 페이지의 확인 뒤 목록 이동이 이탈 확인 창을 띄운다. 보내지
않은 입력을 지키는 쪽이다. CHANGELOG는 다음 커밋이 적는다.

검증: desktop batch에서 확인. node scripts/run-vitest.ts run
tests/features/reference-feature/reference-page.test.tsx
tests/component/form-foundation.test.tsx

Refs: 1106/08-01 (diff review DR-03)
This commit is contained in:
DongHyeonka
2026-11-06 08:01:53 +09:00
parent 80e7f1d63a
commit 145be2df13
2 changed files with 37 additions and 5 deletions
+8 -5
View File
@@ -235,15 +235,18 @@ export function useAppForm<
const submittedValues = unknownSubmissionRef.current;
if (!submittedValues) {
// 1106/08-01. After a remount the form no longer holds the submitted
// values. As a resend does (resendUnknown), the confirmed save settles
// with the values on screen, and focus, lost with the confirm button,
// goes to the feedback area that shows it.
// values. The confirmed save is shown, and focus, lost with the
// confirm button, goes to the feedback area that shows it. The values
// on screen were never sent, so they and the dirty state stay as they
// are (diff review of 1106/08-01).
focusFeedbackRef.current = focusIsLost();
settleSuccessfulValues(values);
setFieldErrors({} as FieldErrors<Values>);
setFormErrors([]);
setResult("success");
return;
}
settleSuccessfulValues(submittedValues);
}, [settleSuccessfulValues, values]);
}, [settleSuccessfulValues]);
const settleNotApplied = useCallback(() => {
if (!unknownSubmissionRef.current) return;
@@ -789,6 +789,35 @@ describe("reference feature page states", () => {
);
});
// 1106/08-01, diff review. What the user typed on the remounted form was
// never sent. Confirming the earlier save shows that save and leaves the
// new input, and its leave guard, in place.
it("keeps what the user typed on a remounted form when confirming the earlier save", async () => {
const { user, release } = await leaveDuringSaveAndComeBack();
release({
ok: false,
error: createFailure("SERVER_FAILURE", "CREATE_REFERENCE_RESOURCE", 0, {
effect: "MAYBE_APPLIED",
}),
});
await screen.findByRole("button", { name: "변경됨으로 확인" });
const name = screen.getByRole("textbox", { name: /새 항목 이름/ });
await user.type(name, "Second item");
screen.getByRole("button", { name: "변경됨으로 확인" }).focus();
await user.keyboard("{Enter}");
const saved = await screen.findByText("저장했습니다.");
await waitFor(() =>
expect(saved.closest(".page-template__feedback")).toHaveFocus(),
);
expect(name).toHaveValue("Second item");
await user.click(screen.getByRole("button", { name: "목록으로 돌아가기" }));
expect(
await screen.findByRole("button", { name: "변경 버리고 이동" }),
).toBeVisible();
});
// 1106/08-01 (B). That save succeeding left the remounted form saying
// nothing. The form cannot know its result, so it points to the list.
it("points to the list once a save the remounted form did not start ends", async () => {