[GH-ISSUE #2972] [Issue]: Drawer autosave silently reverts a row-header rename or regex toggle made while the drawer is dirty #1547

Closed
opened 2026-10-21 05:38:51 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2972

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

When an entry's expanded drawer has an unsaved edit (e.g. text typed into Description/Content/Keys), and the user then renames the entry or flips the regex toggle on the compact row header, the header change is saved immediately — but the drawer's debounced autosave (~850 ms later) POSTs its stale snapshot, which still carries the old name and old useRegex, overwriting the just-saved header change. The user's rename / regex toggle silently snaps back. This is real data loss, not cosmetic.

How to reproduce (try it yourself)

  1. Open a lorebook and expand an entry row (the drawer opens).
  2. Type into the drawer's Description field (do not click away — the drawer is now dirty, autosave pending).
  3. Within the autosave window, flip the regex toggle in the compact row header (or edit + blur the row's name input). That header patch saves useRegex=true (or the new name).
  4. Wait for the drawer's autosave to flush.

You'll see: the entry's useRegex flips back to false (or the name reverts to the old value).
Expected: both the header change and the drawer edit persist.

Where it is

  • packages/client/src/components/lorebooks/LorebookEntryRow.tsx:1107-1138 (buildEntrySavePayload) — the drawer payload re-sends name (1109) and useRegex (1117) from its snapshot.
  • :356-364 (handleUseRegexToggle) and :366-373 (handleNameCommit) — the compact row header is the real owner of useRegex / name.
  • :1308-1328 — the drawer's sync effect only refreshes formRef.current from the upstream entry when switched || (!dirtyRef.current && !savingRef.current), so it refuses to refresh while the drawer is dirty.
  • :1249-1267 (saveNow) — posts the stale formRef.current snapshot.
  • packages/client/src/hooks/use-lorebooks.ts:179-190 (useUpdateLorebookEntry) — no optimistic update; only invalidates onSuccess.

What's happening

buildEntrySavePayload sends name and useRegex, both of which are only editable on the row header (the drawer has no input for either). The drawer's sync effect won't refresh its snapshot from a freshly refetched entry while the drawer is dirty, so a concurrent header patch to name/useRegex is held stale in formRef.current and re-sent on the next autosave, clobbering the newer server value.

Suggested fix

Drop name and useRegex from buildEntrySavePayload so the drawer never persists fields the row header also writes (the cleanest fix — neither field has an input inside the drawer, so the drawer has no business sending them). Alternatively, when the refetched entry differs on a field the drawer is not actively editing, merge that field into formRef.current even while dirty rather than discarding the whole refresh.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2972 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** When an entry's expanded drawer has an unsaved edit (e.g. text typed into Description/Content/Keys), and the user then renames the entry or flips the regex toggle on the **compact row header**, the header change is saved immediately — but the drawer's debounced autosave (~850 ms later) POSTs its stale snapshot, which still carries the old `name` and old `useRegex`, overwriting the just-saved header change. The user's rename / regex toggle silently snaps back. This is real data loss, not cosmetic. **How to reproduce (try it yourself)** 1. Open a lorebook and expand an entry row (the drawer opens). 2. Type into the drawer's Description field (do **not** click away — the drawer is now dirty, autosave pending). 3. Within the autosave window, flip the regex toggle in the compact row header (or edit + blur the row's name input). That header patch saves `useRegex=true` (or the new name). 4. Wait for the drawer's autosave to flush. **You'll see:** the entry's `useRegex` flips back to false (or the name reverts to the old value). **Expected:** both the header change and the drawer edit persist. **Where it is** - `packages/client/src/components/lorebooks/LorebookEntryRow.tsx:1107-1138` (`buildEntrySavePayload`) — the drawer payload re-sends `name` (1109) and `useRegex` (1117) from its snapshot. - `:356-364` (`handleUseRegexToggle`) and `:366-373` (`handleNameCommit`) — the compact row header is the real owner of `useRegex` / `name`. - `:1308-1328` — the drawer's sync effect only refreshes `formRef.current` from the upstream `entry` when `switched || (!dirtyRef.current && !savingRef.current)`, so it refuses to refresh while the drawer is dirty. - `:1249-1267` (`saveNow`) — posts the stale `formRef.current` snapshot. - `packages/client/src/hooks/use-lorebooks.ts:179-190` (`useUpdateLorebookEntry`) — no optimistic update; only invalidates onSuccess. **What's happening** `buildEntrySavePayload` sends `name` and `useRegex`, both of which are only editable on the row header (the drawer has no input for either). The drawer's sync effect won't refresh its snapshot from a freshly refetched `entry` while the drawer is dirty, so a concurrent header patch to `name`/`useRegex` is held stale in `formRef.current` and re-sent on the next autosave, clobbering the newer server value. **Suggested fix** Drop `name` and `useRegex` from `buildEntrySavePayload` so the drawer never persists fields the row header also writes (the cleanest fix — neither field has an input inside the drawer, so the drawer has no business sending them). Alternatively, when the refetched `entry` differs on a field the drawer is **not** actively editing, merge that field into `formRef.current` even while dirty rather than discarding the whole refresh. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in the v2.0.7 branch: drawer autosaves no longer include header-owned name/useRegex fields, so stale drawer state cannot clobber row-header edits while the drawer is dirty. Validated with pnpm check.

<!-- gh-comment-id:4831160207 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in the v2.0.7 branch: drawer autosaves no longer include header-owned name/useRegex fields, so stale drawer state cannot clobber row-header edits while the drawer is dirty. Validated with pnpm check.
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#1547
No description provided.