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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu.Item with class component crashes with "Failed to execute 'compareDocumentPosition'" #1385

Closed
kevinwilde opened this issue Apr 29, 2022 · 4 comments
Assignees

Comments

@kevinwilde
Copy link

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

For example: v1.6.0

What browser are you using?

Chrome

Reproduction URL

https://codesandbox.io/s/headlessui-react-menu-example-forked-d79l6j?file=/src/App.js

Describe your issue

When the children prop of a Menu.Item is a class component or a function which returns a class component, opening the menu causes a crash with

Failed to execute 'compareDocumentPosition' on 'Node': parameter 1 is not of type 'Node'.

or

o.compareDocumentPosition is not a function

depending on the order of Menu.Items, i.e. depending on whether the class component MenuItem is in position a or b in a.compareDocumentPosition(b).

This error does not occur on v1.5.0. Perhaps something changed with how refs were passed onto the children of Menu.Item? #1168 also looks relevant since I believe it is crashing within sortByDomNode

@RobinMalfait RobinMalfait self-assigned this Apr 30, 2022
@RobinMalfait
Copy link
Member

Hey! Thank you for your bug report!
Much appreciated! 🙏

This issue occurs because you are not forwarding all the props and the ref to the underlying DOM node. I've updated your CodeSandbox that does this for both the class component and the functional component:

https://codesandbox.io/s/headlessui-react-menu-example-forked-sdnkl0?file=/src/App.js

In fact, this issue was also happening in Headless UI 1.5.0 but it was a bit less apparent. This CodeSandbox is the one you provided with version 1.5.0 of Headless UI, one thing you will notice is that you can't click the "Hello" menu item because the props were not forwarded correctly: https://codesandbox.io/s/headlessui-react-menu-example-forked-qggrlm?file=/src/App.js

Will make sure to make this better discoverable via docs / checks in Headless UI itself but have to think about a good solution for this.

@kevinwilde
Copy link
Author

Thanks for the explanation!

@killemalljustice
Copy link

Hi @RobinMalfait , do you have an example of this for Vue???

Thanks!!

@jordcodes
Copy link

@killemalljustice I had a similar issue in vue and found using the as property on the menu item to a div made the error go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants