Skip to content

Conversation

@saddlepaddle
Copy link
Collaborator

@saddlepaddle saddlepaddle commented Oct 22, 2025

  • First attempt at fixing chat scroll
  • Much better

Description

Related Issues

Type of Change

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

Testing

Screenshots (if applicable)

Additional Notes


Important

Improves chat scrolling by removing manual scroll handling and relying on UI components for automatic scrolling.

  • Behavior:
    • Removed onScrollToBottom prop and its usage in ChatInput.
    • Removed scrollToBottom method and ScrollController in ChatMessages.
    • Relied on ConversationScrollButton in ChatMessages for automatic scrolling.
  • Refactor:
    • Simplified ChatMessages by removing forwardRef and useImperativeHandle.
    • Adjusted ChatTabContent to remove chatMessagesRef and related logic.
  • Styling:
    • Minor CSS adjustments in ChatInput for button styling.

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

Summary by CodeRabbit

  • Refactor
    • Streamlined chat component architecture for improved maintainability
    • Removed automatic scroll-to-bottom behavior following message submission
    • Updated action button styling for enhanced visual presentation

@vercel
Copy link

vercel bot commented Oct 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
web Error Error Oct 22, 2025 8:34pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Oct 22, 2025 8:34pm

@supabase
Copy link

supabase bot commented Oct 22, 2025

This pull request has been ignored for the connected project wowaemfasoptxrdjhilu because there are no changes detected in apps/backend/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@vercel vercel bot temporarily deployed to Preview – docs October 22, 2025 20:32 Inactive
@coderabbitai
Copy link

coderabbitai bot commented Oct 22, 2025

Walkthrough

The chat tab components are refactored to eliminate imperative scroll-to-bottom behavior via refs and callbacks. ChatMessages transitions from a forwardRef component with a ChatMessagesHandle to a plain observer component using new Conversation rendering primitives. ChatInput and ChatTabContent APIs are updated to remove scroll-related props and ref handling.

Changes

Cohort / File(s) Summary
ChatInput prop interface updates
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx
ChatInputProps signature changed: added messages: ChatMessage[], removed onScrollToBottom: () => void; removed automatic scroll-to-bottom invocation after sending messages; restructured action button conditional styling
ChatMessages component refactoring
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/index.tsx
Changed from forwardRef<ChatMessagesHandle> to plain observer function; removed ChatMessagesHandle interface and ChatMessagesInner internal component; removed useImperativeHandle and useStickToBottomContext imports; replaced ScrollController with direct Conversation rendering structure
ChatTabContent ref-based logic removal
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-tab-content/index.tsx
Removed useRef hook and ChatMessagesHandle ref binding; removed onScrollToBottom prop passing to ChatMessages and ChatInput; eliminated scroll control wiring

Sequence Diagram

sequenceDiagram
    autonumber
    participant User
    participant ChatInput as ChatInput<br/>(Updated)
    participant ChatTabContent as ChatTabContent<br/>(Updated)
    participant ChatMessages as ChatMessages<br/>(Updated)
    participant Conversation as Conversation<br/>Components
    
    rect rgb(220, 240, 255)
        Note over ChatInput,Conversation: Before: Imperative Scroll Control
        User->>ChatInput: Type & send message
        ChatInput->>ChatInput: onScrollToBottom()
        ChatTabContent->>ChatMessages: handleScrollToBottom via ref
        ChatMessages->>ChatMessages: scrollToBottom()
    end
    
    rect rgb(240, 220, 255)
        Note over ChatInput,Conversation: After: Declarative Scroll Control
        User->>ChatInput: Type & send message
        ChatInput->>ChatTabContent: Update messages prop
        ChatTabContent->>ChatMessages: Pass messages & props
        ChatMessages->>Conversation: Render with<br/>ConversationScrollButton
        Conversation->>Conversation: Auto-scroll handled<br/>declaratively
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The changes span three related files with cohesive refactoring patterns (removal of imperative scroll mechanisms), but involve multiple API signature changes, interface deletions, and structural component changes that require verification of consistent propagation across the component tree.

Possibly related PRs

  • improve sse performance #2851: Directly related—replaces useChatContext with useChat hook and updates ChatInput/ChatMessages/ChatTabContent APIs by removing ref and onScrollToBottom patterns.
  • feat: use conversation list smooth #2881: Same code-level changes to chat messaging—replaces scroll primitives (ChatMessageList/useAutoScroll and ChatMessages forwardRef) with new Conversation components and removes imperative scroll-to-bottom handle.
  • fix: overridden chat input #2983: Modifies the same chat-input component and adjusts action button class composition/conditional styling.

Suggested reviewers

  • Kitenite

Poem

🐰 Scroll refs be gone, no more the imperative way!
Observer and Conversation bloom where handles held sway.
Declarative flows like carrots in rows—
ChatMessages springs free, as the chat gently grows! 🌱

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description contains only brief initial notes and leaves all of the template sections unfilled, missing a clear summary in the Description section, any related issue links, a marked type of change, testing steps, screenshots, and additional context. Please complete each section of the template by adding a concise description of the changes, linking related issues, selecting the appropriate type of change checkbox, describing how the changes were tested, and including any relevant screenshots or additional notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly captures the primary goal of the pull request by stating the fix to ensure the chat viewport scrolls to the bottom properly and directly references the main behavioral change without extraneous details.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-chat-scroll

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@saddlepaddle saddlepaddle merged commit 06bb72d into main Oct 22, 2025
5 of 7 checks passed
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-tab-content/index.tsx (1)

1-23: Add client boundary: this component uses hooks (useChat).

Without 'use client', this will break at runtime in Next.js app dir.

As per coding guidelines

+ 'use client';
+
 import { type ChatMessage } from '@onlook/models';
 import { useChat } from '../../../../_hooks/use-chat';
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx (1)

93-108: Enter handling calls handleEnterSelection() twice — can double-apply actions.

Call it once and branch on the result.

-        useEffect(() => {
-            const handleGlobalKeyDown = (e: KeyboardEvent) => {
-                if (e.key === 'Enter' && suggestionRef.current?.handleEnterSelection()) {
-                    e.preventDefault();
-                    e.stopPropagation();
-                    // Stop the event from bubbling to the canvas
-                    e.stopImmediatePropagation();
-                    // Handle the suggestion selection
-                    suggestionRef.current.handleEnterSelection();
-                }
-            };
+        useEffect(() => {
+            const handleGlobalKeyDown = (e: KeyboardEvent) => {
+                if (e.key === 'Enter') {
+                    const handled = suggestionRef.current?.handleEnterSelection?.();
+                    if (handled) {
+                        e.preventDefault();
+                        e.stopPropagation();
+                        e.stopImmediatePropagation();
+                    }
+                }
+            };
🧹 Nitpick comments (7)
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/index.tsx (3)

78-89: Great move to wrap with Conversation; localize “Thinking …”.

Replace hardcoded text per i18n guideline.

As per coding guidelines

-                {isStreaming && <div className="flex w-full h-full flex-row items-center gap-2 px-4 my-2 text-small content-start text-foreground-secondary">
-                    <Icons.LoadingSpinner className="animate-spin" />
-                    <p>Thinking ...</p>
-                </div>}
+                {isStreaming && (
+                    <div className="flex w-full h-full flex-row items-center gap-2 px-4 my-2 text-small content-start text-foreground-secondary">
+                        <Icons.LoadingSpinner className="animate-spin" />
+                        <p>{t(transKeys.editor.panels.edit.tabs.chat.thinking)}</p>
+                    </div>
+                )}

37-62: Avoid redundant keys on children.

Inner components already wrapped; remove keys on AssistantMessage/UserMessage.

-                    messageNode = <AssistantMessage key={message.id} message={message} isStreaming={isStreaming} />;
+                    messageNode = <AssistantMessage message={message} isStreaming={isStreaming} />;
...
-                        <UserMessage
-                            key={message.id}
+                        <UserMessage
                             onEditMessage={onEditMessage}
                             message={message}
                         />

79-83: Skip “system” messages to prevent empty rows.

Current renderMessage returns an empty wrapper for system; filter them out.

-                {messages.map((message) => renderMessage(message))}
+                {messages
+                    .filter((m) => m.role !== 'system')
+                    .map((message) => renderMessage(message))}
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-tab-content/index.tsx (1)

2-2: Prefer path alias instead of deep relative import.

Use @/ for src mapping to improve maintainability.

As per coding guidelines

-import { useChat } from '../../../../_hooks/use-chat';
+import { useChat } from '@/app/project/[id]/_hooks/use-chat';
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx (3)

163-169: Localize placeholder for ASK mode.

Avoid hardcoded user text; use next‑intl key.

As per coding guidelines

-            if (chatMode === ChatType.ASK) {
-                return 'Ask a question about your project...';
-            }
+            if (chatMode === ChatType.ASK) {
+                return t(transKeys.editor.panels.edit.tabs.chat.input.askPlaceholder);
+            }

462-465: Localize tooltip “Stop response”.

Replace with translation key.

As per coding guidelines

-                                <TooltipContent side="top" sideOffset={6} hideArrow>
-                                    {'Stop response'}
-                                </TooltipContent>
+                                <TooltipContent side="top" sideOffset={6} hideArrow>
+                                    {t(transKeys.editor.panels.edit.tabs.chat.actions.stopResponse)}
+                                </TooltipContent>

181-183: Audit remaining hardcoded user-visible strings.

These toasts/messages should use next‑intl.

As per coding guidelines

Examples to replace with t(transKeys...):

  • Line 181: "Pasted image"
  • Lines 213, 219: "Failed to get branch data", "Failed to load image file"
  • Lines 236-237: "Image added to chat"
  • Lines 299-300: "Added ${n} images to chat"
  • Lines 360-361: "Failed to capture screenshot. Error: ..."

Also applies to: 213-221, 236-237, 299-300, 360-361

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0e9f01 and f1d8881.

📒 Files selected for processing (3)
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx (4 hunks)
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/index.tsx (3 hunks)
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-tab-content/index.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
apps/web/client/src/app/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/app/**/*.tsx: Default to Server Components; add 'use client' when using events, state/effects, browser APIs, or client‑only libraries
Do not use process.env in client code; import env from @/env instead

Avoid hardcoded user-facing text; use next-intl messages/hooks

Files:

  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-tab-content/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx
apps/web/client/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/**/*.{ts,tsx}: Use path aliases @/* and ~/* for imports that map to apps/web/client/src/*
Avoid hardcoded user-facing text; use next-intl messages/hooks instead

Use path aliases @/* and ~/* for imports mapping to src/*

Files:

  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-tab-content/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx
apps/web/client/src/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/**/*.tsx: Create MobX store instances with useState(() => new Store()) for stable references across renders
Keep the active MobX store in a useRef and perform async cleanup with setTimeout(() => storeRef.current?.clear(), 0) to avoid route-change races
Avoid useMemo for creating MobX store instances
Avoid putting the MobX store instance in effect dependency arrays if it causes loops; split concerns by domain

apps/web/client/src/**/*.tsx: Create MobX store instances with useState(() => new Store()) for stable identities across renders
Keep the active MobX store in a useRef and clean up asynchronously with setTimeout(() => storeRef.current?.clear(), 0)
Do not use useMemo to create MobX stores
Avoid placing MobX store instances in effect dependency arrays if it causes loops; split concerns instead
observer components must be client components; place a single client boundary at the feature entry; child observers need not repeat 'use client'

Files:

  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-tab-content/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Do not use the any type unless necessary

Files:

  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-tab-content/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx
apps/web/client/src/app/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Default to Server Components; add 'use client' only when using events, state/effects, browser APIs, or client-only libs

Files:

  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-tab-content/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx
{apps,packages}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Avoid using the any type unless absolutely necessary

Files:

  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-tab-content/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/index.tsx
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-input/index.tsx
🧬 Code graph analysis (1)
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/index.tsx (1)
packages/ui/src/components/ai-elements/conversation.tsx (1)
  • Conversation (12-20)
🔇 Additional comments (1)
apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-messages/index.tsx (1)

28-33: No remaining ChatMessages scroll API references
Confirmed no occurrences of ChatMessagesHandle, onScrollToBottom, or ScrollController in the codebase.

@Kitenite Kitenite deleted the fix-chat-scroll branch October 28, 2025 21:22
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.

2 participants