Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popper propTypes validation for Virtual Element object throws an error #30498

Closed
2 tasks done
JeremyGrieshop opened this issue Jan 4, 2022 · 2 comments
Closed
2 tasks done
Assignees
Labels
external dependency Blocked by external dependency, we can鈥檛 do anything about it

Comments

@JeremyGrieshop
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 馃槸

When using the Popper and attempting to pass a fake, Virtual Element object in by setting the coordinates for the Popper, I'll get a prop-types warning in the console:

image

You can see the same one in the codesandbox demo.

This error is very misleading, and if I do some investigative work inside the React prop-types validation routine, I can find that this error is actually the result of React's prop-types validator assuming what was passed in had a shape it was after, when in fact, it was an error object, or error stack passed in by Material-UI. Here's the actual error stack, by running some console.log statements inside factoryWithTypeCheckers.js while Jest runs:

Error: Invalid prop `anchorEl` supplied to `ForwardRef(PopperUnstyled)`. Expected an HTMLElement.
        at HTMLElementType (/workspaces/inter-afw/node_modules/@mui/utils/HTMLElementType.js:21:12)
        at validate (/workspaces/inter-afw/node_modules/prop-types/factoryWithTypeCheckers.js:389:29)
        at checkType (/workspaces/inter-afw/node_modules/prop-types/factoryWithTypeCheckers.js:219:16)
        at Object.validate (/workspaces/inter-afw/node_modules/@mui/utils/chainPropTypes.js:14:12)
        at checkPropTypes (/workspaces/inter-afw/node_modules/react/cjs/react-jsx-runtime.development.js:601:44)
        at validatePropTypes (/workspaces/inter-afw/node_modules/react/cjs/react-jsx-runtime.development.js:1078:7)
        at jsxWithValidation (/workspaces/inter-afw/node_modules/react/cjs/react-jsx-runtime.development.js:1198:7)
        at jsxWithValidationDynamic (/workspaces/inter-afw/node_modules/react/cjs/react-jsx-runtime.development.js:1215:12)
        at Popper (/workspaces/inter-afw/node_modules/@mui/material/node/Popper/Popper.js:42:43)
        at renderWithHooks (/workspaces/inter-afw/node_modules/react-dom/cjs/react-dom.development.js:14985:18)
        at updateForwardRef (/workspaces/inter-afw/node_modules/react-dom/cjs/react-dom.development.js:17044:20)
        at beginWork (/workspaces/inter-afw/node_modules/react-dom/cjs/react-dom.development.js:19098:16)
        at beginWork$1 (/workspaces/inter-afw/node_modules/react-dom/cjs/react-dom.development.js:23940:14)
        at performUnitOfWork (/workspaces/inter-afw/node_modules/react-dom/cjs/react-dom.development.js:22779:12)
        at workLoopSync (/workspaces/inter-afw/node_modules/react-dom/cjs/react-dom.development.js:22707:5)
        at renderRootSync (/workspaces/inter-afw/node_modules/react-dom/cjs/react-dom.development.js:22670:7)
        at performSyncWorkOnRoot (/workspaces/inter-afw/node_modules/react-dom/cjs/react-dom.development.js:22293:18)

Expected behavior 馃

The propType for anchorEl should be a valid object and not log a warning message.

Steps to reproduce 馃暪

Link to CodeSandbox (a very lightly modified fork of the demo):

https://codesandbox.io/s/virtualelementpopper-material-demo-forked-n2tuj?file=/demo.js

Context 馃敠

It's just a warning, but shows up all over the place for me when I run tests.

Your environment 馃寧

`npx @mui/envinfo`
    System:
    OS: Linux 5.10 CentOS Linux 8
  Binaries:
    Node: 14.18.1 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.1.3 - /usr/local/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmPackages:
    @emotion/react: ^11.4.1 => 11.7.1 
    @emotion/styled: ^11.3.0 => 11.6.0 
    @mui/base:  5.0.0-alpha.63 
    @mui/icons-material: ^5.0.0 => 5.2.5 
    @mui/lab: ^5.0.0-alpha.47 => 5.0.0-alpha.63 
    @mui/material: ^5.0.0 => 5.2.7 
    @mui/private-theming:  5.2.3 
    @mui/styled-engine:  5.2.6 
    @mui/styles: ^5.0.0 => 5.2.3 
    @mui/system:  5.2.6 
    @mui/types:  7.1.0 
    @mui/utils:  5.2.3 
    @types/react:  17.0.37 
    react: ^17.0.2 => 17.0.2 
    react-dom: ^17.0.2 => 17.0.2 
    typescript: ^4.3.2 => 4.5.4 
@JeremyGrieshop JeremyGrieshop added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 4, 2022
@JeremyGrieshop JeremyGrieshop changed the title Popper propTypes validation for VirtualElement throws an error Popper propTypes validation for Virtual Element object throws an error Jan 4, 2022
@siriwatknp
Copy link
Member

I am not sure if it relates to this facebook/prop-types#370.

@JeremyGrieshop
Copy link
Author

I am not sure if it relates to this facebook/prop-types#370.

Wow, that totally fixed it (upgrading to prop-types 5.8.1)! I even searched facebook/prop-types first, but I guess he submitted the bug report and the PR literally minutes after I opened this one here.

@mnajdova mnajdova added external dependency Blocked by external dependency, we can鈥檛 do anything about it and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external dependency Blocked by external dependency, we can鈥檛 do anything about it
Projects
None yet
Development

No branches or pull requests

5 participants