fix(scaffold): 생성 폼이 "변경됨으로 확인" 뒤 목록을 연다

문제
create:feature --with-create가 만드는 작성 폼의 feedback은 form.failure와 결과
불명 두 가지뿐이다. 저장 성공은 상세로 이동해서 알리는데, "변경됨으로 확인"은
reconcileUnknownEffect(...).then(form.settleApplied)이고 이동하지 않는다.
settleApplied가 결과를 success로 바꾸고 기본값 resetOnSuccess로 입력을 비우므로,
결과 불명 화면이 사라진 뒤 빈 폼만 남는다. 짝 백엔드 기본(NEVER)에서는 이것이
화면 안의 유일한 행동이다. 사용자는 확인이 받아들여졌는지 모르고, 다시 입력해
저장하면 키 없는 생성이 한 번 더 나간다(실제로 저장됐던 경우 중복). 참조 폼은
같은 경우 "저장했습니다."를 보인다.

고른 방법
확인 뒤 폼을 정리하고(settleApplied, flushSync라 이동 전에 dirty 가드가 풀린다)
목록으로 이동한다. 목록은 항목이 실제로 저장됐는지를 보여 주는 화면이고,
reconcileUnknownEffect가 이미 목록 topic을 무효화한다. 라우터가 목록 제목으로
포커스를 옮기므로 08-01의 포커스 문제도 이 폼에서는 생기지 않는다. 생성 기능
테스트에 "응답을 잃은 생성 → 변경됨으로 확인 → 목록 제목과 항목"을 한 행 더했다
(NEVER·KEYED 공통). 매뉴얼 02의 생성 테스트 행에 적었다.

버린 대안
참조 폼처럼 success 가지에 확인 문구를 둔다: 생성 catalog에 키가 하나 늘고,
항목이 실제로 있는지는 여전히 보이지 않는다.

위험·한계
- 짝 백엔드 생성기에는 목록 GET이 아직 없다(1103/03-07 결정 대기). 실제 짝
  백엔드에서는 이동한 목록이 405를 받는다(생성 목록 페이지가 지금 그렇다).
  생성 테스트는 MSW로 목록을 답한다.
- 생성 결과 파일은 단위 테스트가 문자열로만 보고, 동작은 test:feature-scaffold
  (KEYED, FE-GATE-020)와 test:sample-removal(NEVER)에서 생성한 테스트가 본다.

검증
desktop batch에서 확인:
node scripts/run-vitest.ts run tests/unit/create-feature.test.ts
corepack pnpm test:feature-scaffold
corepack pnpm test:sample-removal

Refs: 1105/08-02
This commit is contained in:
DongHyeonka
2026-11-06 02:33:16 +09:00
parent f2b8ba75d3
commit 90c489c31a
3 changed files with 55 additions and 3 deletions
+37 -2
View File
@@ -617,7 +617,8 @@ import { use${pascal}Create } from "./use-${base}-create.ts";
* of the name (400 ${write.invalidCode}, refused before the write) shows on
* the field and the form saves again. A save whose result is unknown (the
* response was lost) keeps the form: the user checks, or, for a KEYED
* command, resends the same request with the same key.
* command, resends the same request with the same key. Confirming it was
* applied opens the list, which shows whether the item is there.
*/
export default function ${pascal}CreatePage() {
const navigate = useNavigate();
@@ -714,8 +715,13 @@ export default function ${pascal}CreatePage() {
<AsyncSurface
state={mutation.state}
supportReference={form.supportReference}
// The list shows whether the item is there; the form alone
// would show nothing but an emptied input (1105/08-02).
onReconcileUnknownEffect={(resolution) => {
void mutation.reconcileUnknownEffect(resolution).then(form.settleApplied);
void mutation.reconcileUnknownEffect(resolution).then(() => {
form.settleApplied();
void navigate(${camel}RouteUrl("${routeId}"));
});
}}
// Drawn only for a request with a key (a KEYED command).
onResendUnknownEffect={() => {
@@ -842,6 +848,14 @@ function answerItem(body: JsonBodyType = { id: ITEM_ID, name: "First item" }) {
);
}
function answerList() {
api.use(
http.get(\`\${API}${apiPath}\`, () =>
HttpResponse.json({ success: true, data: [{ id: ITEM_ID, name: "First item" }], meta: META }),
),
);
}
async function openForm() {
const user = await openSignedIn(${camel}RouteUrl("${write.create.routeId}"));
expect(
@@ -890,6 +904,27 @@ describe("${names.id} create form on the paired backend", () => {
});
${unknownTest}
// 1105/08-02. Confirming an unknown create opens the list, which shows
// whether the item was saved; the form alone showed nothing.
it("opens the list after the user confirms a create whose response was lost", async () => {
const posts = answerCreate(() => HttpResponse.error());
answerList();
const user = await openForm();
await user.type(await nameField(), "First item");
await user.click(saveButton());
expect(await screen.findByText(KO_MESSAGES["async.mutationEffectUnknown"])).toBeVisible();
await user.click(
screen.getByRole("button", { name: KO_MESSAGES["action.confirmMutationApplied"] }),
);
expect(
await screen.findByRole("heading", { level: 1, name: MESSAGES["${camel}.list.title"] }),
).toBeVisible();
expect(await screen.findByText("First item")).toBeVisible();
expect(posts).toHaveLength(1);
});
});
`;
}