[PR #213] [CLOSED] fix(client): Author's Notes edits lost on outside-click #4508

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/213
Author: @Trade-Mottoes
Created: 4/24/2026
Status: ❌ Closed

Base: main ← Head: refactor/author-notes-dialog


📝 Commits (1)

  • b71f15a fix(client): Author's Notes edits lost on outside-click

📊 Changes

2 files changed (+184 additions, -58 deletions)

View changed files

📝 packages/client/src/components/chat/ChatRoleplayPanels.tsx (+136 -38)
📝 packages/client/src/components/chat/ChatRoleplaySurface.tsx (+48 -20)

📄 Description

The bug

Open Author's Notes, type content, click outside the popover. The typed content is lost — sometimes. Whether the save takes is, in the current implementation, in the lap of the gods. :)

Repro: Open Author's Notes on any chat. Type a paragraph. Click anywhere outside the popover. Re-open. Roughly half the time the content is gone.

Root cause

The outside-click handler fires on mousedown and unmounts the textarea before its onBlur (which triggered the save) can run. No reliable fix is possible within the popover-plus-blur-save architecture — the container is trying to be both a transient peek surface (dismiss on mousedown) and a live editor (persist on blur), and those contracts race by construction.

Fix

Split viewing and editing into their proper containers.

  • AuthorNotesPeek — read-only popover. Transient dismissal is safe because no mutation is in flight. Uses click rather than mousedown for predictable close semantics.
  • AuthorNotesPanel — committed editing in the shared Modal primitive (same one used by EditAgentModal, LorebookMakerModal, etc.) with explicit Save / Cancel. isDirty gates prop-sync so external refetches don't clobber pending edits.
  • AuthorNotesButton — three-state machine (closed / peek / edit) owning all transitions; the two child components are unaware of each other.

Why peek/edit rather than just "use Modal for everything"

Viewing and editing have different optimal containers. Peeking is by far the more common action ("what did I put in here again?") and is cheap, frequent, and safe. Editing wants a committed feel — backdrop, focus trap, Escape. The one-container-fits-both compromise is precisely what caused the save race: the popover was trying to serve both contracts at once.

User-visible result

All four close paths (X / backdrop / Escape / Cancel) are race-proof by construction. Desktop and mobile now render as a single consistent dialog (previously desktop was a popover, mobile a full-screen portal). Also picks up role=dialog, aria-modal, Escape handling and focus trap from the shared Modal.

Testing

  • pnpm lint && pnpm build pass.
  • Manually verified all four close paths on desktop and mobile viewport.
  • Manually verified the save race is gone: rapid type-then-outside-click no longer loses content.

Screenshots

Peek with discrete edit button:
image

Edit:
image

Summary by CodeRabbit

Release Notes

  • New Features
    • Author's Notes now use explicit Save and Cancel buttons for draft editing instead of auto-save.
    • Preview mode for Author's Notes is now read-only with an Edit button to transition to edit mode.
    • Enhanced mobile UI for Author's Notes with improved preview and edit workflow.

🔄 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/213 **Author:** [@Trade-Mottoes](https://github.com/Trade-Mottoes) **Created:** 4/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `refactor/author-notes-dialog` --- ### 📝 Commits (1) - [`b71f15a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b71f15af1cb141693c3f6945f8c48eeca105e0d3) fix(client): Author's Notes edits lost on outside-click ### 📊 Changes **2 files changed** (+184 additions, -58 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatRoleplayPanels.tsx` (+136 -38) 📝 `packages/client/src/components/chat/ChatRoleplaySurface.tsx` (+48 -20) </details> ### 📄 Description ## The bug Open Author's Notes, type content, click outside the popover. The typed content is lost — sometimes. Whether the save takes is, in the current implementation, in the lap of the gods. :) **Repro:** Open Author's Notes on any chat. Type a paragraph. Click anywhere outside the popover. Re-open. Roughly half the time the content is gone. ## Root cause The outside-click handler fires on `mousedown` and unmounts the textarea before its `onBlur` (which triggered the save) can run. No reliable fix is possible within the popover-plus-blur-save architecture — the container is trying to be both a transient peek surface (dismiss on mousedown) and a live editor (persist on blur), and those contracts race by construction. ## Fix Split viewing and editing into their proper containers. - **`AuthorNotesPeek`** — read-only popover. Transient dismissal is safe because no mutation is in flight. Uses `click` rather than `mousedown` for predictable close semantics. - **`AuthorNotesPanel`** — committed editing in the shared `Modal` primitive (same one used by `EditAgentModal`, `LorebookMakerModal`, etc.) with explicit Save / Cancel. `isDirty` gates prop-sync so external refetches don't clobber pending edits. - **`AuthorNotesButton`** — three-state machine (closed / peek / edit) owning all transitions; the two child components are unaware of each other. ## Why peek/edit rather than just "use Modal for everything" Viewing and editing have different optimal containers. Peeking is by far the more common action ("what did I put in here again?") and is cheap, frequent, and safe. Editing wants a committed feel — backdrop, focus trap, Escape. The one-container-fits-both compromise is precisely what caused the save race: the popover was trying to serve both contracts at once. ## User-visible result All four close paths (X / backdrop / Escape / Cancel) are race-proof by construction. Desktop and mobile now render as a single consistent dialog (previously desktop was a popover, mobile a full-screen portal). Also picks up `role=dialog`, `aria-modal`, Escape handling and focus trap from the shared `Modal`. ## Testing - `pnpm lint && pnpm build` pass. - Manually verified all four close paths on desktop and mobile viewport. - Manually verified the save race is gone: rapid type-then-outside-click no longer loses content. ## Screenshots Peek with discrete edit button: <img width="350" height="220" alt="image" src="https://github.com/user-attachments/assets/56e593e7-86b6-4621-b92b-60dbe56fdfa1" /> Edit: <img width="501" height="399" alt="image" src="https://github.com/user-attachments/assets/3cd58a33-9f81-47fd-a1d6-39d1d0a5d887" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Author's Notes now use explicit Save and Cancel buttons for draft editing instead of auto-save. * Preview mode for Author's Notes is now read-only with an Edit button to transition to edit mode. * Enhanced mobile UI for Author's Notes with improved preview and edit workflow. <!-- 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:15 +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#4508
No description provided.