From 145be2df1371ec0e676f5a854bebb80ae437550d Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 6 Nov 2026 08:01:43 +0900 Subject: [PATCH] =?UTF-8?q?fix(forms):=20=EB=8B=A4=EC=8B=9C=20=EB=A7=88?= =?UTF-8?q?=EC=9A=B4=ED=8A=B8=ED=95=9C=20=ED=8F=BC=EC=9D=98=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=EC=9D=80=20=EB=B3=B4=EB=82=B4=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EC=9D=80=20=EC=9E=85=EB=A0=A5=EC=9D=84=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=EB=90=A8=EC=9C=BC=EB=A1=9C=20=EB=91=90=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 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) --- src/presentation/forms/use-app-form.ts | 13 +++++---- .../reference-feature/reference-page.test.tsx | 29 +++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/presentation/forms/use-app-form.ts b/src/presentation/forms/use-app-form.ts index 9f859164..47abaea5 100644 --- a/src/presentation/forms/use-app-form.ts +++ b/src/presentation/forms/use-app-form.ts @@ -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); + setFormErrors([]); + setResult("success"); return; } settleSuccessfulValues(submittedValues); - }, [settleSuccessfulValues, values]); + }, [settleSuccessfulValues]); const settleNotApplied = useCallback(() => { if (!unknownSubmissionRef.current) return; diff --git a/tests/features/reference-feature/reference-page.test.tsx b/tests/features/reference-feature/reference-page.test.tsx index be84b7e0..71052085 100644 --- a/tests/features/reference-feature/reference-page.test.tsx +++ b/tests/features/reference-feature/reference-page.test.tsx @@ -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 () => {