-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: ⨯ Menu.js ⨯ Internal error: ReferenceError: document is not defined #15531
Comments
FYI: This is NextJS 14 + TypeScript, its
|
Menu's
|
@janhassel do you think it makes sense to guard against this by moving this out of the default function parameter and instead have it in a useEffect? |
@edumorlom it would be helpful to have a concrete reproduction of this issue, could you put together a sandbox of it on codesandbox? |
@tay1orjones I have to admit I'm not super familiar with how Next.js handles the rehydration, so let me know if this makes sense or not. Having the function Menu({
target = document?.body,
}) { or alternatively remove the default value and add a nullish coalescing operator when creating the portal (also with optional chaining)? createPortal(rendered, target ?? document?.body) I'm leaning towards the first option though (provided it works as I assume) for a more transparent API. |
I'm also getting this error, maybe I didn't implement it correctly, but I just have the following:
|
A good first step would be to implement @janhassel's first suggestion and seeing if this resolves the issue 👍 |
Package
@carbon/react
Browser
Chrome, Safari, Firefox, Edge
Package version
@carbon/react@1.47.0
React version
react@18.2.0
Description
The following code causes the an error:
Reproduction/example
None
Steps to reproduce
Any time I compile my code with NextJS/Typescript, I get the error above.
Suggested Severity
Severity 2 = User cannot complete task, and/or no workaround within the user experience of a given component.
Application/PAL
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: