Skip to content

[popover][combobox] Use reactive domReferenceElement subscriptions - #4017

Merged
atomiks merged 1 commit into
mui:masterfrom
atomiks:codex/reactive-dom-reference-subscriptions
Feb 10, 2026
Merged

atomiks merged 1 commit into
mui:masterfrom
atomiks:codex/reactive-dom-reference-subscriptions

Conversation

@atomiks

@atomiks atomiks commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

Ensures these variables can't be stale during a render.

@atomiks atomiks added type: bug It doesn't behave as expected. component: popover Changes related to the popover component. component: combobox Changes related to the combobox component. labels Feb 8, 2026
@pkg-pr-new

pkg-pr-new Bot commented Feb 8, 2026

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@4017
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@4017
    

commit: 7e52979

@greptile-apps

greptile-apps Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR updates ComboboxTrigger and PopoverPositioner to read domReferenceElement via the reactive store subscription API (floatingRootContext.useState('domReferenceElement')) instead of the non-reactive select(...). This ensures components re-render when the reference element changes and prevents comparing against stale values during render/effects.

No must-fix issues found in the changeset: in PopoverPositioner, removing optional chaining is safe because floatingRootContext is always present (initialized to an empty FloatingRootStore in the popover store state).

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • The change is a small, targeted refactor to use the reactive store subscription (useState) for domReferenceElement, aligning with how other store keys are already consumed and preventing staleness. floatingRootContext is always initialized for popover, so removing optional chaining does not introduce a runtime error.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/combobox/trigger/ComboboxTrigger.tsx Switched domReferenceElement access from non-reactive select to reactive useState on floatingRootContext so effects compare against the current reference during render.
packages/react/src/popover/positioner/PopoverPositioner.tsx Changed domReferenceElement read to floatingRootContext.useState(...) to keep it reactive; also removed optional chaining, which is safe given floatingRootContext is always initialized to an empty root context store.

@mui-bot

mui-bot commented Feb 8, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+3B(0.00%) ▼-5B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Feb 8, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 7e52979
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/698912a43aebc30008a6469b
😎 Deploy Preview https://deploy-preview-4017--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@michaldudak

Copy link
Copy Markdown
Member

Does this solve an existing bug? I generally managed to avoid having triggers reactive to the referenceElement as this causes re-rendering of all triggers when the active one changes. While this is not an issue with Combobox today, as it doesn't support detached triggers, it might be better to avoid it (in case we want to introduce them in the future).

@atomiks

atomiks commented Feb 10, 2026

Copy link
Copy Markdown
Contributor Author

For Combobox, it does look like a bug if the reference changes

Does this solve an existing bug? I generally managed to avoid having triggers reactive to the referenceElement as this causes re-rendering of all triggers when the active one changes.

For Popover, it seems like the select() calls belongs in the effect instead of render in this case?

@michaldudak

Copy link
Copy Markdown
Member

For Popover, this doesn't introduce any additional renders as it's already reactive to activeTriggerElement.
I think we can merge it, but it'll have to be refactored if we ever introduce detached triggers to Combobox.

@atomiks
atomiks merged commit cdd9a74 into mui:master Feb 10, 2026
10 checks passed
@atomiks
atomiks deleted the codex/reactive-dom-reference-subscriptions branch February 10, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: combobox Changes related to the combobox component. component: popover Changes related to the popover component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants