[GH-ISSUE #3506] [Issue]: Persona portrait focus/zoom pending save is lost on tab close (no pagehide flush) #1894

Closed
opened 2026-10-21 05:43:36 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Persona portrait focus/zoom adjustments made in the tracker panel are saved through a 180ms debounce, and the only flush of a pending save happens in a React effect cleanup (component unmount). Nothing flushes the pending save when the document unloads, so closing the tab or hard-refreshing right after adjusting the portrait silently loses the adjustment.

Expected behavior

A pending portrait focus/zoom save survives tab close and hard refresh, the same way game-state patches and chat drafts already do (use-game-state-patcher.ts flushes on beforeunload with { keepalive: true }; ChatInput.tsx flushes drafts on pagehide).

Actual behavior

The flush lives only in an unmount effect cleanup (PersonaInventoryPanel.tsx ~302-309, renamed from PersonaTrackerPanel.tsx in PR #3503 with identical content). Effect cleanups do not run on document unload, so the debounced save (created at ~211-219, sent via useUpdatePersona at ~197) is dropped. During a continuous drag each movement resets the debounce, so the at-risk window is longer than 180ms in practice.

Steps to reproduce

  1. Open a chat whose tracker panel shows the persona inventory/portrait section.
  2. Adjust the persona portrait focus or zoom.
  3. Close the tab (or hard-refresh) immediately after the last adjustment, before the debounced save lands.
  4. Reload: the portrait adjustment has reverted.

Environment

  • Marinara Engine version: staging (code-level finding)
  • Install type: source
  • OS + version: any
  • Browser or app shell: any

Logs, screenshots, or video

Not applicable — this is a code-review finding. Relevant code:

  • packages/client/src/features/tracker-panel/components/sections/PersonaInventoryPanel.tsx — debounce ~211-219, flush call ~197, unmount-only cleanup flush ~302-309
  • packages/client/src/hooks/use-characters.ts useUpdatePersona (~1033) — does not currently accept any request options
  • packages/client/src/lib/api-client.ts — api.patch already accepts init?: RequestInit (~262); no lifecycle-tied AbortController exists, which is why the unmount-path flush works fine today without keepalive

Additional context

Origin: CodeRabbit review on PR #3503 suggested adding keepalive to the unmount flush; on verification the suggestion was withdrawn as misdirected because SPA unmount does not abort fetches — the actual gap is that no flush runs on document unload at all. Discussion: https://github.com/Pasta-Devs/Marinara-Engine/pull/3503#issuecomment-4949033335

Why it matters: the lost data is cosmetic (portrait focus X/Y/zoom inside trackerCardColors), so severity is low, but the fix is small and the codebase already has the pattern in three places.

Correct fix shape (the two halves are only useful together):

  1. Thread a narrow keepalive?: boolean option through useUpdatePersona, destructured OUT of the PATCH body before api.patch(..., data, keepalive ? { keepalive: true } : undefined) — following the use-achievements.ts precedent of a narrow boolean rather than raw RequestInit, so nothing can leak into the JSON body or override fetch options.
  2. Pass keepalive: true from the portrait flush, and add a pagehide listener in the panel that performs the same flush (mirror use-game-state-patcher.ts:411 / ChatInput.tsx's draft flush). The existing pending-save ref nulling already guards against double flushes on bfcache pagehide.

Should land after PR #3503 (which renames the file) to avoid conflicts.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jul 11, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3506 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Persona portrait focus/zoom adjustments made in the tracker panel are saved through a 180ms debounce, and the only flush of a pending save happens in a React effect cleanup (component unmount). Nothing flushes the pending save when the document unloads, so closing the tab or hard-refreshing right after adjusting the portrait silently loses the adjustment. ## Expected behavior A pending portrait focus/zoom save survives tab close and hard refresh, the same way game-state patches and chat drafts already do (`use-game-state-patcher.ts` flushes on `beforeunload` with `{ keepalive: true }`; `ChatInput.tsx` flushes drafts on `pagehide`). ## Actual behavior The flush lives only in an unmount effect cleanup (`PersonaInventoryPanel.tsx` ~302-309, renamed from `PersonaTrackerPanel.tsx` in PR #3503 with identical content). Effect cleanups do not run on document unload, so the debounced save (created at ~211-219, sent via `useUpdatePersona` at ~197) is dropped. During a continuous drag each movement resets the debounce, so the at-risk window is longer than 180ms in practice. ## Steps to reproduce 1. Open a chat whose tracker panel shows the persona inventory/portrait section. 2. Adjust the persona portrait focus or zoom. 3. Close the tab (or hard-refresh) immediately after the last adjustment, before the debounced save lands. 4. Reload: the portrait adjustment has reverted. ## Environment - Marinara Engine version: staging (code-level finding) - Install type: source - OS + version: any - Browser or app shell: any ## Logs, screenshots, or video Not applicable — this is a code-review finding. Relevant code: - `packages/client/src/features/tracker-panel/components/sections/PersonaInventoryPanel.tsx` — debounce ~211-219, flush call ~197, unmount-only cleanup flush ~302-309 - `packages/client/src/hooks/use-characters.ts` `useUpdatePersona` (~1033) — does not currently accept any request options - `packages/client/src/lib/api-client.ts` — `api.patch` already accepts `init?: RequestInit` (~262); no lifecycle-tied `AbortController` exists, which is why the unmount-path flush works fine today without `keepalive` ## Additional context Origin: CodeRabbit review on PR #3503 suggested adding `keepalive` to the unmount flush; on verification the suggestion was withdrawn as misdirected because SPA unmount does not abort fetches — the actual gap is that no flush runs on document unload at all. Discussion: https://github.com/Pasta-Devs/Marinara-Engine/pull/3503#issuecomment-4949033335 Why it matters: the lost data is cosmetic (portrait focus X/Y/zoom inside `trackerCardColors`), so severity is low, but the fix is small and the codebase already has the pattern in three places. Correct fix shape (the two halves are only useful together): 1. Thread a narrow `keepalive?: boolean` option through `useUpdatePersona`, destructured OUT of the PATCH body before `api.patch(..., data, keepalive ? { keepalive: true } : undefined)` — following the `use-achievements.ts` precedent of a narrow boolean rather than raw `RequestInit`, so nothing can leak into the JSON body or override fetch options. 2. Pass `keepalive: true` from the portrait flush, and add a `pagehide` listener in the panel that performs the same flush (mirror `use-game-state-patcher.ts:411` / `ChatInput.tsx`'s draft flush). The existing pending-save ref nulling already guards against double flushes on bfcache `pagehide`. Should land after PR #3503 (which renames the file) to avoid conflicts. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:43:36 +07:00
  • closed this issue
  • added the
    in-pr
    bug
    labels
Author
Owner

@SpicyMarinara commented on GitHub (Jul 11, 2026):

Claimed for implementation by @SpicyMarinara in draft PR #3507.

<!-- gh-comment-id:4949121751 --> @SpicyMarinara commented on GitHub (Jul 11, 2026): Claimed for implementation by @SpicyMarinara in draft PR #3507.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 11, 2026):

Addressed in PR #3507, which is ready for review and has CodeRabbit requested.

<!-- gh-comment-id:4949217429 --> @SpicyMarinara commented on GitHub (Jul 11, 2026): Addressed in PR #3507, which is ready for review and has CodeRabbit requested.
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#1894
No description provided.