-
-
Notifications
You must be signed in to change notification settings - Fork 13
refactor: complete migration to React 19 #116
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
Conversation
✅ Deploy Preview for eslint-code-explorer ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
"@types/node": "^18.19.44", | ||
"@types/react": "^18.3.3", | ||
"@types/react-dom": "^18.3.0", | ||
"@types/node": "^20", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR completes the migration to React 19 by replacing legacy APIs with the new function-based ref and context shorthands.
- Removed all
React.forwardRef
wrappers in favor of direct function components that acceptref
props. - Swapped
<Context.Provider>
usages for the new<Context>
shorthand. - Bumped Radix UI and TypeScript type versions in
package.json
to align with React 19.
Reviewed Changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/components/ui/toggle.tsx | Switched Toggle to a function component with direct ref prop |
src/components/ui/toggle-group.tsx | Updated ToggleGroup and its items to use the new ref and context shorthand |
src/components/ui/toast.tsx | Refactored Toast primitives to direct function components forwarding ref and props |
src/components/ui/text-field.tsx | Removed forwardRef , added React.RefAttributes to TextFieldProps |
src/components/ui/switch.tsx | Converted Switch to function component with direct ref prop |
src/components/ui/select.tsx | Updated Select primitives to new ref‐accepting functions |
src/components/ui/popover.tsx | Refactored PopoverContent to accept ref directly and use context shorthand |
src/components/ui/label.tsx | Switched Label to a function component with direct ref prop |
src/components/ui/dropdown-menu.tsx | Converted all DropdownMenu primitives from forwardRef to direct‐ref function components |
src/components/ui/dialog.tsx | Updated Dialog primitives to function components forwarding ref |
src/components/ui/button.tsx | Changed Button to a function component using ref prop instead of forwardRef |
src/components/ui/accordion.tsx | Refactored Accordion primitives to direct function components with ref prop |
src/components/theme-provider.tsx | Replaced <ThemeProviderContext.Provider> with <ThemeProviderContext> shorthand |
package.json | Bumped @radix-ui/react-toast , @types/node , @types/react , and @types/react-dom versions |
Comments suppressed due to low confidence (1)
src/components/theme-provider.tsx:50
- [nitpick] With the new React 19 context shorthand (
<Context>
instead of<Context.Provider>
), consider adding a comment or updating your README to clarify this syntax for future maintainers who may be unfamiliar with the pattern.
<ThemeProviderContext {...props} value={{ theme, setTheme }}>
const Toggle = ({ | ||
className, | ||
variant, | ||
size, | ||
ref, | ||
...props | ||
}: React.ComponentPropsWithRef<typeof TogglePrimitive.Root> & | ||
VariantProps<typeof toggleVariants>) => ( | ||
<TogglePrimitive.Root | ||
ref={ref} | ||
className={cn(toggleVariants({ variant, size, className }))} | ||
{...props} | ||
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This manual pattern of destructuring props and forwarding refs is repeated across many UI components; consider creating a higher-order component or factory utility to wrap primitives with consistent ref and className handling to reduce boilerplate and improve maintainability.
const Toggle = ({ | |
className, | |
variant, | |
size, | |
ref, | |
...props | |
}: React.ComponentPropsWithRef<typeof TogglePrimitive.Root> & | |
VariantProps<typeof toggleVariants>) => ( | |
<TogglePrimitive.Root | |
ref={ref} | |
className={cn(toggleVariants({ variant, size, className }))} | |
{...props} | |
/> | |
const Toggle = withClassNameAndRef( | |
TogglePrimitive.Root, | |
toggleVariants |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea I felt the same too. At lot of places I was able to see manually de structuring ref and then passing it again as ref={ref}
although we were spreading rest of the props. This is a nitpick anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.
But, If it's alright, could I handle this refactor in a separate PR? I feel like including it here would make the scope a bit too broad 😅.
ping @harish-sethuraman |
Hi, @eslint/eslint-team If anyone has some time, would you mind taking a look at this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know enough about React to really evaluate the code, but I tested out the app and everything works as it should. So, let's merge this and see what happens.
Prerequisites checklist
What is the purpose of this pull request?
What changes did you make? (Give an overview)
Hello,
In this PR, I've completed migration to React 19.
Starting with React 19,
Context.Provider
,forwardRef
, and several other APIs have been deprecated in favor of a simpler API design.While using legacy APIs don't currently throw an error, these APIs will be removed in the future, which could block us from upgrading to the latest version of React.
Here's a reference for it:
https://react.dev/blog/2024/12/05/react-19#improvements-in-react-19
I've made two notable changes in this PR:
First, I removed
forwardRef
and switched to passing refs directly as props.Second, I updated
<Context.Provider>
to use just<Context>
.Related Issues
Ref: eslint/eslint.org#740
Is there anything you'd like reviewers to focus on?