Skip to content

Some components cannot be used with Next's SSR #123

Closed
@ferretwithaberet

Description

Describe the bug
I noticed this bug while trying to use the Modal component in a Next.js project. The error I am getting is document is not defined. I dug up a bit and I found out that the Modal component uses document.body as the default value for the root param and it also uses document.createElement to create it's container which it tries to append to root. The bug comes from Next.js trying to render the react in a SSR environment where object like window or document are not defined.

To Reproduce
Steps to reproduce the behavior:

  1. Make a Next.js project
  2. Add flowbite-react
  3. Make a Next.js page where you try to use the Modal component
  4. See error

Expected behavior
Component should work properly and no error should be logged to the console.

Desktop (please complete the following information):

  • OS: [e.g. iOS] EndeavourOS Linux x86_64 Kernel 5.17.7-arch1-1
  • Browser [e.g. chrome, safari] Brave
  • Version [e.g. 22] V1.38.115 (Chromium 101.0.4951.64)

Additional context
While deciding what to use, I also looked at other component libraries and I saw this PR which might be how they solved this issue, but I am not sure if that commit fixes this issue.

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions