nextui-org / nextui

πŸš€ Beautiful, fast and modern React UI library.
https://nextui.org
MIT License
21.41k stars 1.39k forks source link

[BUG] - Using Dropdown component in Next.JS throws a runtime exception #1403

Open iyxan23 opened 1 year ago

iyxan23 commented 1 year ago

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

  1. Install NextUI as described in the docs
  2. Copy the code from https://nextui.org/docs/components/dropdown#usage
  3. Clicks the dropdown button
  4. 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)

robodove commented 1 year ago

Happens on Tabs too @tabs/2.0.11

For now wrapping them in a client component ("use client") makes them work.

jrgarciadev commented 1 year ago

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.

iyxan23 commented 1 year ago

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.

Alright! I'll be keeping an eye on new updates πŸ˜‰ Thanks for the quick response

guivalerioS commented 1 year ago

Hy guys, Do we have an estimate of when this will be fixed?

JimmyRice commented 11 months ago

The Select component doesn't seem to be working either.

CitizenBeta commented 11 months ago

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.

What exactly do we add to our code to temporarily resolve it? I'm running into this issue with dropdowns.

CitizenBeta commented 11 months ago

If anyone else comes here, this is what it's supposed to look like, and it does fix this error perfectly:

Screenshot from 2023-09-27 17-03-02

robodove commented 11 months ago

If anyone else comes here, this is what it's supposed to look like, and it does fix this error perfectly:

Screenshot from 2023-09-27 17-03-02

No need to mark the whole page or larger server components as client components because of this.

You can just do this

"use client"
export { Select } from "@nextui-org/select"

Now you can just import the component from this file and you're done

mohammad1381 commented 10 months ago

If anyone else comes here, this is what it's supposed to look like, and it does fix this error perfectly: Screenshot from 2023-09-27 17-03-02

No need to mark the whole page or larger server components as client components because of this.

You can just do this

"use client"
export { Select } from "@nextui-org/select"

Now you can just import the component from this file and you're done

For some them not working this way. For example it works for Buttonbut not work for Tabs

meshv-p commented 10 months ago

Happens on Tabs too @tabs/2.0.11

For now wrapping them in a client component ("use client") makes them work.

Thanks for this. It's works for me.. I was finding around for Tabs issue, but I didn't find....

sspaeth-r7 commented 10 months ago

Is there any way to work around this on a component which must be server-side generated?

yahorbarkouski commented 10 months ago

Hey there, any updates for tabs?

YTG2G3 commented 9 months ago

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.

EpicCatto commented 9 months ago

any updates?

mxchinegod commented 9 months ago

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.

caanyp24 commented 9 months ago

same issue here any updates?

ahomu commented 8 months ago

same issue...

ArianSha commented 8 months ago

+1

elanclarkson commented 8 months ago

+1

ygd commented 8 months ago

+1

vvchldmsdn commented 8 months ago

I fix this removing the NextUIProvider from the layout.tsx of your nextjs application in src/app/layout.tsx (i put providers there cuz i see it like the root app component). Create a new layout component in other directory and import providers there, it works perfectly for me

You meant "other directory" insidie app directory like 'src/app/something/layout' or 'src/something/layout' ? or either works. Thanks in advance

usuarez commented 8 months ago

I fix this removing the NextUIProvider from the layout.tsx of your nextjs application in src/app/layout.tsx (i put providers there cuz i see it like the root app component). Create a new layout component in other directory and import providers there, it works perfectly for me

You meant "other directory" insidie app directory like 'src/app/something/layout' or 'src/something/layout' ? or either works. Thanks in advance

Hello i found a fix for that:

  1. we don't need import the rootLayout in our pages (my first mistake)
  2. add the 'use client' directive is mandatory for our client side components, in this case if you import nextUI components in the page.tsx then need to declare 'use client' at the top of the file.
vvchldmsdn commented 7 months ago

I fix this removing the NextUIProvider from the layout.tsx of your nextjs application in src/app/layout.tsx (i put providers there cuz i see it like the root app component). Create a new layout component in other directory and import providers there, it works perfectly for me

You meant "other directory" insidie app directory like 'src/app/something/layout' or 'src/something/layout' ? or either works. Thanks in advance

Hello i found a fix for that:

  1. we don't need import the rootLayout in our pages (my first mistake)
  2. add the 'use client' directive is mandatory for our client side components, in this case if you import nextUI components in the page.tsx then need to declare 'use client' at the top of the file.

I love you

robertgoacher commented 7 months ago

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.

Any update on this yet, @jrgarciadev ?

hashproton commented 7 months ago

Any updates?

mayyusan101 commented 7 months ago

Any update?

Pr1ms commented 7 months ago

Hello. Does anyone have a workaround for rendering Table elements 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 a use client context but it still generate the error : Error: Unknown element <[object Object]> in collection.

ottoernir commented 6 months ago

still no fix for this?

CMarshall92 commented 5 months ago

Not only is this an issues the types are incorrect as well, its expecting react nodes and the components are returning reactElements

image

Poweranimal commented 5 months ago

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.

@jrgarciadev Would you be so kind and share with us the issue of react-aria that fixes this issue?

pablojsx commented 5 months ago

well

tookender commented 5 months ago

@jrgarciadev Would you be so kind and share with us the issue of react-aria that fixes this issue?

bdubtga commented 4 months ago

Still having this issue trying to use dropdowns, any timeline on a update?

usuarez commented 4 months ago

Still having this issue trying to use dropdowns, any timeline on a update?

Hi, try with the 'use client' y your component

CitizenBeta commented 4 months ago

Still having this issue trying to use dropdowns, any timeline on a update?

Hi, try with the 'use client' y your component

This works but breaks SSR

usuarez commented 4 months ago

This works but breaks SSR

Every nextUi component has the 'use client' declared at top, and i don't know if the dev want to change it, finally i decided to use primereact, is very easy

stefnto commented 4 months ago

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.

Guys did you read the dev's reply? He said you should use "use client" for now, but internally nextjs removes the 'use client' so the component is rendered in the server...

dragonlobster commented 1 month ago

this bug also applies to Select. the docs don't mention use client at all

Veeresh-R-G commented 1 month ago

I am facing this issue with the table component too.

image

wingkwong commented 1 month ago

@Veeresh-R-G it's more like you missed TableBody.

Veeresh-R-G commented 1 month ago

@Veeresh-R-G it's more like you missed TableBody.

@wingkwong I had copied the code from the docs at Next-UI. For the first time I ran the code, it did show the mentioned errors, but now its working fine.

Thanks for the prompt reply πŸ˜€

slimshreydy commented 2 weeks ago

Any updates on this issue?