fix(react): stabilize composed ref identities to end React 19 render loop (#3963)#3967
Merged
chaance merged 1 commit intoJun 15, 2026
Merged
Conversation
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Follows up on #3899, which stabilized Slot's composed ref to fix the React 19 infinite re-render loop. The same unstable-identity pattern still exists in several other packages' own code, and under React 19's ref-cleanup semantics each reproduces the same
Maximum update depth exceededcrash.useComposedRefsisReact.useCallback(composeRefs(...refs), refs). When a member ofrefsis an inline arrow (or the composition is a barecomposeRefs(...)in render), the composed callback gets a new identity every render. React 19 detaches/re-attaches the ref on every commit; any composed state-setter ref togglesnull -> nodeeach cycle, scheduling another render — an infinite loop.Changes
Same principle as #3899 — give the composed refs a stable identity:
useComposedRefs(forwardedRef, setX)), matching existing usage likeselect.tsxonTriggerChange:react-dismissable-layer:DismissableLayer→setNodereact-focus-scope:FocusScope→setContainerreact-popper:PopperContent→setContentreact-scroll-area:ScrollArea→setScrollArea,Scrollbar→setScrollbar,Thumb→scrollbarContext.onThumbChange(already stabilized viauseCallbackRef)react-select:SelectContentImpl/SelectItemAlignedPosition→setContent,SelectItemText→setItemTextNodecomposeRefs(...)intouseComposedRefsabove the JSX:react-dropdown-menu:DropdownMenuTriggerreact-menu:MenuSubTrigger(composed directly with theonTriggerChangestate setter)useCallbackRefbefore composing (they take extra args, so can't be passed directly):react-select:SelectItem(value,disabled) andSelectItemText(value,disabled)Notes
react-dismissable-layeris emphasized in [React 19] Unstable composed-ref identities in several primitives still cause "Maximum update depth exceeded" after the Slot fix (#3899) #3963 as the residual loop driver, since it wraps every menu/popover/dialog content stack.Closes #3963.