Skip to content
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]: Server-side rendering broken on Menu and OverflowMenu #16251

Closed
2 tasks done
guidari opened this issue Apr 23, 2024 · 2 comments · Fixed by #16559
Closed
2 tasks done

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

guidari opened this issue Apr 23, 2024 · 2 comments · Fixed by #16559

Comments

@guidari
Copy link
Contributor

guidari commented Apr 23, 2024

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:

export function useWindowEvent(eventName, callback) {
/**
* @type {MutableRefObject<WindowEventCallback<E> | null>}
*/
const savedCallback = useRef(null);
useEffect(() => {
savedCallback.current = callback;
}, [callback]);
useEffect(() => {
/**
* @type {WindowEventCallback<E>}
*/
function handler(event) {
if (savedCallback.current) {
savedCallback.current(event);
}
}
window.addEventListener(eventName, handler);
return () => {
window.removeEventListener(eventName, handler);
};
}, [eventName]);
}

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
Copy link
Member

Related: #15531

@DoaaRadwan
Copy link

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

@guidari guidari added severity: 2 https://ibm.biz/carbon-severity and removed severity: 3 https://ibm.biz/carbon-severity labels May 14, 2024
@guidari guidari moved this to ⏱ Backlog in Design System May 14, 2024
@guidari guidari moved this from ⏱ Backlog to 🚦 In Review in Design System May 24, 2024
@github-project-automation github-project-automation bot moved this from 🚦 In Review to ✅ Done in Design System Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants