[PR #288] [MERGED] Fix/persona editor avatar refetch clobbers draft #4548

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/288
Author: @Xelvanis
Created: 4/28/2026
Status: ✅ Merged
Merged: 4/28/2026
Merged by: @SpicyMarinara

Base: main ← Head: fix/persona-editor-avatar-refetch-clobbers-draft


📝 Commits (4)

  • f71809a feat(persona-editor): enhance persona loading and avatar synchronization
  • 9f1839f fix(persona-editor): guard avatar upload races and sync persona cache
  • 6f77be4 fix(react-query): merge persona cache updates defensively
  • e3b07bd chore(react-query): tighten persona cache merge typing

📊 Changes

2 files changed (+37 additions, -4 deletions)

View changed files

📝 packages/client/src/components/personas/PersonaEditor.tsx (+21 -3)
📝 packages/client/src/hooks/use-characters.ts (+16 -1)

📄 Description

Linked issue

Closes #290

Summary

Prevents unsaved persona form edits from being overwritten when the persona list refetches after an avatar upload/change.

Why this change

Users editing a Persona could lose in-progress text if they changed the avatar. Avatar uploads trigger a personas refetch; the editor was re-initializing formData from server data on refetch, clobbering local unsaved edits and causing apparent “field wipes”.

What changed

  • Track the currently loaded persona id and only initialize formData when opening/switching personas (or when not dirty).
  • Keep avatarPreview synced with server avatar path without resetting formData.
  • Clear the file input after selection so the same image can be re-selected, and revert preview on upload failure.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Opened make new persona, added text to fields, enabled persona stats, added custom tracker field, uploaded avatar picture, verified all added text and the custom tracker field remained
  • Opened existing persona, changed field text, uploaded new avatar, verified field text change remained instead of reverting to previous state
  • Verified pressing save works as normal and saved data persists after browser refresh.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

Notes for reviewers

This is intentionally scoped to PersonaEditor local state management; no server/shared schema changes.

Quick review for errors / unwanted behavior

  • Scope is tight: only packages/client/src/components/personas/PersonaEditor.tsx changed.
  • Risk check: the key guard is if (!isSwitchingPersona && dirty) return; which prevents refetch clobbering. That’s exactly what we want for this bug.
  • Switching personas: still reinitializes the form when rawPersona.id changes (expected).
  • Avatar sync effect: only fills avatarPreview when it’s null, so it won’t override a freshly-selected local preview.
  • Validation: pnpm check passed locally (lint + build). Only remaining lint warning is unrelated (ConversationInput.tsx).

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced persona editor to better handle persona switching and server-driven updates
    • Avatar preview now correctly syncs with server changes without affecting form data
    • Improved avatar upload error recovery with automatic preview reversion and file input reset
    • Better preservation of unsaved edits when server data is refreshed

Summary by CodeRabbit

  • Bug Fixes

    • Avatar upload failures now revert the preview to the last saved state.
    • Local edits are preserved when server data is refreshed; the editor no longer overwrites the form unless the persona changes.
    • Re-uploading the same avatar file now works reliably; avatar input is cleared after selection.
    • Avatar uploads are de-duplicated and made race-safe to prevent incorrect previews.
  • New Features

    • Persona updates apply optimistically for snappier list updates, then refresh from the server.

🔄 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/288 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 4/28/2026 **Status:** ✅ Merged **Merged:** 4/28/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `main` ← **Head:** `fix/persona-editor-avatar-refetch-clobbers-draft` --- ### 📝 Commits (4) - [`f71809a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f71809a60ef33299245143186d36ae15bb642c14) feat(persona-editor): enhance persona loading and avatar synchronization - [`9f1839f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9f1839f1944daf340b7cbf25f1be4430102e4298) fix(persona-editor): guard avatar upload races and sync persona cache - [`6f77be4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6f77be4fd241db87929a69189d9ad8c0d7a2a792) fix(react-query): merge persona cache updates defensively - [`e3b07bd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e3b07bded6bf31efbd98ec2fbbe8a62478ffe662) chore(react-query): tighten persona cache merge typing ### 📊 Changes **2 files changed** (+37 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/personas/PersonaEditor.tsx` (+21 -3) 📝 `packages/client/src/hooks/use-characters.ts` (+16 -1) </details> ### 📄 Description ## Linked issue Closes #290 ## Summary Prevents unsaved persona form edits from being overwritten when the persona list refetches after an avatar upload/change. ## Why this change Users editing a Persona could lose in-progress text if they changed the avatar. Avatar uploads trigger a personas refetch; the editor was re-initializing `formData` from server data on refetch, clobbering local unsaved edits and causing apparent “field wipes”. ## What changed - Track the currently loaded persona id and **only initialize `formData`** when opening/switching personas (or when not dirty). - Keep `avatarPreview` synced with server avatar path **without resetting `formData`**. - Clear the file input after selection so the same image can be re-selected, and revert preview on upload failure. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [X] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [X] Above manual verification completed (describe below) - [X] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Opened make new persona, added text to fields, enabled persona stats, added custom tracker field, uploaded avatar picture, verified all added text and the custom tracker field remained - Opened existing persona, changed field text, uploaded new avatar, verified field text change remained instead of reverting to previous state - Verified pressing save works as normal and saved data persists after browser refresh. ## Docs and release impact - [X] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) <!-- Add before/after screenshots or recordings for UI changes --> ### Notes for reviewers This is intentionally scoped to `PersonaEditor` local state management; no server/shared schema changes. ## Quick review for errors / unwanted behavior - **Scope is tight**: only `packages/client/src/components/personas/PersonaEditor.tsx` changed. - **Risk check**: the key guard is `if (!isSwitchingPersona && dirty) return;` which prevents refetch clobbering. That’s exactly what we want for this bug. - **Switching personas**: still reinitializes the form when `rawPersona.id` changes (expected). - **Avatar sync effect**: only fills `avatarPreview` when it’s null, so it won’t override a freshly-selected local preview. - **Validation**: `pnpm check` passed locally (lint + build). Only remaining lint warning is unrelated (`ConversationInput.tsx`). ## Summary by CodeRabbit * **Bug Fixes** * Enhanced persona editor to better handle persona switching and server-driven updates * Avatar preview now correctly syncs with server changes without affecting form data * Improved avatar upload error recovery with automatic preview reversion and file input reset * Better preservation of unsaved edits when server data is refreshed <!-- end of auto-generated comment: release notes by coderabbit.ai --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Avatar upload failures now revert the preview to the last saved state. * Local edits are preserved when server data is refreshed; the editor no longer overwrites the form unless the persona changes. * Re-uploading the same avatar file now works reliably; avatar input is cleared after selection. * Avatar uploads are de-duplicated and made race-safe to prevent incorrect previews. * **New Features** * Persona updates apply optimistically for snappier list updates, then refresh from the server. <!-- 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:36 +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#4548
No description provided.