Skip to content

fix: stabilise MenuPortal updateComputedPosition to prevent infinite re-render loop#6097

Open
9KenM wants to merge 2 commits intoJedWatson:masterfrom
9KenM:fix/menu-portal-infinite-rerender
Open

fix: stabilise MenuPortal updateComputedPosition to prevent infinite re-render loop#6097
9KenM wants to merge 2 commits intoJedWatson:masterfrom
9KenM:fix/menu-portal-infinite-rerender

Conversation

@9KenM
Copy link
Copy Markdown

@9KenM 9KenM commented Apr 20, 2026

Problem

updateComputedPosition closes over computedPosition and lists its
sub-properties (offset, rect.left, rect.width) as useCallback
dependencies. This means every call to setComputedPosition produces a
new callback identity, which invalidates the
useLayoutEffect([updateComputedPosition]) and immediately re-fires the
callback.

Under subpixel-drifting conditions (zoomed-out viewport, scrollable
ancestor, or fractional DPI) the measured offset oscillates by <1px
between frames. Each oscillation triggers setComputedPosition
identity change → effect re-run → repeat, until React throws:

Maximum update depth exceeded.

Fixes #6003.

Solution

Track computedPosition in a ref so the comparison inside
updateComputedPosition always reads the latest value without the
callback depending on it. This gives updateComputedPosition a stable
identity across renders and breaks the loop.

Reproduction

  1. Render a portaled <Select menuPosition="fixed" /> inside a scrollable container
  2. Set browser zoom to 90% or 110% (triggers subpixel rect drift)
  3. Open the dropdown and scroll the container
  4. Console shows: Maximum update depth exceeded

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 20, 2026

⚠️ No Changeset found

Latest commit: 4033960

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Apr 20, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

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.

Maximum update depth exceeded

1 participant