[PR #274] [MERGED] fix(chat-input): enable send button immediately after branching #4539

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

📋 Pull Request Information

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

Base: main ← Head: fix/branch-send-button-enabled


📝 Commits (1)

  • b38b70a fix(chat-input): enable send button immediately after branching

📊 Changes

1 file changed (+13 additions, -0 deletions)

View changed files

📝 packages/client/src/components/chat/ChatInput.tsx (+13 -0)

📄 Description

Summary

Closes #259.

After creating a new branch, the send button stayed disabled until the user typed at least one character (then deleted it). This was a regression from prior versions where you could branch and immediately click send to prompt the LLM to continue.

Root cause

ChatInput.tsx derives canRetry / canContinue from lastMessageRole, which it reads off the React Query cache via qc.getQueryData(chatKeys.messages(activeChatId)). That call reads the cache once per render but does not subscribe to it — so when the new branch's messages finished loading, no re-render fired, and the button stayed in its disabled state. Typing produced a re-render, which re-read the cache and finally surfaced the new lastMessageRole.

The pre-existing comment explicitly forbids using useQuery here because mixing a useQuery observer with the useInfiniteQuery observer in useChatMessages on the same key corrupts query state.

Fix

Subscribe to the React Query cache for the active chat's messages key and bump a render counter when it updates. This keeps lastMessageRole reactive without introducing a conflicting observer.

const [, bumpMessagesTick] = useState(0);
useEffect(() => {
  if (!activeChatId) return;
  const targetKey = JSON.stringify(chatKeys.messages(activeChatId));
  return qc.getQueryCache().subscribe((event) => {
    if (JSON.stringify(event.query.queryKey) === targetKey) {
      bumpMessagesTick((n) => n + 1);
    }
  });
}, [activeChatId, qc]);

Test plan

  • Manually verify in browser: create a chat, branch it from an assistant message in roleplay mode, click send without typing — LLM should continue.
  • Manually verify in browser: branch from a user message — send should trigger retry without typing.
  • Manually verify in browser: switch between chats — drafts still restore and send-button state still matches each chat.
  • Manually verify in browser: typing + sending a normal message still works.
  • pnpm check passes (TS + ESLint, no new warnings introduced by this change).

Notes

  • No linked feature request beyond issue #259, which is the bug report itself.

Summary by CodeRabbit

  • Bug Fixes
    • Improved chat input responsiveness—the send button and related controls now update immediately when new messages arrive, without requiring user interaction.

🔄 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/274 **Author:** [@LukaTheHero](https://github.com/LukaTheHero) **Created:** 4/28/2026 **Status:** ✅ Merged **Merged:** 4/28/2026 **Merged by:** [@LukaTheHero](https://github.com/LukaTheHero) **Base:** `main` ← **Head:** `fix/branch-send-button-enabled` --- ### 📝 Commits (1) - [`b38b70a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b38b70a1966e9ce050dcb1bd72aeeeb2c48831fa) fix(chat-input): enable send button immediately after branching ### 📊 Changes **1 file changed** (+13 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/chat/ChatInput.tsx` (+13 -0) </details> ### 📄 Description ## Summary Closes #259. After creating a new branch, the send button stayed disabled until the user typed at least one character (then deleted it). This was a regression from prior versions where you could branch and immediately click send to prompt the LLM to continue. ### Root cause `ChatInput.tsx` derives `canRetry` / `canContinue` from `lastMessageRole`, which it reads off the React Query cache via `qc.getQueryData(chatKeys.messages(activeChatId))`. That call reads the cache once per render but does **not** subscribe to it — so when the new branch's messages finished loading, no re-render fired, and the button stayed in its disabled state. Typing produced a re-render, which re-read the cache and finally surfaced the new `lastMessageRole`. The pre-existing comment explicitly forbids using `useQuery` here because mixing a `useQuery` observer with the `useInfiniteQuery` observer in `useChatMessages` on the same key corrupts query state. ### Fix Subscribe to the React Query cache for the active chat's messages key and bump a render counter when it updates. This keeps `lastMessageRole` reactive without introducing a conflicting observer. ```tsx const [, bumpMessagesTick] = useState(0); useEffect(() => { if (!activeChatId) return; const targetKey = JSON.stringify(chatKeys.messages(activeChatId)); return qc.getQueryCache().subscribe((event) => { if (JSON.stringify(event.query.queryKey) === targetKey) { bumpMessagesTick((n) => n + 1); } }); }, [activeChatId, qc]); ``` ## Test plan - [ ] Manually verify in browser: create a chat, branch it from an assistant message in roleplay mode, click send without typing — LLM should continue. - [ ] Manually verify in browser: branch from a user message — send should trigger retry without typing. - [ ] Manually verify in browser: switch between chats — drafts still restore and send-button state still matches each chat. - [ ] Manually verify in browser: typing + sending a normal message still works. - [ ] `pnpm check` passes (TS + ESLint, no new warnings introduced by this change). ## Notes - No linked feature request beyond issue #259, which is the bug report itself. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved chat input responsiveness—the send button and related controls now update immediately when new messages arrive, without requiring user interaction. <!-- 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:32 +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#4539
No description provided.