[PR #8912] [MERGED] perf(client): instant message delete, chat rename and folder edits #8878

Closed
opened 2026-11-07 17:40:25 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8912
Author: @Gunterlie
Created: 11/6/2026
Status: ✅ Merged
Merged: 11/6/2026
Merged by: @Gunterlie

Base: staging ← Head: perf/feel-4-optimistic-actions


📝 Commits (7)

  • 5b13434 perf(client): show message deletes, chat renames and folder edits at once
  • c60258c fix(client): refetch instead of restoring snapshots when an optimistic action fails
  • 5123d2a fix(client): put back only the hidden items when an optimistic action fails
  • 5269aca fix(client): show pending deletes, renames and folder edits on read instead of rewriting the cache
  • fd8c251 fix(client): refetch after refused actions and keep deletes hidden until the transcript refetch
  • f8100e9 fix(client): hide server-confirmed deletes on read and never shorten cached pages
  • 36734a5 fix(client): end the hiding of confirmed deletes on any newer transcript fetch

📊 Changes

6 files changed (+243 additions, -7 deletions)

View changed files

📝 packages/client/src/hooks/use-characters.ts (+31 -2)
📝 packages/client/src/hooks/use-chats.ts (+103 -5)
➕ packages/client/src/lib/character-group-cache.ts (+18 -0)
📝 packages/client/src/lib/message-page-cache.ts (+21 -0)
➕ scripts/regressions/character-group-cache.regression.ts (+33 -0)
📝 scripts/regressions/message-page-cache.regression.ts (+37 -0)

📄 Description

Part of #8904 (slice 4).

Why

Deleting a message, renaming a chat or editing a character folder waited for the server round-trip before the UI changed. On a slow box or a remote install that reads as "did my click work?". These actions now show at once and refetch from the server if it refuses (no snapshot restore, so changes that land during the request are kept).

What changed

The caches keep the server data. The queries show pending mutations on top of it through TanStack's useMutationState + select, so a failed action simply stops being pending and nothing has to be put back.

  • Message delete (single and bulk): useChatMessages hides messages whose delete is pending, and after success keeps them hidden (small per-chat list) until the transcript refetch lands. The cached pages are never shortened, so Load more and page order stay correct. A refused delete just shows the message again and refetches.
  • Chat rename: useChats, useChat and useChatGroup show the pending name at once. On success the server copy is written as before.
  • Character folder rename / move / delete: useCharacterGroups shows pending folder updates and deletes in order (applyGroupEdits in lib/character-group-cache.ts; members written as the JSON string the server stores). On success the edit is written to the cache, then the groups and catalog refresh.
  • Not in this slice: swipe delete stays server-first, because the server decides which swipe shows next. The character favourite has no quick toggle today; it saves with the editor.

Validation

  • Client tsc --noEmit: pass.
  • ESLint on the changed files: pass.
  • message-page-cache regression (extended with removeMessagesFromPages) and new character-group-cache regression (stacked edits, failed rename after a landed move, two failed edits, pending delete): pass.

Manual checks

  • Manually verify in a browser: delete one message and a bulk selection; they vanish at once. Stop the server (or block the request in DevTools) and delete again; the messages come back with an error.
  • Manually verify: in a chat with older history, delete a message while the follow-up messages request is blocked; Load more stays visible and the deleted message stays hidden.
  • Manually verify: rename a chat from the sidebar; the name changes at once in the sidebar and the chat header, including a chat inside a group.
  • Manually verify: rename, move cards into, and delete a character folder; the panel updates at once.

Review

CodeRabbit CLI auth is not available on this host; the marinara-reviewer agent and Dottore reviewed it. Earlier rounds rewrote the cache and restored on error; each restore variant lost data in some case (concurrent replies, unreachable server, shortened pages hiding Load more, stale indices, stacked folder edits). The current design avoids restores entirely by showing pending mutations on read.


🔄 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/8912 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 11/6/2026 **Status:** ✅ Merged **Merged:** 11/6/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `staging` ← **Head:** `perf/feel-4-optimistic-actions` --- ### 📝 Commits (7) - [`5b13434`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5b13434c24121b7f3248df08af84751ca19cffc4) perf(client): show message deletes, chat renames and folder edits at once - [`c60258c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c60258c9da646d16c7cc47ea8d8755a777395361) fix(client): refetch instead of restoring snapshots when an optimistic action fails - [`5123d2a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5123d2ad7d71daaf5013d70509c1ddd89003494b) fix(client): put back only the hidden items when an optimistic action fails - [`5269aca`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5269acaaaa365f14f1ea7a40a3a433704d1bb6d4) fix(client): show pending deletes, renames and folder edits on read instead of rewriting the cache - [`fd8c251`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fd8c251c4cd1ac01778a4dc40ef9680d31db5122) fix(client): refetch after refused actions and keep deletes hidden until the transcript refetch - [`f8100e9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f8100e92fb1eec900955838e132aeed30f480b61) fix(client): hide server-confirmed deletes on read and never shorten cached pages - [`36734a5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/36734a5b33e3cfb75293789e47fa1feb9c99a926) fix(client): end the hiding of confirmed deletes on any newer transcript fetch ### 📊 Changes **6 files changed** (+243 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/hooks/use-characters.ts` (+31 -2) 📝 `packages/client/src/hooks/use-chats.ts` (+103 -5) ➕ `packages/client/src/lib/character-group-cache.ts` (+18 -0) 📝 `packages/client/src/lib/message-page-cache.ts` (+21 -0) ➕ `scripts/regressions/character-group-cache.regression.ts` (+33 -0) 📝 `scripts/regressions/message-page-cache.regression.ts` (+37 -0) </details> ### 📄 Description Part of #8904 (slice 4). ## Why Deleting a message, renaming a chat or editing a character folder waited for the server round-trip before the UI changed. On a slow box or a remote install that reads as "did my click work?". These actions now show at once and refetch from the server if it refuses (no snapshot restore, so changes that land during the request are kept). ## What changed The caches keep the server data. The queries show pending mutations on top of it through TanStack's `useMutationState` + `select`, so a failed action simply stops being pending and nothing has to be put back. - **Message delete (single and bulk):** `useChatMessages` hides messages whose delete is pending, and after success keeps them hidden (small per-chat list) until the transcript refetch lands. The cached pages are never shortened, so Load more and page order stay correct. A refused delete just shows the message again and refetches. - **Chat rename:** `useChats`, `useChat` and `useChatGroup` show the pending name at once. On success the server copy is written as before. - **Character folder rename / move / delete:** `useCharacterGroups` shows pending folder updates and deletes in order (`applyGroupEdits` in `lib/character-group-cache.ts`; members written as the JSON string the server stores). On success the edit is written to the cache, then the groups and catalog refresh. - **Not in this slice:** swipe delete stays server-first, because the server decides which swipe shows next. The character favourite has no quick toggle today; it saves with the editor. ## Validation - Client `tsc --noEmit`: pass. - ESLint on the changed files: pass. - `message-page-cache` regression (extended with `removeMessagesFromPages`) and new `character-group-cache` regression (stacked edits, failed rename after a landed move, two failed edits, pending delete): pass. ## Manual checks - [ ] Manually verify in a browser: delete one message and a bulk selection; they vanish at once. Stop the server (or block the request in DevTools) and delete again; the messages come back with an error. - [ ] Manually verify: in a chat with older history, delete a message while the follow-up messages request is blocked; Load more stays visible and the deleted message stays hidden. - [ ] Manually verify: rename a chat from the sidebar; the name changes at once in the sidebar and the chat header, including a chat inside a group. - [ ] Manually verify: rename, move cards into, and delete a character folder; the panel updates at once. ## Review CodeRabbit CLI auth is not available on this host; the `marinara-reviewer` agent and Dottore reviewed it. Earlier rounds rewrote the cache and restored on error; each restore variant lost data in some case (concurrent replies, unreachable server, shortened pages hiding Load more, stale indices, stacked folder edits). The current design avoids restores entirely by showing pending mutations on read. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:40:25 +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#8878
No description provided.