Skip to content

false change item id exception  #5176

Open
@rolanday

Description

@rolanday

Provide a general summary of the issue here

When rendering / not rendering item in collection based on state flag, rac throws an exception claiming item id changed. Code is slight variant on the rac menu sample:

      <MenuTrigger>
        <Button aria-label="Menu">☰</Button>
        <Popover>
          <Menu onAction={() => setUser((p) => !p)}>
            {user ? (
              <Section>
                <Item id="account">Account</Item>
                <Item id="signout">Sign out</Item>
              </Section>
            ) : (
              <Section>
                <Item id="signin">Sign in</Item>
              </Section>
            )}
          </Menu>
        </Popover>
      </MenuTrigger>

When select item, flips state and swaps sections rendered, resulting in:

Error: Cannot change the id of an item
    at $7135fc7d473fd974$export$dc064fe9e59310fd.setProps (http://localhost:3000/build/routes/_index-4NWDFMCL.js:7009:15)
    at http://localhost:3000/build/routes/_index-4NWDFMCL.js:7369:63
    at commitAttachRef (http://localhost:3000/build/_shared/chunk-GIAAE3CH.js:17271:28)
    at commitLayoutEffectOnFiber (http://localhost:3000/build/_shared/chunk-GIAAE3CH.js:17159:17)
    at commitLayoutMountEffects_complete (http://localhost:3000/build/_shared/chunk-GIAAE3CH.js:17976:17)
    at commitLayoutEffects_begin (http://localhost:3000/build/_shared/chunk-GIAAE3CH.js:17965:15)
    at commitLayoutEffects (http://localhost:3000/build/_shared/chunk-GIAAE3CH.js:17916:11)
    at commitRootImpl (http://localhost:3000/build/_shared/chunk-GIAAE3CH.js:19349:13)
    at commitRoot (http://localhost:3000/build/_shared/chunk-GIAAE3CH.js:19273:13)
    at performSyncWorkOnRoot (http://localhost:3000/build/_shared/chunk-GIAAE3CH.js:18891:11)

🤔 Expected Behavior?

Able to conditionally render node in menu component tree based on state

😯 Current Behavior

Unble to conditionally render node in menu component tree based on state

💁 Possible Solution

No response

🔦 Context

No response

🖥️ Steps to Reproduce

Repo available at following repro:
https://github.com/rolanday/react-aria-change-id

  1. Clone
  2. Install node modules
  3. npm run dev
  4. Open menu, click item, observe result in devtools

Version

"react-aria-components": "^1.0.0-beta.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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions