fix(popover): prevent setState-during-commit crash in React 19 - #23144
Open
snicolas-ibm wants to merge 1 commit into
Open
fix(popover): prevent setState-during-commit crash in React 19#23144snicolas-ibm wants to merge 1 commit into
snicolas-ibm wants to merge 1 commit into
Conversation
✅ Deploy Preview for v12-carbon-react ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v12-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v11-carbon-react ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for v11-carbon-web-components ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for carbon-elements ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
React 19 calls ref callbacks synchronously during the commit phase. The
setFloatingvalue provided viaPopoverContextis auseStatesetterbacked by
@floating-ui/react. Passing it directly intouseMergedRefs()as a DOM ref callback causes
setStateduring commit, exceeding React 19'snested update limit and crashing with "Maximum update depth exceeded".
The fix introduces a
setFloatingSaferef callback inPopoverContentthatcaptures the DOM node in a plain ref, then forwards it to
setFloatinginsidea
useEffect(which runs after commit, safely outside the synchronous commitphase). A
typeof setFloating === 'function'guard is also added because thecontext default value is a plain ref object (
{ current: null }), not afunction setter.
Note: the long-term fix belongs in
@floating-ui/react— the root cause isthat
useFloating()backs its ref callbacks withuseStatesetters. TheseCarbon patches are the pragmatic workaround while floating-ui resolves this.
See also: https://github.com/floating-ui/floating-ui/issues
Changelog
Fixed
PopoverContentwhen
@floating-ui/react'ssetFloatingsetter was used directly as a DOMref callback via
useMergedRefs.Testing / Reviewing
Popover,Tooltip, orToggletip—previously they crashed on mount with "Maximum update depth exceeded";
they should now render correctly
yarn jest --testPathPatterns "Popover|Tooltip|Toggletip"— all 120 tests pass
PR Checklist
As the author of this PR, before marking ready for review, confirm you:
Updated documentation and storybook examples— no public API or visual changeFollowed the required v12 migration documentation— runtime compatibility patch, no consumer migration burden