React UIKit v3 error - ReferenceError: Element is not defined

Hello,
I’m upgrading React UIKit from v2 to v3 and got an error message ReferenceError: Element is not defined

My project enviroments following:

  • Nextjs: ^12.1.2,
  • React: ^17.0.2,
  • @sendbird/uikit-react: ^3.1.0

@Sravan_S Hi Sravan,
My project is using Nextjs and having problem as above when integrating React UIKit v3. Can you help me to solve this?
Thank you.

Hello @minhdat97

ReferenceError: Element is not defined is not very useful, can you share the full trace? or even a minimum reproducible repo in codesandbox/github?

Sorry, I haven’t been able to reproducible repo yet.

Here is tracelog.

1 Like

Let me see what I can find

1 Like

Can you see if this sample works for you?

Before, dynamic import of component used to work. Somehow it stopped working from 12.xx?

I changed to import dynamic for Channel, ChannelList, Provider and it worked. How about hooks, for example useChannelContext, how I can dynamic import it?

When I checked
import { useChannelListContext } from "@sendbird/uikit-react/ChannelList/context";
These worked fine

1 Like

cc @Tyler incase if we get similar questions

1 Like

Yep, I fixed.
Thank you so much.

I had this issue with <Channel>. After importing dynamically, I’m having trouble passing props in the the component.

How I imported based on code above:

const Channel = dynamic(import("@sendbird/uikit-react/Channel"), {
  ssr: false,
})

See attachements:

I looked through the uikit code in github and was able to resolve by doing the following:

import { ChannelContextProps } from '@sendbird/uikit-react/Channel/context'
const Channel = dynamic(import("@sendbird/uikit-react/Channel"), {
  ssr: false,
})
const channelProps: ChannelContextProps = {
  channelUrl: CHANNEL_URL,
  replyType: 'QUOTE_REPLY',
  disableUserProfile: true,
  isMessageGroupingEnabled: true,
}

return (
<SendbirdProvider
  appId="XXXXX"
  userId="sendbird"
  nickname="sendbird"
>
  <Channel {...channelProps} />
</SendbirdProvider>
)
1 Like

Hmm, this never happened on my sample projects…
Let us investigate. Can you share your project config?