From fbaaaee43d883bf1194ab3e71338878acae3eb1b Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 6 Nov 2026 05:33:23 +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=B4=20=EC=9E=90?= =?UTF-8?q?=EA=B8=B0=EA=B0=80=20=EC=8B=9C=EC=9E=91=ED=95=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EC=9D=80=20=EC=A0=80=EC=9E=A5=EC=9D=98=20=EB=81=9D?= =?UTF-8?q?=EC=9D=84=20=EB=B3=B4=EC=9D=B8=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: 저장 중에 참조 작성 폼을 떠났다가 돌아오면(1105/08-04가 지원 경로로 다루는 길) 새 폼 인스턴스에는 제출한 값도 결과도 없다. (A) 그 저장이 결과 불명으로 끝나 "변경됨으로 확인"을 누르면 settleApplied가 제출한 값이 없어 아무것도 하지 않는다. 결과 문구가 없고 눌렀던 버튼이 빠져 포커스가 body로 간다. 같은 훅의 재전송(resendUnknown)은 다시 마운트를 이미 처리한다. (B) 그 저장이 성공하거나 적용 안 됨으로 끝나면 진행 문구만 사라지고 아무것도 보이지 않는다. 사용자가 같은 항목을 다시 입력하면 새 생성이 나간다(리뷰 probe 08-R1). 고른 방법: - (A) 리뷰의 최소 개선 (1): settleApplied가 제출한 값이 없으면 지금 값으로 성공을 정한다. 재전송과 같다. 포커스를 잃었으면 feedback 자리로 옮긴다. 1105/08-01의 포커스 복구는 직전 결과가 effect-unknown일 때만 걸려서 다시 마운트한 폼(직전 idle)에는 닿지 않는다. - (B) 리뷰 (2)의 작은 쪽: 참조 폼이 "자기가 시작하지 않은 저장이 돌던 것"을 기억하고, 그 저장이 끝나면 feedback에 기존 링크 "목록을 새로 불러와 확인"을 둔다. 이 폼이 직접 저장하면 지운다. 새 문구는 없다. 버린 대안: 코디네이터가 마지막 시도의 결과를 채널에 남기고 폼이 그것을 보이기(정확하지만 코디네이터 계약이 넓어진다), useAppForm이 코디네이터 상태를 받아 결과를 하나로 내기(지난 라운드 3.5 (B), 설계 변경이다). 위험·한계: (B)는 결과를 말하지 않고 목록으로 안내만 한다. 생성기 템플릿의 작성 폼은 (A)에서 목록으로 옮기므로 해당 없고, (B) 안내는 넣지 않았다 (1106/08-02는 이동만 고친다). (A)는 resetOnSuccess면 다시 마운트한 뒤 입력한 값을 비운다. 재전송과 같은 동작이다. 브라우저 3엔진 e2e는 더하지 않았다. 검증: 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 --- .../reference-resource-form-page.tsx | 40 +++++++--- src/presentation/forms/use-app-form.ts | 12 ++- .../reference-feature/reference-page.test.tsx | 80 +++++++++++++++++++ 3 files changed, 117 insertions(+), 15 deletions(-) diff --git a/src/features/reference-feature/presentation/reference-resource-form-page.tsx b/src/features/reference-feature/presentation/reference-resource-form-page.tsx index f6047e45..bbdab87f 100644 --- a/src/features/reference-feature/presentation/reference-resource-form-page.tsx +++ b/src/features/reference-feature/presentation/reference-resource-form-page.tsx @@ -1,4 +1,4 @@ -import { useCallback } from "react"; +import { useCallback, useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import { @@ -59,7 +59,30 @@ export default function ReferenceResourceFormPage() { // feedback says a save is running, instead of a click that does nothing. const otherSaveRunning = mutation.state.indicator === "mutation-pending" && !form.pending; + // 1106/08-01. The result of that save belongs to the form that started + // it, not to this one. Once it ends, the feedback points to the list, + // which shows whether the item is there, until this form saves itself. + const [otherSaveSeen, setOtherSaveSeen] = useState(false); + if (!otherSaveSeen && otherSaveRunning && form.result === "idle") { + setOtherSaveSeen(true); + } else if (otherSaveSeen && (form.pending || form.result !== "idle")) { + setOtherSaveSeen(false); + } const guard = useDirtyNavigationGuard(form.dirty && !form.pending); + const reloadList = ( +

+ { + void invalidation + ?.invalidate([REFERENCE_RESOURCE_INVALIDATION_TOPIC]) + .catch(() => {}); + }} + > + {message("reference.form.reloadList")} + +

+ ); return (
-

- { - void invalidation - ?.invalidate([REFERENCE_RESOURCE_INVALIDATION_TOPIC]) - .catch(() => {}); - }} - > - {message("reference.form.reloadList")} - -

+ {reloadList} ) : form.result === "success" ? (

{message("reference.form.saved")}

@@ -189,6 +201,8 @@ export default function ReferenceResourceFormPage() { // 1105/08-04. While this form's own unknown result is being // checked, the result that follows is shown instead. + ) : otherSaveSeen ? ( + reloadList ) : null } aside={ diff --git a/src/presentation/forms/use-app-form.ts b/src/presentation/forms/use-app-form.ts index 6b3b74b9..c0351fd5 100644 --- a/src/presentation/forms/use-app-form.ts +++ b/src/presentation/forms/use-app-form.ts @@ -230,9 +230,17 @@ export function useAppForm< const settleApplied = useCallback(() => { const submittedValues = unknownSubmissionRef.current; - if (!submittedValues) return; + 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. + focusFeedbackRef.current = focusIsLost(); + settleSuccessfulValues(values); + return; + } settleSuccessfulValues(submittedValues); - }, [settleSuccessfulValues]); + }, [settleSuccessfulValues, values]); 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 744e5ce6..37e51dd2 100644 --- a/tests/features/reference-feature/reference-page.test.tsx +++ b/tests/features/reference-feature/reference-page.test.tsx @@ -644,6 +644,86 @@ describe("reference feature page states", () => { expect(createResource).toHaveBeenCalledTimes(2); }); + /** + * 1106/08-01. The form the user came back to did not start the save + * still running, and holds none of its result (review probe 08-R1). + */ + async function leaveDuringSaveAndComeBack() { + const user = userEvent.setup(); + let release: + | ((result: ReferenceResult) => void) + | undefined; + const createResource = vi + .fn() + .mockImplementationOnce( + () => + new Promise>((resolve) => { + release = resolve; + }), + ); + renderReference( + inputWith({ createResource }), + "/examples/reference-resources/new", + ); + await user.type( + await screen.findByRole("textbox", { name: /새 항목 이름/ }), + "First item", + ); + await user.click(screen.getByRole("button", { name: "저장" })); + await waitFor(() => expect(createResource).toHaveBeenCalledOnce()); + await user.click(screen.getByRole("button", { name: "목록으로 돌아가기" })); + await waitFor(() => + expect(window.location.pathname).toBe("/examples/reference-resources"), + ); + window.history.pushState({}, "", "/examples/reference-resources/new"); + window.dispatchEvent(new PopStateEvent("popstate")); + expect(await screen.findByText("변경 사항을 저장하고 있습니다.")).toBeVisible(); + return { + user, + release(result: ReferenceResult) { + release?.(result); + }, + }; + } + + // 1106/08-01 (A). Confirming that save from the remounted form used to + // show nothing and drop focus to the body: the form had no submitted + // values to settle. + it("shows the save confirmed on a remounted form and keeps focus in its feedback", async () => { + const { user, release } = await leaveDuringSaveAndComeBack(); + release({ + ok: false, + error: createFailure("SERVER_FAILURE", "CREATE_REFERENCE_RESOURCE", 0, { + effect: "MAYBE_APPLIED", + }), + }); + const confirm = await screen.findByRole("button", { name: "변경됨으로 확인" }); + confirm.focus(); + + await user.keyboard("{Enter}"); + + const saved = await screen.findByText("저장했습니다."); + await waitFor(() => + expect(saved.closest(".page-template__feedback")).toHaveFocus(), + ); + }); + + // 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 () => { + const { release } = await leaveDuringSaveAndComeBack(); + release({ + ok: true, + value: { resourceId: "created-1", title: "First item", createdAt: null }, + }); + + expect( + await screen.findByRole("link", { name: "목록을 새로 불러와 확인" }), + ).toBeVisible(); + expect(screen.queryByText("변경 사항을 저장하고 있습니다.")).not.toBeInTheDocument(); + expect(screen.getByRole("button", { name: "저장" })).toBeEnabled(); + }); + // 0929/08-04. The ids a user quotes to support reach the screens that // need them, and the sample status page shows no made-up reference. it("shows the request id of an unknown create next to its result", async () => {