Skip to content

Popover anchorEl console.warn spam in jsdom in MUI 7.3.8 #47792

@joshkel

Description

@joshkel

Steps to reproduce

Steps:

  1. Clone the repo at https://github.com/joshkel/mui-jsdom-anchorel-bug
  2. pnpm i
  3. pnpm t
  4. Note the anchorEl warnings in the console.
  5. Compare with MUI 7.3.7, which did not have these warnings.

Current behavior

Warnings and errors about invalid anchorEl in the console.

  console.warn
    MUI: The `anchorEl` prop provided to the component is invalid.
    The anchor element should be part of the document layout.
    Make sure the element is present in the document or that it's not display none.

      28 |     render(<TestSelect />);
      29 |
    > 30 |     fireEvent.mouseDown(screen.getByLabelText('Age'));
         |               ^
      31 |     fireEvent.click(screen.getByText('Twenty'));
      32 |   });
      33 | });

      at node_modules/.pnpm/@mui+material@7.3.8_@emotion+react@11.14.0_@types+react@18.3.28_react@18.3.1__@emotion+_c717ef74b561a9170687cdfe6f8fd663/node_modules/@mui/material/Popover/Popover.js:161:17
      at node_modules/.pnpm/@mui+material@7.3.8_@emotion+react@11.14.0_@types+react@18.3.28_react@18.3.1__@emotion+_c717ef74b561a9170687cdfe6f8fd663/node_modules/@mui/material/Popover/Popover.js:194:26
      at node_modules/.pnpm/@mui+material@7.3.8_@emotion+react@11.14.0_@types+react@18.3.28_react@18.3.1__@emotion+_c717ef74b561a9170687cdfe6f8fd663/node_modules/@mui/material/Popover/Popover.js:247:25

Expected behavior

No log spam; no significant behavior changes from 7.3.7.

Context

As a result of #47692, MUI now warns about "invalid" anchorEl properties in test environments. This causes a problem for test environments such as Jest with jsdom: it's my understanding that jsdom doesn't contain a layout engine, so all elements within jsdom have 0 dimensions, so checks such as

if (
!globalThis.MUI_TEST_ENV &&
box.top === 0 &&
box.left === 0 &&
box.right === 0 &&
box.bottom === 0
) {
console.warn(
[
'MUI: The `anchorEl` prop provided to the component is invalid.',
'The anchor element should be part of the document layout.',
"Make sure the element is present in the document or that it's not display none.",
].join('\n'),
);
}

trigger even for "valid" anchorEl values.

What's the recommended way to use MUI in a test environment? I see in #47692 that globalThis.MUI_TEST_ENV is implemented, but it sounds like that's undocumented and intended for internal use only. I suspect that use in jsdom is common enough that going back to the previous behavior of process.env.NODE_ENV === 'test' would be better.

Your environment

npx @mui/envinfo
  System:
    OS: macOS 15.7.3
  Binaries:
    Node: 24.13.0 - /Users/josh/.nvm/versions/node/v24.13.0/bin/node
    npm: 11.6.2 - /Users/josh/.nvm/versions/node/v24.13.0/bin/npm
    pnpm: Not Found
  Browsers:
    Chrome: 144.0.7559.133
    Edge: 145.0.3800.58
    Firefox: 147.0.4
    Safari: 26.2
  npmPackages:
    @base-ui/utils:  0.2.3 
    @emotion/react:  11.14.0 
    @emotion/styled:  11.14.1 
    @mui/core-downloads-tracker:  7.3.8 
    @mui/icons-material:  7.3.8 
    @mui/lab:  7.0.1-beta.22 
    @mui/material:  7.3.8 
    @mui/private-theming:  7.3.8 
    @mui/styled-engine:  7.3.8 
    @mui/system:  7.3.8 
    @mui/types:  7.4.11 
    @mui/utils:  7.3.8 
    @mui/x-date-pickers:  8.27.0 
    @mui/x-internals:  8.26.0 
    @mui/x-tree-view:  8.27.1 
    @types/react: ^18.3.27 => 18.3.27 
    react: ^18.3.1 => 18.3.1 
    react-dom: ^18.3.1 => 18.3.1 
    typescript: ^5.9.3 => 5.9.3 

Search keywords: popover anchorel

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions