[PR #239] [MERGED] fix(client): persist Author's Notes across outside-click dismissal #4522

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/239
Author: @LukaTheHero
Created: 4/26/2026
Status: ✅ Merged
Merged: 4/26/2026
Merged by: @LukaTheHero

Base: main ← Head: fix/author-notes-save-race


📝 Commits (1)

  • 4741b8d fix(client): persist Author's Notes across outside-click dismissal

📊 Changes

1 file changed (+29 additions, -1 deletions)

View changed files

📝 packages/client/src/components/chat/ChatRoleplayPanels.tsx (+29 -1)

📄 Description

The bug

Open Author's Notes, type something, click outside the popover — typed content is lost some of the time.

Root cause

The outside-click handler in AuthorNotesButton fires on mousedown and calls setOpen(false), which unmounts the textarea before its onBlur (the only save trigger) can run. onBlur is the lone save path, so when it loses the race the edit is dropped.

Big thanks to @Trade-Mottoes for surfacing this in #213 — the diagnosis there is spot on. I'm taking a different fix path here so we can keep the existing CSS/HTML structure and the no-explicit-save UX intact (Marinara prefers consistency with the existing infrastructure, and the popover should just persist what you typed without a Save button).

Fix

Flush pending edits from a useEffect cleanup in AuthorNotesPanel.

  • Cleanups run synchronously when React unmounts the component, so the save fires even when outside-click destroys the textarea before onBlur.
  • React Query's mutate is fire-and-forget — the network request goes out fine after the component is gone.
  • A baselineRef snapshot of the incoming chatMeta gates the flush, so we only mutate when the user actually changed something (no spurious writes on simple peek-and-close).
  • A latestRef carries the most recent textarea/depth values into the cleanup closure.
  • The existing onBlur save path is preserved — it still handles the tab-between-fields case where the popover stays mounted.

What did NOT change

  • No markup, no CSS, no new components, no Modal swap, no Save/Cancel buttons.
  • Mobile and desktop render exactly the same as before.
  • One file touched: packages/client/src/components/chat/ChatRoleplayPanels.tsx (+29 / -1).

Testing

  • pnpm check passes.
  • Manually verified: rapid type-then-outside-click no longer loses content, on both desktop popover and mobile portal.
  • Verified peek-and-close (no edit) does not trigger an unnecessary mutation.

Test plan

  • Open Author's Notes, type a paragraph, click outside — re-open and confirm content is preserved.
  • Repeat 10x rapidly to confirm the race is gone.
  • Change Injection Depth, click outside — confirm depth persists.
  • Open Author's Notes and close without typing — confirm no extraneous network calls.
  • Mobile viewport: same scenarios via the portal.

Summary by CodeRabbit

  • Bug Fixes
    • Improved author notes preservation by ensuring edits are reliably saved when navigating between chats, preventing accidental data loss from rapid interactions or panel closures.

🔄 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/239 **Author:** [@LukaTheHero](https://github.com/LukaTheHero) **Created:** 4/26/2026 **Status:** ✅ Merged **Merged:** 4/26/2026 **Merged by:** [@LukaTheHero](https://github.com/LukaTheHero) **Base:** `main` ← **Head:** `fix/author-notes-save-race` --- ### 📝 Commits (1) - [`4741b8d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4741b8d93c710b95b057de129c2017a8a9c50edd) fix(client): persist Author's Notes across outside-click dismissal ### 📊 Changes **1 file changed** (+29 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatRoleplayPanels.tsx` (+29 -1) </details> ### 📄 Description ## The bug Open Author's Notes, type something, click outside the popover — typed content is lost some of the time. ## Root cause The outside-click handler in `AuthorNotesButton` fires on `mousedown` and calls `setOpen(false)`, which unmounts the textarea before its `onBlur` (the only save trigger) can run. `onBlur` is the lone save path, so when it loses the race the edit is dropped. Big thanks to @Trade-Mottoes for surfacing this in #213 — the diagnosis there is spot on. I'm taking a different fix path here so we can keep the existing CSS/HTML structure and the no-explicit-save UX intact (Marinara prefers consistency with the existing infrastructure, and the popover should just persist what you typed without a Save button). ## Fix Flush pending edits from a `useEffect` cleanup in `AuthorNotesPanel`. - Cleanups run synchronously when React unmounts the component, so the save fires even when outside-click destroys the textarea before `onBlur`. - React Query's `mutate` is fire-and-forget — the network request goes out fine after the component is gone. - A `baselineRef` snapshot of the incoming `chatMeta` gates the flush, so we only mutate when the user actually changed something (no spurious writes on simple peek-and-close). - A `latestRef` carries the most recent textarea/depth values into the cleanup closure. - The existing `onBlur` save path is preserved — it still handles the tab-between-fields case where the popover stays mounted. ## What did NOT change - No markup, no CSS, no new components, no Modal swap, no Save/Cancel buttons. - Mobile and desktop render exactly the same as before. - One file touched: `packages/client/src/components/chat/ChatRoleplayPanels.tsx` (+29 / -1). ## Testing - `pnpm check` passes. - Manually verified: rapid type-then-outside-click no longer loses content, on both desktop popover and mobile portal. - Verified peek-and-close (no edit) does not trigger an unnecessary mutation. ## Test plan - [x] Open Author's Notes, type a paragraph, click outside — re-open and confirm content is preserved. - [x] Repeat 10x rapidly to confirm the race is gone. - [x] Change Injection Depth, click outside — confirm depth persists. - [x] Open Author's Notes and close without typing — confirm no extraneous network calls. - [x] Mobile viewport: same scenarios via the portal. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved author notes preservation by ensuring edits are reliably saved when navigating between chats, preventing accidental data loss from rapid interactions or panel closures. <!-- 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-22 04:08: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#4522
No description provided.