Skip to content

Toggling a useState within a Popover to control a set of Collection items fails to update properly #10199

@uncvrd

Description

@uncvrd

Provide a general summary of the issue here

Hi again - I'm running in to an issue when trying to use SelectStateContext to determine if there is a value in order to show a "remove selection" option in the Select ListBox. But I cannot get my list to render an additional item based on a conditional from a component inside a popover, even if I add it as a dependency at every level of the collection. I've tried different cache busting approaches i promise. Maybe I'm missing something though

🤔 Expected Behavior?

I expect to be able to use const state = useContext(SelectStateContext); specifically the value prop from state to add a list item so that the user can "deselect" from the list

😯 Current Behavior

Currently even though the value of Boolean(state?.value) shows as true or false in the logs and the list of items re-render, the collection itself doesn't show the newly added item

💁 Possible Solution

I swear ive double and triple checked traditional caching issues ive run in to before (duplicate ids, not using dependency array) and i still cannot get it to work. I did some investigation and the TLDR i've come up with so far is:

State that lives inside a component rendered within Select's Popover seemingly can't control which items exist in the collection. Maybe it's because Select renders a hidden copy of its children to build the collection, so any useState inside that subtree is a separate instance from the one I interact with in the visible UI? As a result, toggling local state in the real tree doesn't affect the hidden tree's copy, so the collection never updates. The fix I've found is to lift any state that controls collection structure above the Select.

I also confirmed that if you remove the Virtualizer, it still is a problem.

Is this something that is necessary or worthy of tracking as a bug?

🔦 Context

I'm just trying to implement a select component that shows a deselect option if a value in the select is defined.

It's probably worth watching all 3 in a row first to understand what I'm finally trying to accomplish.

  1. Trying to use useContext (cannot get Clear selection to show after I select an item and reopen the Select) ❌
Screen.Recording.2026-06-13.at.2.09.37.AM.mov
  1. Trying to use local useState (cannot get Clear selection to show after I select an item and reopen the Select) ❌
Screen.Recording.2026-06-13.at.2.10.16.AM.mov
  1. Trying to use parent useState (allows the Clear selection to show) ✅
Screen.Recording.2026-06-13.at.2.14.35.AM.mov

🖥️ Steps to Reproduce

Stackblitz: https://stackblitz.com/edit/vrrrd46r?file=src%2FExample.tsx

useContext case (fails)

  1. Click the Select component, and note that no item is selected yet
  2. Select an Option, the popover closes
  3. Now if you open it again, you won't see the "Clear selection" option (but i want it to)

useState case (fails)

I tried forcing this by adding a toggleable useState boolean to see if it was a problem with the useContext (spoiler: it's not)

  1. Go to line 47-48 of Example.tsx and comment out const isClearable = isClearableFromSelectContext; and uncomment const isClearable = fakeClearable;
  2. Repeat steps 1-3 of useContext case above

What DOES work is if you hoist the useState into the parent of DebugListBox and pass fakeClearable as a prop of DebugListBox.

Version

1.18.0

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

MacOS

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions