Skip to content

Conversation

Rish-it
Copy link
Contributor

@Rish-it Rish-it commented Aug 27, 2025

Description

Related Issues

Fixes #2761

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Release
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes


Important

Fixes response halting in chat by managing isStopped state and refines code style by removing unnecessary parentheses.

  • Chat Functionality:
    • Adds isStopped state in use-chat.tsx to manage chat stopping.
    • Updates sendMessage and stop functions to handle isStopped state.
    • Ensures isStopped is reset on chat finish and error.
  • Code Style:
    • Removes unnecessary parentheses in onlook-preload-script.js and other files for cleaner code.

This description was created by Ellipsis for 3e274fc. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features

    • Added the ability to stop an in-progress chat response.
    • The chat UI now clearly reflects when a response has been stopped.
  • Bug Fixes

    • Waiting/loading state now updates correctly when a response is stopped, completed, or errors.
    • Prevented the chat from appearing “stuck” in a waiting state after stopping.

Copy link

vercel bot commented Aug 27, 2025

@Rish-it is attempting to deploy a commit to the Onlook Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Aug 27, 2025

Walkthrough

Adds an isStopped flag and custom stop function to the chat hook/provider, updates context to expose stop and isStopped, resets isStopped across finish/error/new-message paths, and updates waiting-state computation to respect isStopped so UI/streaming halts when stopped.

Changes

Cohort / File(s) Summary
Chat hook/provider updates
apps/web/client/src/app/project/[id]/_hooks/use-chat.tsx
Introduces isStopped state, exposes stop and isStopped via ChatContext, resets isStopped on finish/error/new send, and updates isWaiting to require not isStopped. Extends ExtendedUseChatHelpers to include isStopped.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as Chat UI
  participant Hook as use-chat (Provider)
  participant Chat as Underlying chat API

  User->>UI: Click "Send"
  UI->>Hook: sendMessage()
  Hook->>Hook: set isStopped = false
  Hook->>Chat: start stream
  Chat-->>Hook: status = streaming
  Hook-->>UI: context { status: streaming, isStopped: false }
  UI->>UI: isWaiting = true (streaming && !isStopped)

  User->>UI: Click "Stop"
  UI->>Hook: stop()
  Hook->>Hook: set isStopped = true
  Hook->>Chat: stop()
  Hook-->>UI: context { isStopped: true }
  UI->>UI: isWaiting = false (not waiting when stopped)
  Note over Hook,UI: onFinish/onError reset isStopped = false for next run
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Stop the response and streaming animation entirely when user presses Stop (#2761)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation

Poem

I thump my paw—“Stop!”—the stream grows still,
No more word-rain taps the window sill.
I nibble code like clover leaves,
Toggle flags beneath the eaves.
Now chats can pause on rabbit’s cue—
A hush, a wink, then hop anew. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
apps/web/client/src/app/project/[id]/_hooks/use-chat.tsx (3)

37-37: Consider stop-state reset timing to avoid UI flicker/regressions.

Resetting isStopped in onFinish can race with status updates. Prefer keeping it true on user-initiated stops and only clearing on the next send, or at least avoid clearing on finishReason === 'stop'.

Apply:

-            setIsStopped(false);
+            if (finishReason !== 'stop') {
+                setIsStopped(false);
+            }

(Optional) Keeping the onError reset is fine; you already clear it at the start of sendMessage().

Also applies to: 58-58, 73-73


91-95: Guard stop to only toggle when actively sending/streaming.

Prevents setting a “stopped” flag when nothing is in-flight, which can confuse waiting-state UIs.

Apply:

-    const customStop = () => {
-        setIsStopped(true);
-        chat.stop();
-    };
+    const customStop = () => {
+        if (chat.status === 'streaming' || chat.status === 'submitted') {
+            setIsStopped(true);
+            chat.stop();
+        }
+    };

13-16: Align sendMessage signature with implementation default

The sendMessage helper provides a default for its type parameter, but its current type definition requires callers to always pass an argument. While a search across the codebase did not surface any zero-arg invocations, updating the signature to make type optional will:

  • Accurately reflect the implementation’s behavior
  • Prevent future TypeScript errors if callers omit the argument
  • Maintain backward compatibility (no existing call sites rely on a required arg)

Please update in apps/web/client/src/app/project/[id]/_hooks/use-chat.tsx (around lines 13–16):

-type ExtendedUseChatHelpers = UseChatHelpers & { 
-    sendMessage: (type: ChatType) => Promise<string | null | undefined>;
-    isStopped: boolean;
-};
+type ExtendedUseChatHelpers = UseChatHelpers & { 
+    sendMessage: (type?: ChatType) => Promise<string | null | undefined>;
+    isStopped: boolean;
+};
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6e072e5 and 3e274fc.

📒 Files selected for processing (1)
  • apps/web/client/src/app/project/[id]/_hooks/use-chat.tsx (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/client/src/app/project/[id]/_hooks/use-chat.tsx (2)
apps/web/client/src/components/store/editor/chat/context.ts (1)
  • ChatContext (15-229)
apps/web/client/src/components/store/editor/index.tsx (1)
  • useEditorEngine (9-13)
🔇 Additional comments (4)
apps/web/client/src/app/project/[id]/_hooks/use-chat.tsx (4)

11-11: LGTM: React imports expanded appropriately.

useState addition is correct for the new stop state.


23-23: LGTM: Introduces explicit stop state.

State is well-scoped to the provider.


96-96: LGTM: Provider overrides stop and exposes isStopped.

Shape aligns with UseChatHelpers (stop) plus your extension.


102-102: Confirm all possible ChatStatus values in @ai-sdk/react and include any tool-call states in isWaiting.

Please double-check the list of statuses returned by useChat (e.g. by inspecting the ChatStatus type in your @ai-sdk/react install, such as node_modules/@ai-sdk/react/dist/index.d.ts) to see if there’s an intermediate “tool-call” or “awaiting-tool-calls” state. If so, update the guard in apps/web/client/src/app/project/[id]/_hooks/use-chat.tsx (around line 102) accordingly:

-    const isWaiting = (context.status === 'streaming' || context.status === 'submitted') && !context.isStopped;
+    const isWaiting =
+        (['streaming', 'submitted', /* add any tool-call statuses here, e.g. 'awaiting-tool-calls' */] as const)
+            .includes(context.status)
+        && !context.isStopped;

You can locate the full set of statuses with a quick grep, for example:

grep -R "export type ChatStatus" -n node_modules/@ai-sdk/react

@Kitenite Kitenite closed this Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Stop the response entirely when the user "stops"
2 participants