Replace forwarded ref instances of useProvidedRefOrCreate with useMergedRefs#7644
Replace forwarded ref instances of useProvidedRefOrCreate with useMergedRefs#7644iansan5653 wants to merge 34 commits intomainfrom
useProvidedRefOrCreate with useMergedRefs#7644Conversation
|
|
422c4e4 to
006cc27
Compare
…se-provided-ref-or-create
|
🤖 Lint issues have been automatically fixed and committed to this PR. |
This reverts commit 08b8cfe.
…om/primer/react into replace-use-provided-ref-or-create
This reverts commit d01c755.
|
😞 This is the most frustrating PR ever. I have no idea why the integration CI is failing, and the only way I can try things is by changing files in this PR, then waiting for the canary release, then rerunning the integration CI. So I'm going to have to revert each individual file one by one until I figure out which change is causing the failure. Very painful.
|
This reverts commit 0118db0.
This reverts commit 07eeee3.
|
|
A successful canary CI run (i.e., a valid canary version published via the Note: Make sure the Canary Release label is applied to the PR — the Next steps:
For more details, see this workflow run. |
In #7638 I created a
useMergedRefshook and migrated all instances ofuseRefObjectAsForwardedRefto it.A similar pattern is using
useProvidedRefOrCreatefor this. It's typically used with a type cast and ats-expect-errorcomment (❗):This is obviously problematic. The type errors are trying to point out the problem with this pattern: it will break if consumers pass ref callbacks. Ref callbacks are likely to become more and more common as React 19 has introduced ref callback cleanup functions, making ref callbacks a viable alternative to effects.
A much better pattern is to be consistent and use the same approach as in #7638:
Note, however, that I did not deprecate
useProvidedRefOrCreateor remove all calls to it. There are still some valid use cases where refs can be passed in to refer to elements rendered outside the component. We most often see this in anchor refs. There are also some utility hooks that can create a ref internally or use a passed ref. These two cases are still valid; the case I'm targeting here is specifically around forwarded refs.useMergedRefsto be React 19 compatible and public + deprecateuseRefObjectAsForwardedRefanduseProvidedRefOrCreate#7672Changelog
New
Changed
Removed
Rollout strategy
Testing & Reviewing
Merge checklist