Skip to content

feat: implement Thread viewport with radix-ui scroll-area primitives #1566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

PieterT2000
Copy link
Contributor

@PieterT2000 PieterT2000 commented Feb 8, 2025

Addresses #1125


Important

Implement Thread viewport using Radix UI scroll-area primitives, adding new components and updating existing ones.

  • Components:
    • Implement ScrollArea and ScrollBar components in scroll-area.tsx using @radix-ui/react-scroll-area.
    • Update ThreadPrimitiveRoot in ThreadRoot.tsx to use ScrollAreaPrimitive.Root and include ScrollBar.
    • Update ThreadPrimitiveViewport in ThreadViewport.tsx to use ScrollAreaPrimitive.Viewport.
  • Dependencies:
    • Add @radix-ui/react-scroll-area version 1.2.1 to package.json in both apps/registry and packages/react.
  • Misc:
    • Remove Scrollbar.mdx documentation file.

This description was created by Ellipsis for 448efd6. It will automatically update as commits are pushed.

Copy link

vercel bot commented Feb 8, 2025

@PieterT2000 is attempting to deploy a commit to the assistant-ui Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

LGTM 👍

Copy link
Contributor

promptless bot commented Feb 8, 2025

📝 Documentation updates detected! You can review documentation updates here

                        Promptless's comment below: 

The PR implements a significant change to the Thread component's scrollbar functionality, making it a built-in feature using Radix UI's scroll-area primitives. I've made the following documentation updates:

  1. Updated the Thread.mdx documentation to reflect that the Root component now uses Radix UI's ScrollArea.Root by default
  2. Updated the Viewport component documentation to indicate it uses ScrollArea.Viewport
  3. Added information about the built-in custom scrollbar functionality
  4. Fixed a typo in "Contains" (was "Containts")

The old Scrollbar.mdx documentation file has been removed as part of the PR since the functionality is now built into the core components. No additional documentation updates are needed since the feature is now handled automatically by the Thread component.

Let me summarize the changes for the user.

I've updated the documentation to reflect the new built-in scrollbar functionality in the Thread component. The main changes are:

  1. Updated the Thread primitive documentation to show that it now includes built-in custom scrollbar functionality using Radix UI's scroll-area primitives.
  2. Removed the separate Scrollbar.mdx documentation since this functionality is now built into the core Thread component.
  3. Updated the component descriptions to reflect that Root and Viewport components now use Radix UI's ScrollArea components by default.

These changes align with the PR's implementation of Thread viewport with Radix UI scroll-area primitives, making the custom scrollbar functionality a built-in feature rather than requiring manual setup.

Copy link
Contributor

coderabbitai bot commented Feb 8, 2025

Walkthrough

The pull request removes the documentation file for implementing a custom scrollbar and introduces new scroll area components. A new file is added that defines ScrollArea and ScrollBar components using primitives from the @radix-ui/react-scroll-area library. The ThreadRoot and ThreadViewport components are updated to replace previous div implementations with these scroll area primitives, with corresponding updates to type definitions. In addition, a new ScrollBar component is added to another part of the codebase to manage scrollbar styling and functionality. The dependency on @radix-ui/react-scroll-area is updated in multiple package.json files to version 1.2.1, and the registry of components now includes an entry for "scroll-area". No changes were made to declarations of exported or public entities apart from the necessary updates to component references and type definitions.

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

apps/registry/components/ui/scroll-area.tsx

