fix: composer send attempt while signed out reopens login instead of dead-ending

SW
4mo ago
+129-7

What

On chat.recoupable.dev, a signed-out visitor who dismisses the Privy login modal can type in the composer but can never send: the workspace never provisions without auth, so the send button stays permanently disabled and Enter is a silent no-op (form.requestSubmit() bails when the default submit button is disabled). This PR turns that dead end into a login reprompt: any send attempt (button click or Enter) while unauthenticated reopens the Privy login modal via usePrivy().login().

Part of recoupable/chat#1902 (item C4).

How

  • New lib/chat/getComposerSubmitAction.ts: pure decision function returning "send" | "prompt-login" | "disabled". Auth is checked before workspace blockers, because the workspace never provisions for anonymous visitors; without that ordering the signed-out state is permanently "disabled".
  • components/VercelChat/ChatInput.tsx: computes the action from usePrivy() (ready, authenticated, login) plus the existing context flags. When the action is prompt-login the send button stays enabled and the submit handler calls login() instead of handleSendMessage. Signed-in behavior (workspace gating, stop-while-generating, empty-input no-op) is unchanged. The button also gains a state-accurate aria-label ("Sign in to send" / "Send message" / "Stop response").
  • login() is never called before Privy finishes initializing (ready gate in the decision function).

Draft persistence: the composer draft is React state (useState("") in hooks/useVercelChat.ts) inside the <Chat> instance, which NewChatBootstrap keeps mounted with a stable ref-based id across the provisioning transition. The Privy modal is an overlay, so nothing unmounts: the drafted text survives dismissing and reopening the modal and the full auth flow, and sends normally once the workspace provisions after login.

How to test

  1. Open the preview signed out and dismiss the auto-opened Privy login modal.
  2. Type a message in the composer. The send button is now enabled (previously stuck disabled).
  3. Click send or press Enter: the Privy login modal reopens and the typed text stays in the composer.
  4. Dismiss again, press Enter again: modal reopens again (repeatable, no dead end).
  5. Complete login: the draft is still in the composer; once the workspace dot turns green, send works normally.
  6. Signed in: empty-input Enter still does nothing, sends still gate on workspace readiness, and the stop button still works mid-response.

Tests: pnpm exec vitest run (282 passed, incl. 6 new for getComposerSubmitAction); pnpm exec tsc --noEmit clean for the changed files.

Preview verification to follow in a PR comment.

🤖 Generated with Claude Code


Summary by cubic

Fixes the signed-out composer dead end: pressing Send or Enter now reopens the Privy login modal and preserves the draft. Addresses recoupable/chat#1902 (C4).

  • Bug Fixes
    • Added getComposerSubmitAction to decide between "send" | "prompt-login" | "disabled", checking auth before workspace blockers.
    • Updated VercelChat/ChatInput to call usePrivy().login() from @privy-io/react-auth on unauthenticated send, keep Send enabled with correct aria-labels, and guard until Privy is ready; drafts persist and signed-in behavior is unchanged.