Skip to content

fix(popover): prevent setState-during-commit crash in React 19 - #23144

Open
snicolas-ibm wants to merge 1 commit into
carbon-design-system:mainfrom
snicolas-ibm:fix/react-19-popover-setfloating-ref
Open

fix(popover): prevent setState-during-commit crash in React 19#23144
snicolas-ibm wants to merge 1 commit into
carbon-design-system:mainfrom
snicolas-ibm:fix/react-19-popover-setfloating-ref

Conversation

@snicolas-ibm

Copy link
Copy Markdown

React 19 calls ref callbacks synchronously during the commit phase. The
setFloating value provided via PopoverContext is a useState setter
backed by @floating-ui/react. Passing it directly into useMergedRefs()
as a DOM ref callback causes setState during commit, exceeding React 19's
nested update limit and crashing with "Maximum update depth exceeded".

The fix introduces a setFloatingSafe ref callback in PopoverContent that
captures the DOM node in a plain ref, then forwards it to setFloating inside
a useEffect (which runs after commit, safely outside the synchronous commit
phase). A typeof setFloating === 'function' guard is also added because the
context default value is a plain ref object ({ current: null }), not a
function setter.

Note: the long-term fix belongs in @floating-ui/react — the root cause is
that useFloating() backs its ref callbacks with useState setters. These
Carbon patches are the pragmatic workaround while floating-ui resolves this.
See also: https://github.com/floating-ui/floating-ui/issues

Changelog

Fixed

  • Fixed a "Maximum update depth exceeded" crash in React 19 in PopoverContent
    when @floating-ui/react's setFloating setter was used directly as a DOM
    ref callback via useMergedRefs.

Testing / Reviewing

  1. Upgrade your app to React 19
  2. Render any component that uses Popover, Tooltip, or Toggletip
    previously they crashed on mount with "Maximum update depth exceeded";
    they should now render correctly
  3. Run the test suite:
    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:

  • Reviewed every line of the diff
  • Updated documentation and storybook examples — no public API or visual change
  • Followed the required v12 migration documentation — runtime compatibility patch, no consumer migration burden
  • Wrote passing tests that cover this change — existing 120 tests all pass; no new test added as the fix is not observable by synchronous assertions
  • Addressed any impact on accessibility (a11y) — no change
  • Tested for cross-browser consistency — no change
  • Validated that this code is ready for review and status checks should pass

@snicolas-ibm
snicolas-ibm requested a review from a team as a code owner August 27, 2026 07:50
@netlify

netlify Bot commented Aug 27, 2026

Copy link
Copy Markdown

Deploy Preview for v12-carbon-react ready!

Name Link
🔨 Latest commit a6ca8f9
🔍 Latest deploy log https://app.netlify.com/projects/v12-carbon-react/deploys/6a8fec5d04465d0008122f4a
😎 Deploy Preview https://deploy-preview-23144--v12-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 27, 2026

Copy link
Copy Markdown

Deploy Preview for v12-carbon-web-components ready!

Name Link
🔨 Latest commit a6ca8f9
🔍 Latest deploy log https://app.netlify.com/projects/v12-carbon-web-components/deploys/6a8fec5d24f1460008eda968
😎 Deploy Preview https://deploy-preview-23144--v12-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 27, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a6ca8f9
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/6a8fec5d038a6600080094ef
😎 Deploy Preview https://deploy-preview-23144--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 27, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit a6ca8f9
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/6a8fec5d1864a500089977c8
😎 Deploy Preview https://deploy-preview-23144--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 27, 2026

Copy link
Copy Markdown

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit a6ca8f9
🔍 Latest deploy log https://app.netlify.com/projects/carbon-elements/deploys/6a8fec5db3f4d20008bc429a
😎 Deploy Preview https://deploy-preview-23144--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant