Migrate from React.forwardRef to React 19 ref patterns #102
+702
−1,370
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR migrates the entire codebase from the deprecated
React.forwardRef
pattern to React 19's native ref handling, ensuring compatibility with React 19 while maintaining full backward compatibility.Problem
React 19 has deprecated the usage of
forwardRef
, but components still need to handle and type refs correctly. The repository contained 109+ instances ofReact.forwardRef
across all primitive packages that needed to be updated to follow React 19's guidelines.Solution
Updated all components to use React 19's native ref pattern where components can accept
ref
as a regular prop:Before (React 18 pattern):
After (React 19 pattern):
Key Changes
React.forwardRef
across 32 primitive packagesuseAugmentedRef
with proper ref fallbacksPackages Updated
All primitive packages were updated including:
slot
,types
,hooks
,utils
switch
,checkbox
,label
,separator
,avatar
,collapsible
accordion
,alert-dialog
,context-menu
,dialog
,dropdown-menu
,hover-card
,menubar
,navigation-menu
,popover
,progress
,radio-group
,select
,slider
,table
,tabs
,toast
,toggle
,toggle-group
,toolbar
,tooltip
Testing
React.forwardRef
remain in the codebaseImpact
This migration brings the rn-primitives library fully up to date with React 19 best practices, removing deprecated patterns while maintaining complete compatibility. The codebase is now ready for React 19 production use with modern ref handling.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
telemetry.astro.build
node /home/REDACTED/work/rn-primitives/rn-primitives/node_modules/.bin/astro build
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
This pull request was created as a result of the following prompt from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.