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 = (
+
@@ -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 () => {