nextui icon indicating copy to clipboard operation
nextui copied to clipboard

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

Open iyxan23 opened this issue 2 years ago • 43 comments

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)

iyxan23 avatar Aug 15 '23 07:08 iyxan23

Happens on Tabs too @tabs/2.0.11

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

alightinastorm avatar Aug 15 '23 08:08 alightinastorm

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 avatar Aug 15 '23 12:08 jrgarciadev

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

iyxan23 avatar Aug 15 '23 12:08 iyxan23

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

guivalerioS avatar Sep 08 '23 02:09 guivalerioS

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

JimmyRice avatar Sep 27 '23 17:09 JimmyRice

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.

RyanPaiva56 avatar Sep 27 '23 20:09 RyanPaiva56

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

RyanPaiva56 avatar Sep 27 '23 21:09 RyanPaiva56

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

alightinastorm avatar Sep 27 '23 21:09 alightinastorm

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 Button but not work for Tabs

mohammad1381 avatar Oct 21 '23 09:10 mohammad1381

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....

meshv-p avatar Oct 26 '23 14:10 meshv-p

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

sspaeth-r7 avatar Nov 01 '23 21:11 sspaeth-r7

Hey there, any updates for tabs?

yahorbarkouski avatar Nov 06 '23 14:11 yahorbarkouski

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.

YTG2G3 avatar Nov 24 '23 09:11 YTG2G3

any updates?

EpicCatto avatar Dec 03 '23 17:12 EpicCatto

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.

mxchinegod avatar Dec 11 '23 16:12 mxchinegod

same issue here any updates?

caanyp24 avatar Dec 17 '23 00:12 caanyp24

same issue...

ahomu avatar Dec 19 '23 07:12 ahomu

+1

ArianSha avatar Dec 26 '23 00:12 ArianSha

+1

elanclarkson avatar Dec 27 '23 23:12 elanclarkson

+1

ygd avatar Jan 09 '24 00:01 ygd

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

vvchldmsdn avatar Jan 14 '24 17:01 vvchldmsdn

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.

usuarez avatar Jan 15 '24 19:01 usuarez

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

vvchldmsdn avatar Jan 19 '24 06:01 vvchldmsdn

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 ?

robertgoacher avatar Jan 19 '24 20:01 robertgoacher

Any updates?

whysocket avatar Feb 03 '24 01:02 whysocket

Any update?

mayyusan101 avatar Feb 03 '24 10:02 mayyusan101

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 Table and its sub-components from within a use client context but it still generate the error : Error: Unknown element <[object Object]> in collection.

Pr1ms avatar Feb 06 '24 23:02 Pr1ms

still no fix for this?

ottoernir avatar Mar 14 '24 13:03 ottoernir

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

image

CMarshall92 avatar Mar 24 '24 02:03 CMarshall92

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?

Poweranimal avatar Mar 27 '24 14:03 Poweranimal