Oops! Something went wrong! :(

ESLint: 9.20.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

packages/react/src/primitives/thread/ThreadViewport.tsx

Oops! Something went wrong! :(

ESLint: 9.20.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

apps/registry/src/registry.ts

Oops! Something went wrong! :(

ESLint: 9.20.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.

  • 2 others
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

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

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.

Copy link
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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a9e96d0 and 448efd6.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • apps/docs/content/docs/ui/shadcn-ui/Scrollbar.mdx (0 hunks)
  • apps/registry/components/ui/scroll-area.tsx (1 hunks)
  • apps/registry/package.json (1 hunks)
  • apps/registry/src/registry.ts (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/react/src/primitives/thread/ThreadRoot.tsx (1 hunks)
  • packages/react/src/primitives/thread/ThreadViewport.tsx (1 hunks)
  • packages/react/src/ui/base/scroll-area.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/docs/content/docs/ui/shadcn-ui/Scrollbar.mdx
🔇 Additional comments (9)
packages/react/src/primitives/thread/ThreadRoot.tsx (3)

1-4: LGTM! Clean import statements.

The imports are well-organized and include all necessary dependencies for the ScrollArea implementation.


7-8: LGTM! Type definitions are properly updated.

The Element and Props types are correctly updated to use ScrollAreaPrimitive.Root.


14-24: LGTM! Clean implementation of ScrollArea.

The implementation correctly:

  • Uses ScrollAreaPrimitive.Root
  • Handles className merging
  • Includes ScrollBar component
packages/react/src/ui/base/scroll-area.tsx (1)

7-26: LGTM! Well-structured ScrollBar component.

The component is well-implemented with:

  • Proper type definitions
  • Correct ref forwarding
  • Default vertical orientation
packages/react/src/primitives/thread/ThreadViewport.tsx (2)

10-15: LGTM! Type definitions are properly updated.

The Element and Props types are correctly updated to use ScrollAreaPrimitive.Viewport while preserving the autoScroll property.


28-34: LGTM! Clean implementation of Viewport.

The implementation correctly:

  • Uses ScrollAreaPrimitive.Viewport
  • Preserves autoScroll functionality
  • Handles className merging
apps/registry/components/ui/scroll-area.tsx (1)

8-25: LGTM! Well-structured ScrollArea component.

The ScrollArea component is well-implemented with:

  • Proper type definitions
  • Correct ref forwarding
  • Appropriate default styling
apps/registry/src/registry.ts (1)

17-17: LGTM! Dependency registration is correct.

The addition of "scroll-area" to the thread component's registry dependencies aligns with the PR objective of implementing the Thread viewport using Radix UI scroll-area primitives.

apps/registry/package.json (1)

18-18: 🌐 Web query:

What is the latest version of @radix-ui/react-scroll-area?

💡 Result:

The latest version of `@radix-ui/react-scroll-area` is **1.2.3**, published on February 5, 2025[1][9]. This information comes directly from both its npm registry listing and Radix UI's official documentation[9], which also provides installation instructions:

```bash
npm install @radix-ui/react-scroll-area
# or
yarn add @radix-ui/react-scroll-area
```

The package has been actively maintained with recent updates, including release candidates for previous versions like 1.2.0-rc.x[7][8]. The current stable release (1.2.3) includes native scroll behavior preservation while enabling custom styling of scrollbars[9].

Citations:

- 1: https://www.npmjs.com/package/@radix-ui/react-scroll-area
- 2: https://jsr.io/@radix-ui-fork/react-scroll-area
- 3: https://github.com/radix-ui/themes/blob/main/packages/radix-ui-themes/src/components/scroll-area.tsx
- 4: https://github.com/radix-ui/primitives/blob/main/packages/react/scroll-area/src/ScrollArea.tsx
- 5: https://www.jsdelivr.com/package/npm/@radix-ui/react-scroll-area
- 6: https://ui.tailus.io/react/components/scroll-area/
- 7: https://www.assistant-ui.com/docs/ui/styled/Scrollbar
- 8: https://npm.io/package/@radix-ui/react-scroll-area
- 9: https://www.radix-ui.com/primitives/docs/components/scroll-area
- 10: https://www.npmjs.com/package/radix-ui/v/1.1.0?activeTab=dependencies

Comment on lines +10 to +25
>(({ className, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.ScrollAreaScrollbar
ref={ref}
orientation={orientation}
className={classNames(
"flex touch-none select-none transition-colors",
orientation === "vertical" &&
"h-full w-2.5 border-l border-l-transparent p-[1px]",
orientation === "horizontal" &&
"h-2.5 flex-col border-t border-t-transparent p-[1px]",
className,
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="bg-border relative flex-1 rounded-full" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider adding aria-label for accessibility.

The ScrollBar component could benefit from an accessibility enhancement.

 <ScrollAreaPrimitive.ScrollAreaScrollbar
   ref={ref}
   orientation={orientation}
+  aria-label={`${orientation} scrollbar`}
   className={classNames(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
>(({ className, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.ScrollAreaScrollbar
ref={ref}
orientation={orientation}
className={classNames(
"flex touch-none select-none transition-colors",
orientation === "vertical" &&
"h-full w-2.5 border-l border-l-transparent p-[1px]",
orientation === "horizontal" &&
"h-2.5 flex-col border-t border-t-transparent p-[1px]",
className,
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="bg-border relative flex-1 rounded-full" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
(({ className, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.ScrollAreaScrollbar
ref={ref}
orientation={orientation}
aria-label={`${orientation} scrollbar`}
className={classNames(
"flex touch-none select-none transition-colors",
orientation === "vertical" &&
"h-full w-2.5 border-l border-l-transparent p-[1px]",
orientation === "horizontal" &&
"h-2.5 flex-col border-t border-t-transparent p-[1px]",
className,
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="bg-border relative flex-1 rounded-full" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
))

Comment on lines 26 to 46
const ScrollBar = React.forwardRef<
React.ComponentRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
>(({ className, orientation = "vertical", ...props }, ref) => (
<ScrollAreaPrimitive.ScrollAreaScrollbar
ref={ref}
orientation={orientation}
className={cn(
"flex touch-none select-none transition-colors",
orientation === "vertical" &&
"h-full w-2.5 border-l border-l-transparent p-[1px]",
orientation === "horizontal" &&
"h-2.5 flex-col border-t border-t-transparent p-[1px]",
className,
)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="bg-border relative flex-1 rounded-full" />
</ScrollAreaPrimitive.ScrollAreaScrollbar>
));
ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider consolidating duplicate ScrollBar implementations.

There appears to be a duplicate implementation of the ScrollBar component between this file and packages/react/src/ui/base/scroll-area.tsx. Consider consolidating these implementations to maintain consistency and reduce code duplication.

Consider moving the ScrollBar component to a shared location and importing it in both places.

@@ -76,6 +76,7 @@
"@radix-ui/react-dialog": "^1.1.6",
"@radix-ui/react-popover": "^1.1.6",
"@radix-ui/react-primitive": "^2.0.2",
"@radix-ui/react-scroll-area": "^1.2.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider aligning version constraints across packages.

The dependency is using a caret range (^1.2.1) while the registry package uses a pinned version (1.2.1). Consider using consistent version constraints across packages to prevent potential version mismatches.

-    "@radix-ui/react-scroll-area": "^1.2.1",
+    "@radix-ui/react-scroll-area": "1.2.1",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"@radix-ui/react-scroll-area": "^1.2.1",
"@radix-ui/react-scroll-area": "1.2.1",

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR implements Radix UI scroll area primitives to enhance the Thread viewport's scrolling functionality, addressing auto-scrolling issues from issue #1125.

  • Added @radix-ui/react-scroll-area v1.2.1 in both packages/react and apps/registry for consistent scrolling behavior
  • Replaced basic Primitive.div with ScrollAreaPrimitive.Viewport in ThreadViewport.tsx to improve scrolling functionality
  • Added new scroll-area.tsx components in both packages and registry for custom scrollbar implementation
  • Concerning deletion of Scrollbar.mdx documentation without replacement, potentially impacting developer guidance
  • Modified registry.ts to include scroll-area as a dependency for the thread component

💡 (3/5) Reply to the bot's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

8 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

)}
{...props}
>
<ScrollAreaPrimitive.ScrollAreaThumb className="bg-border relative flex-1 rounded-full" />
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider adding aria-label to ScrollAreaThumb for better accessibility

Comment on lines +21 to +22
{children}
<ScrollBar />
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: ScrollBar should be placed after Viewport component, not directly after children. This will cause layout issues.

Suggested change
{children}
<ScrollBar />
<ScrollAreaPrimitive.Viewport>
{children}
</ScrollAreaPrimitive.Viewport>
<ScrollBar />

Copy link

trag-bot bot commented Feb 8, 2025

@trag-bot didn't find any issues in the code! ✅✨

Copy link

trag-bot bot commented Feb 8, 2025

Pull request summary

  • Added documentation for integrating a custom scrollbar using @radix-ui/react-scroll-area.
  • Updated the registry to include the new scroll-area dependency.
  • Specified the @radix-ui/react-scroll-area version in the package.json file.
  • Modified ThreadPrimitiveRoot to use ScrollAreaPrimitive.Root instead of a primitive div.
  • Updated ThreadPrimitiveViewport to utilize ScrollAreaPrimitive.Viewport for better scroll handling.
  • Created a new ScrollBar component that wraps ScrollAreaPrimitive.ScrollAreaScrollbar.
  • Adjusted CSS styles for the custom scrollbar to ensure proper layout and appearance.
  • Updated the lock file to reflect the new dependencies and versions.
  • Ensured compatibility with existing components by maintaining the structure of Thread.Root and Thread.Viewport.
  • Enhanced the overall integration of the scrollbar component within the existing UI framework.

@Yonom
Copy link
Member

Yonom commented Feb 9, 2025

Thank you so much, this is an amazing contribution - I need to do some testing on this before releasing it - will get back to you around Monday!

@PieterT2000
Copy link
Contributor Author

Thanks! By the way, there don't seem to be any unit/integration tests yet. Is that a decision due to the library's rapidly evolving nature, or is it still being considered? The library is still <1.0.0, so users should expect things to break, but I would be happy to contribute in that area anyway.

@maxcodefaster
Copy link

maxcodefaster commented Mar 25, 2025

@Yonom any updates on when this will be merged? Or is this already implemented with this: https://www.assistant-ui.com/docs/ui/Scrollbar

@AVGVSTVS96
Copy link
Collaborator

@PieterT2000 sorry for the delay! we are looking to merge this soon, can you update and resolve conflicts? thanks for your contribution!

@PieterT2000
Copy link
Contributor Author

Sure, no problem!

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.

4 participants