nextui: [BUG] - Using Dropdown component in Next.JS throws a runtime exception
NextUI Version
^2.0.15
Describe the bug
Using the Dropdown component as stated in the docs causes a Runtime Exception when the trigger is clicked. The error itself does not provide any meaningful information for debugging: Error: Unknown element <[object Object]> in collection., so I believe this is an internal bug. Source: https://nextui.org/docs/components/dropdown
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
- Install NextUI as described in the docs
- Copy the code from https://nextui.org/docs/components/dropdown#usage
- Clicks the dropdown button
- Raised a cryptic runtime exception
Error: Unknown element <[object Object]> in collection.
Additional info: I’m using Vivaldi, a derivative of chrome.
Expected behavior
I expected the dropdown to show and to not raise an exception.
Screenshots or Videos
https://github.com/nextui-org/nextui/assets/31884435/455677d5-ee0f-45f6-bf88-97660457b20a
Operating System Version
Fedora 38 KDE Plasma; Linux laptop 6.3.11-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Jul 2 13:17:31 UTC 2023 x86_64 GNU/Linux
Browser
Other (add additonal context)
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 6
- Comments: 37 (1 by maintainers)
Hey @iyxan23 we are waiting for the next react-aria release to get this issue fixed, the current collection approach is compiled by next.js in a different way so it removes the
use client;directive, in the meantime please add the directive on top of your files for collection based components -> Table, Accordion, Dropdown, and Tabs.Is there any way to work around this on a component which must be server-side generated?
Hey there, any updates for tabs?
Hy guys, Do we have an estimate of when this will be fixed?
Any update on this yet, @jrgarciadev ?
If you put your offending Accordion/Dropdown/Select, etc. code into a new component, put
"use script";into that component, and import it into your server-borne .jsx file (being sure to remove"use script";from there if you put it as a temp fix), it will work.Still doesn’t seem to be working. The workaround is creating a mess between client component and server action… I hope this gets fixed soon.
Happens on Tabs too @tabs/2.0.11
For now wrapping them in a client component (“use client”) makes them work.
Hello. Does anyone have a workaround for rendering
Tableelements into a server page (which cannot be made a client page without rewriting like 30% of my application and infringing constraints I have to enforce) ?None of the workarounds therein work for this purpose.
I’ve tried reexporting
Tableand its sub-components from within ause clientcontext but it still generate the error :Error: Unknown element <[object Object]> in collection.No need to mark the whole page or larger server components as client components because of this.
You can just do this
Now you can just import the component from this file and you’re done
The Select component doesn’t seem to be working either.
well
still no fix for this?
I love you
+1
+1
For some them not working this way. For example it works for
Buttonbut not work forTabsIf anyone else comes here, this is what it’s supposed to look like, and it does fix this error perfectly: