Skip to content

fix: make playground scroll not scroll down when not needed#8676

Merged
lucaseduoli merged 2 commits into
mainfrom
fix/playground_scroll
Jun 23, 2025
Merged

fix: make playground scroll not scroll down when not needed#8676
lucaseduoli merged 2 commits into
mainfrom
fix/playground_scroll

Conversation

@lucaseduoli
Copy link
Copy Markdown
Collaborator

@lucaseduoli lucaseduoli commented Jun 23, 2025

This pull request refines the scrolling behavior in the chat view component to improve user experience, particularly around smooth and instant scrolling transitions. It adjusts the logic for determining when to scroll and modifies how scrolling behavior is managed.

Improvements to scrolling behavior:

  • Refined scroll behavior logic in ChatScrollAnchor: Simplified the condition for using playgroundScrollBehaves in the scrollIntoView method and added logic to switch between "smooth" and "instant" scrolling dynamically, ensuring smoother transitions when necessary. (src/frontend/src/modals/IOModal/components/chatView/components/chat-scroll-anchor.tsx, [1] [2]

  • Adjusted bottom scroll detection in ChatView: Increased the threshold for detecting if the user is at the bottom of the chat from 3 to 30 pixels, which provides a more forgiving margin for triggering auto-scroll behavior. (src/frontend/src/modals/IOModal/components/chatView/components/chat-view.tsx, src/frontend/src/modals/IOModal/components/chatView/components/chat-view.tsxL194-R211)

  • Initialized smooth scrolling on chat history load: Added a useEffect hook to set the default scrolling behavior to "smooth" when the chat history changes, ensuring a consistent initial experience. (src/frontend/src/modals/IOModal/components/chatView/components/chat-view.tsx, src/frontend/src/modals/IOModal/components/chatView/components/chat-view.tsxL194-R211)

Summary by CodeRabbit

  • Improvements
    • Enhanced chat scrolling behavior for smoother and more intuitive navigation, especially when new messages are added or errors occur.
    • Increased the scroll threshold for detecting when the user is at the bottom of the chat, reducing accidental triggers.
    • Improved handling of scroll behavior transitions for a more seamless chat experience.

@lucaseduoli lucaseduoli self-assigned this Jun 23, 2025
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 23, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 23, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes adjust the scroll behavior logic in the chat view and anchor components. The scroll detection threshold is increased, and the logic for toggling scroll behavior between "smooth" and "instant" is refined. Additionally, scroll behavior is now set to "smooth" when chat history updates, and effect dependencies are updated for more precise control.

Changes

File(s) Change Summary
src/frontend/src/modals/IOModal/components/chatView/components/chat-scroll-anchor.tsx Simplified and restructured scroll behavior logic in useEffect, modified delayed scroll triggers, and updated effect dependencies.
src/frontend/src/modals/IOModal/components/chatView/components/chat-view.tsx Increased scroll detection threshold, refined canScroll condition, introduced setPlaygroundScrollBehaves on chat updates.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatView
    participant ChatScrollAnchor
    participant Store

    User->>ChatView: Scrolls or new message arrives
    ChatView->>Store: setPlaygroundScrollBehaves("smooth") (on chat history update)
    ChatView->>ChatScrollAnchor: Updates trackVisibility
    ChatScrollAnchor->>ChatScrollAnchor: useEffect triggers on trackVisibility
    alt trackVisibility.category == "error"
        ChatScrollAnchor->>ChatScrollAnchor: Scroll with playgroundScrollBehaves
        ChatScrollAnchor->>ChatScrollAnchor: Delayed smooth scroll after 400ms
    else non-error category
        ChatScrollAnchor->>ChatScrollAnchor: Scroll with playgroundScrollBehaves
        alt playgroundScrollBehaves == "smooth"
            ChatScrollAnchor->>Store: setPlaygroundScrollBehaves("instant")
            ChatScrollAnchor->>ChatScrollAnchor: Delayed instant scroll after 200ms
        end
    end
Loading
✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch fix/playground_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
🪧 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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.

Documentation and Community

  • 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.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jun 23, 2025
Copy link
Copy Markdown
Contributor

@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: 1

🔭 Outside diff range comments (1)
src/frontend/src/modals/IOModal/components/chatView/components/chat-scroll-anchor.tsx (1)

27-50: Clarify the scroll behavior toggle logic.

The new toggle mechanism for non-error categories appears to have redundant logic:

  1. It scrolls with the current playgroundScrollBehaves value
  2. If that value is "smooth", it immediately switches to "instant"
  3. Then after 200ms, it scrolls again with "instant" behavior

This creates two scroll calls and the second one seems unnecessary since the behavior is already set to "instant". Consider simplifying this logic or clarifying the intended behavior.

        scrollRef.current.scrollIntoView({
          behavior: playgroundScrollBehaves,
        });
-        if (playgroundScrollBehaves === "smooth") {
-          setPlaygroundScrollBehaves("instant");
-          setTimeout(() => {
-            if (!scrollRef.current) return;
-            scrollRef.current.scrollIntoView({
-              behavior: "instant",
-            });
-          }, 200);
-        }
+        if (playgroundScrollBehaves === "smooth") {
+          setPlaygroundScrollBehaves("instant");
+        }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 068db12 and 09803f4.

📒 Files selected for processing (2)
  • src/frontend/src/modals/IOModal/components/chatView/components/chat-scroll-anchor.tsx (2 hunks)
  • src/frontend/src/modals/IOModal/components/chatView/components/chat-view.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`src/frontend/**/*.{ts,tsx,js,jsx}`: All React and TypeScript/JavaScript source files for the frontend must reside under src/frontend/ and use .ts, .tsx, .js, or .jsx extensions.

src/frontend/**/*.{ts,tsx,js,jsx}: All React and TypeScript/JavaScript source files for the frontend must reside under src/frontend/ and use .ts, .tsx, .js, or .jsx extensions.

  • src/frontend/src/modals/IOModal/components/chatView/components/chat-view.tsx
  • src/frontend/src/modals/IOModal/components/chatView/components/chat-scroll-anchor.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: autofix
🔇 Additional comments (4)
src/frontend/src/modals/IOModal/components/chatView/components/chat-view.tsx (4)

194-194: Good improvement to scroll detection threshold.

Increasing the bottom detection threshold from 3 to 30 pixels provides a more forgiving trigger for auto-scroll behavior, reducing unwanted scroll interruptions due to minor pixel variations.


206-208: Correct addition of scroll behavior state management.

The setPlaygroundScrollBehaves setter is properly imported and will be used to coordinate scroll behavior between components.


210-213: Good initialization of smooth scrolling behavior.

Setting the scroll behavior to "smooth" and enabling scrolling when chat history changes ensures a consistent and pleasant initial scrolling experience, aligning well with the PR objectives.


200-200: To fully understand the impact of this change, let’s pull in the surrounding scroll handler and auto-scroll effect:

#!/bin/bash
echo "=== chat-view.tsx (lines 1–150) ==="
sed -n '1,150p' src/frontend/src/modals/IOModal/components/chatView/components/chat-view.tsx

echo "=== chat-view.tsx (lines 140–260) ==="
sed -n '140,260p' src/frontend/src/modals/IOModal/components/chatView/components/chat-view.tsx

echo "=== Auto-scroll useEffect (chatHistory) ==="
rg -C5 "chatHistory" src/frontend/src/modals/IOModal/components/chatView/components/chat-view.tsx

}
}
}, [canScroll, trackVisibility]);
}, [trackVisibility]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix stale closure issue with canScroll dependency.

The useEffect uses canScroll in its condition but canScroll is not included in the dependency array. This creates a stale closure where the effect may use outdated values of canScroll, potentially breaking the scroll functionality.

-  }, [trackVisibility]);
+  }, [trackVisibility, canScroll]);

Or alternatively, if the intent is to only trigger on trackVisibility changes, consider restructuring the logic to not depend on canScroll within the effect.

🤖 Prompt for AI Agents
In
src/frontend/src/modals/IOModal/components/chatView/components/chat-scroll-anchor.tsx
at line 52, the useEffect hook uses the variable canScroll inside its logic but
does not include canScroll in the dependency array, causing a stale closure
issue. To fix this, add canScroll to the dependency array so the effect re-runs
whenever canScroll changes, ensuring it uses the latest value. Alternatively, if
the effect should only depend on trackVisibility, refactor the effect logic to
avoid using canScroll inside it.

Copy link
Copy Markdown
Collaborator

@mfortman11 mfortman11 left a comment

Choose a reason for hiding this comment

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

Good fix

@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Jun 23, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jun 23, 2025
@lucaseduoli lucaseduoli added this pull request to the merge queue Jun 23, 2025
Merged via the queue into main with commit eeb7f24 Jun 23, 2025
53 checks passed
@lucaseduoli lucaseduoli deleted the fix/playground_scroll branch June 23, 2025 18:40
ogabrielluiz pushed a commit to bkatya2001/langflow that referenced this pull request Jun 24, 2025
…-ai#8676)

Fixed playground scroll

Co-authored-by: Carlos Coelho <80289056+carlosrcoelho@users.noreply.github.com>
Khurdhula-Harshavardhan pushed a commit to JigsawStack/langflow that referenced this pull request Jul 1, 2025
…-ai#8676)

Fixed playground scroll

Co-authored-by: Carlos Coelho <80289056+carlosrcoelho@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants