-
Notifications
You must be signed in to change notification settings - Fork 47k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reuse string ref if conceptually identical
Now that string refs are coerced to callback refs in the JSX runtime, a new callback ref is recreated each time. This is a subtle behavior difference from the old behavior, because it means React will reattach the ref on every render. While this is mostly not a huge issue, it is technically observable because a child component can observe a parent component's ref inside a layout effect or componentDidUpdate before the parent ref is able to update (because layout effects and refs run in child -> parent order). To preserve the old behavior, I added the string refs "deps" as extra properties on the callback. Then in the reconciler, we can compare the deps to check whether the old callback ref can be reused. This is similar to what we did before but in addition to checking the string itself, we also need to check the other and the type, since those are bound earlier than they were before.
- Loading branch information
Showing
3 changed files
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters