carbon-design-system / carbon

A design system built by IBM
https://www.carbondesignsystem.com
Apache License 2.0
7.74k stars 1.79k forks source link

[Bug]: Server-side rendering broken on Menu and OverflowMenu #16251

Closed guidari closed 3 months ago

guidari commented 4 months ago

Package

@carbon/react

Browser

No response

Package version

v1.55.0

React version

18.02

Description

Reported on Slack

When using NextJS with Menu and OverflowMenu with server-side rendering the following error shows up: Internal error: ReferenceError: document is not defined

This might be solved by using this helper:

https://github.com/carbon-design-system/carbon/blob/71c553cb9d162d3bfc32885f5d0234d048322b3c/packages/react/src/internal/useEvent.js#L68-L94

Reproduction/example

https://stackblitz.com/edit/stackblitz-starters-vavqe5?file=app%2Fpage.tsx

Steps to reproduce

Open Stackblitz example and check the console log

Suggested Severity

Severity 3 = User can complete task, and/or has a workaround within the user experience of a given component.

Application/PAL

No response

Code of Conduct

janhassel commented 4 months ago

Related: #15531

DoaaRadwan commented 4 months ago

Any updates on this? a similar issue was reported to the @carbon/ibm-products team and was fixed here https://github.com/carbon-design-system/ibm-products/issues/4966 if this could be of any help .