You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[popover][combobox] Use reactive domReferenceElement subscriptions - #4017
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.
Switched domReferenceElement access from non-reactive select to reactive useState on floatingRootContext so effects compare against the current reference during render.
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.
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).
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?
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.
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
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.
Ensures these variables can't be stale during a render.