mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #275] [MERGED] fix(chat-bg): make Remove background actually stick across switches #4540
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#4540
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/275
Author: @LukaTheHero
Created: 4/28/2026
Status: ✅ Merged
Merged: 4/28/2026
Merged by: @LukaTheHero
Base:
main← Head:fix/chat-background-remove-persist📝 Commits (1)
c6d3442fix(chat-bg): make Remove background actually stick across switches📊 Changes
3 files changed (+60 additions, -16 deletions)
View changed files
📝
packages/client/src/components/chat/ChatArea.tsx(+28 -12)📝
packages/client/src/components/panels/SettingsPanel.tsx(+20 -2)📝
packages/client/src/hooks/use-chats.ts(+12 -2)📄 Description
Summary
Closes #260.
Removing a chat background via the Settings panel did not survive chat switches (and sometimes did not survive a page refresh either). Three compounding issues were responsible:
1. Stale React Query cache after metadata writes
useUpdateChatMetadataonly calledqc.invalidateQueries(...)on success and never wrote the server response into the cache. React Query invalidation only triggers a refetch when an active observer is mounted; if the user fired the mutation and then navigated away, the cache was marked stale but never refreshed. Coming back to that chat served the pre-mutation snapshot, and the restore effect re-applied the supposedly-removed background.Fix: the hook now
setQueryData(chatKeys.detail(id), data)directly with the mutation response, so the cache is always fresh regardless of observer state. Falls back to invalidate if the response is null.2. Restore effect was a one-way sync
ChatArea's background-restore effect only setchatBackgroundwhen the chat's metadata had a value — it never cleared the global UI-store value. Switching to a chat whose metadata was empty (or had been cleared) left whatever URL was last in the store, including from the previous chat.Fix: the effect now mirrors metadata exactly, setting
nullwhen metadata has no background. Brand-new chats no longer carry over the previous chat's background as a "don't flash to black" preview, but a fresh-empty chat is the more honest behavior.3. Remove button leaned on a fragile debounced effect chain
The Remove handler in
SettingsPanelonly calledsetChatBackground(null). Persistence relied on auseEffectinChatAreato observe that change and (after a 500 ms debounce) fire a metadata patch. That chain had timing/closure ambiguities that occasionally dropped the write.Fix: the handler now calls
useUpdateChatMetadatadirectly from the click, alongside the UI-store update — no debounce, no effect dep race.The
ChatAreapersist effect's null-write branch is left in place because slash commands, scene events, and agent paths still clear the background without going through Settings.Files
packages/client/src/hooks/use-chats.ts—useUpdateChatMetadata.onSuccesswrites response into the detail cache.packages/client/src/components/chat/ChatArea.tsx— restore effect now syncs to null when metadata is empty.packages/client/src/components/panels/SettingsPanel.tsx— Remove / pick handler fires the mutation directly.Side benefits
Every other consumer of
useUpdateChatMetadata(sprite settings, branch labels, chat setup wizard, summary popover, game-state sync, etc.) now sees its mutation result reflected in the cache immediately rather than after a refetch round-trip. No behavior changes for those callers; they just get consistent freshness.Game mode is unaffected by the restore-effect change —
GameSurfacedeliberately ignoreschatBackground(_chatBackgroundunderscore-prefixed at line 565, with an accompanying comment) and renders its own scene-derived background from the asset manifest.Test plan
pnpm checkpasses (no new TS / ESLint regressions).Notes
No linked feature request beyond issue #260, which is the bug report itself.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.