Skip to content

vitest-browser-react(v4): Element reference error when testing Radix DropdownMenu with modal={true} #8810

@onyedikachi23

Description

@onyedikachi23

Describe the bug

Provider is Playwright. When I use user event to click the DropdownMenuTrigger, the DropdownMenu opens and i'm able to reference elements in it. But when I try to reference elements declared before the DropdownMenu was opened, I get the error:

VitestBrowserElementError: Cannot find element with locator: locator( // and so on).

But I noticed this only happens when modal={true} in the DropdownMenu. Setting <DropdownMenu modal={false} />, I don't get the error and things work fine.

Although setting <DropdownMenu modal={false} /> doesn't negatively affect the feature I'm testing, it might be a problem when I actually need <DropdownMenu modal={true} />.

Reproduction

Run this message-composer.test.tsx.

The test passes when you set modal={false} in MessageAttachmentsPickerMenu

System Info

System:
    OS: Linux 6.11 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
    CPU: (4) x64 Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
    Memory: 1.83 GB / 7.64 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 23.9.0 - /home/onyedikachi23/.nvm/versions/node/v23.9.0/bin/node
    npm: 11.2.0 - /home/onyedikachi23/.nvm/versions/node/v23.9.0/bin/npm
    pnpm: 10.8.1 - /home/onyedikachi23/.nvm/versions/node/v23.9.0/bin/pnpm
    Watchman: 4.9.0 - /usr/bin/watchman
  Browsers:
    Brave Browser: 135.1.77.95
    Chrome: 140.0.7339.80
    Firefox: 143.0.4
    Firefox Developer Edition: 143.0.4
  npmPackages:
    @vitejs/plugin-react: ^5.1.0 => 5.1.0 
    @vitest/browser-playwright: ^4.0.3 => 4.0.3 
    vite: ^7.1.7 => 7.1.12 
    vitest: ^4.0.3 => 4.0.3 
    vitest-browser-react: ^2.0.0 => 2.0.0

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions