[PR #5640] [MERGED] fix(client): stop DraftNumberInput dropping an edit made during a commit round trip #6861

Closed
opened 2026-10-23 04:14:23 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5640
Author: @kolacheee
Created: 8/29/2026
Status: ✅ Merged
Merged: 8/29/2026
Merged by: @kolacheee

Base: staging ← Head: fix/5636-run-interval-dropped-commit


📝 Commits (3)

  • 283904d fix(client): stop DraftNumberInput dropping an edit made during a commit round trip
  • 5491f52 fix(client): harden the DraftNumberInput fix per adversarial verification
  • b6e6f01 fix(client): resync an abandoned draft when the input is disabled mid-edit

📊 Changes

4 files changed (+106 additions, -5 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 e2e/core-flows.e2e.ts (+46 -2)
📝 packages/client/src/components/game/GameCharacterSheet.tsx (+9 -1)
📝 packages/client/src/components/ui/DraftNumberInput.tsx (+50 -2)

📄 Description

Closes #5636

Why

#5636: the Secret Plot "Run Interval" field silently dropped an edit — CI caught a run where a value typed right after a previous Enter-commit never reached the server (fill 0, blur, server stayed at the previous 11 for a full 10-second poll, and no third PATCH request appeared in the trace at all). A real user hits the same window by typing a value, pressing Enter, then immediately correcting it and clicking away: the correction vanishes with no error.

The defect is not specific to that field — it lives in the shared DraftNumberInput component, which backs ~35 numeric settings fields across the connection editor, preset editor, settings panel, drawer, wizards, and game sheets.

What was wrong

Two independent mechanisms could discard a typed-but-not-yet-blurred draft:

  1. Prop echo wipes the draft. The useEffect([value]) sync re-seeded the draft unconditionally. The async echo of a previous commit (mutate → invalidate → refetch) landing mid-edit replaced the in-progress draft with the old value, so blur re-committed the old value.
  2. Unmount drops the edit. React fires no blur for a node that unmounts. If the surrounding tree is torn down mid-edit (a parent re-keys, a gate condition flips, the drawer closes), the pending draft died with the node — no commit at all. This is the only mechanism consistent with the CI trace showing no third PATCH (a draft wipe would still have PATCHed something on blur; a focus steal would have fired blur and committed the typed value).

The fix (both in DraftNumberInput)

  1. The prop→draft sync now yields while the input is focused (focusedRef). External updates still sync any time the field is not focused, and blur still reconciles through commit().
  2. A cleanup effect flushes the pending draft on unmount if the input was still focused — the same commit blur would have performed. This also fixes the adjacent case where closing the drawer mid-edit silently dropped the edit.

Test hardening

The Secret Plot e2e step now forwards the previous commit's PATCH to the server immediately but holds its response until the next edit has begun, and forges the echoed interval to a value the client never displayed (12) — the metadata version guard accepts it, so the unfixed component resyncs the draft to "12" mid-edit and blur commits 12 instead of the typed 0. (Merely delaying the echo cannot pin the bug: the optimistic cache update means the echo carries the number the input already shows, so the resync is invisible.) A/B verified: red on the pre-fix component (Expected: "0", Received: "12" at the mid-edit assertion) and green 3/3 with the fix.

Verification round (second commit): an adversarial review pass over the first commit found and fixed three things — (1) the original held-PATCH test choreography was vacuous and could have flaked against the fixed component, hence the forged-echo redesign above; (2) the unmount flush turned GameCharacterSheet's torn-down mid-edit case from a silent drop into a latent misdirected write (index-captured commits landing in a reseeded draft), so the Edit button now reseeds the draft from the live card on entry; (3) two robustness gaps in the new component code (commitRef now assigned in a layout effect; the editing latch drops when the input is disabled mid-edit, since the browser fires no blur for that). The same pass exonerated the drawer-internal tree as a remount source, refuted the whole-drawer-remount theory, and confirmed a real field remount vector in unguarded chat-cache writers — filed separately as #5641 (this PR's unmount flush absorbs its symptom).

Validation

  • pnpm check — passing (full build).
  • desktop-chromium -g "Secret Plot" — deterministic A/B: red pre-fix, green 3/3 post-fix (--retries=0).
  • StrictMode double-mount, all three commitOnValidChange sites, popover/drawer dismiss paths, and slider-pair concerns were checked against consumer code and verified safe (no spurious or double commits).
  • Manually verify in browser: Roleplay chat → Chat Settings → Agents → Narrative Director → type an interval, press Enter, immediately type another value and click away; reopen and confirm the second value survived.
  • Manually verify a commitOnValidChange field (Settings → the auto-commit numeric fields) still commits while typing and clamps on blur.
  • Manually verify a game character sheet: edit a pool value, save, re-enter Edit — values start from the live card.

Summary by CodeRabbit

  • Bug Fixes

    • Preserved in-progress number edits when asynchronous updates arrive during editing.
    • Ensured focused edits are committed when leaving a field or navigating away.
    • Refreshed values when reopening edit mode to prevent stale drafts.
    • Improved reliability when making consecutive edits during delayed saves.
  • Tests

    • Added end-to-end coverage for editing while an earlier save is still processing.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5640 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 8/29/2026 **Status:** ✅ Merged **Merged:** 8/29/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/5636-run-interval-dropped-commit` --- ### 📝 Commits (3) - [`283904d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/283904dc736d866966a396cf4396189c28a14ef1) fix(client): stop DraftNumberInput dropping an edit made during a commit round trip - [`5491f52`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5491f529a506e9190c4e236cf945ab197ebf7f0c) fix(client): harden the DraftNumberInput fix per adversarial verification - [`b6e6f01`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b6e6f016ed3302109d0eb08223cb38acd4b1e5d4) fix(client): resync an abandoned draft when the input is disabled mid-edit ### 📊 Changes **4 files changed** (+106 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `e2e/core-flows.e2e.ts` (+46 -2) 📝 `packages/client/src/components/game/GameCharacterSheet.tsx` (+9 -1) 📝 `packages/client/src/components/ui/DraftNumberInput.tsx` (+50 -2) </details> ### 📄 Description Closes #5636 ## Why #5636: the Secret Plot "Run Interval" field silently dropped an edit — CI caught a run where a value typed right after a previous Enter-commit never reached the server (fill `0`, blur, server stayed at the previous `11` for a full 10-second poll, and **no third PATCH request appeared in the trace at all**). A real user hits the same window by typing a value, pressing Enter, then immediately correcting it and clicking away: the correction vanishes with no error. The defect is not specific to that field — it lives in the shared `DraftNumberInput` component, which backs ~35 numeric settings fields across the connection editor, preset editor, settings panel, drawer, wizards, and game sheets. ## What was wrong Two independent mechanisms could discard a typed-but-not-yet-blurred draft: 1. **Prop echo wipes the draft.** The `useEffect([value])` sync re-seeded the draft unconditionally. The async echo of a *previous* commit (mutate → invalidate → refetch) landing mid-edit replaced the in-progress draft with the old value, so blur re-committed the old value. 2. **Unmount drops the edit.** React fires no blur for a node that unmounts. If the surrounding tree is torn down mid-edit (a parent re-keys, a gate condition flips, the drawer closes), the pending draft died with the node — no commit at all. This is the only mechanism consistent with the CI trace showing **no** third PATCH (a draft wipe would still have PATCHed *something* on blur; a focus steal would have fired blur and committed the typed value). ## The fix (both in `DraftNumberInput`) 1. The prop→draft sync now yields while the input is focused (`focusedRef`). External updates still sync any time the field is not focused, and blur still reconciles through `commit()`. 2. A cleanup effect flushes the pending draft on unmount if the input was still focused — the same commit blur would have performed. This also fixes the adjacent case where closing the drawer mid-edit silently dropped the edit. ## Test hardening The Secret Plot e2e step now forwards the previous commit's PATCH to the server immediately but holds its **response** until the next edit has begun, and forges the echoed interval to a value the client never displayed (`12`) — the metadata version guard accepts it, so the unfixed component resyncs the draft to "12" mid-edit and blur commits 12 instead of the typed 0. (Merely *delaying* the echo cannot pin the bug: the optimistic cache update means the echo carries the number the input already shows, so the resync is invisible.) A/B verified: **red on the pre-fix component** (`Expected: "0", Received: "12"` at the mid-edit assertion) and **green 3/3 with the fix**. Verification round (second commit): an adversarial review pass over the first commit found and fixed three things — (1) the original held-PATCH test choreography was vacuous *and* could have flaked against the fixed component, hence the forged-echo redesign above; (2) the unmount flush turned `GameCharacterSheet`'s torn-down mid-edit case from a silent drop into a latent misdirected write (index-captured commits landing in a reseeded draft), so the Edit button now reseeds the draft from the live card on entry; (3) two robustness gaps in the new component code (`commitRef` now assigned in a layout effect; the editing latch drops when the input is disabled mid-edit, since the browser fires no blur for that). The same pass exonerated the drawer-internal tree as a remount source, refuted the whole-drawer-remount theory, and confirmed a real *field* remount vector in unguarded chat-cache writers — filed separately as #5641 (this PR's unmount flush absorbs its symptom). ## Validation - `pnpm check` — passing (full build). - `desktop-chromium -g "Secret Plot"` — deterministic A/B: red pre-fix, green 3/3 post-fix (`--retries=0`). - StrictMode double-mount, all three `commitOnValidChange` sites, popover/drawer dismiss paths, and slider-pair concerns were checked against consumer code and verified safe (no spurious or double commits). - Manually verify in browser: Roleplay chat → Chat Settings → Agents → Narrative Director → type an interval, press Enter, immediately type another value and click away; reopen and confirm the second value survived. - Manually verify a `commitOnValidChange` field (Settings → the auto-commit numeric fields) still commits while typing and clamps on blur. - Manually verify a game character sheet: edit a pool value, save, re-enter Edit — values start from the live card. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Preserved in-progress number edits when asynchronous updates arrive during editing. * Ensured focused edits are committed when leaving a field or navigating away. * Refreshed values when reopening edit mode to prevent stale drafts. * Improved reliability when making consecutive edits during delayed saves. * **Tests** * Added end-to-end coverage for editing while an earlier save is still processing. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:14:23 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6861
No description provided.