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

UseLayoutEffect Warning #31

Open
fmssn opened this issue Jul 28, 2023 · 2 comments
Open

UseLayoutEffect Warning #31

fmssn opened this issue Jul 28, 2023 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@fmssn
Copy link

fmssn commented Jul 28, 2023

When using the package, I get the warning:

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://reactjs.org/link/uselayouteffect-ssr for common fixes.

I assume this is because interactivity is obviously not given when rendering to a PDF. This does not break anything, yet it makes debugging and logging a bit inconvenient. Have you dealt with this issue before? Is there a way to suppress this warning without suppressing other warnings?

@EvHaus EvHaus added bug Something isn't working help wanted Extra attention is needed labels Jul 28, 2023
@EvHaus
Copy link
Owner

EvHaus commented Jul 28, 2023

Yeah... it's super annoying and I have no idea how to fix it cleanly. My workaround for this has been:

// Silence `useLayoutEffect does nothing on the server` warnings. These come
// from `recharts` but they're harmless and just clutter the console output.
const consoleError = console.error;
console.error = function (message) {
    if (message?.startsWith('Warning: useLayoutEffect does nothing on the server')) return;
    consoleError.apply(console, arguments);
};

@fmssn
Copy link
Author

fmssn commented Jul 28, 2023

Thank you for the fast response! This works for now. I looked into it, but I don't know how to fix it either without delving deeply into e.g. Recharts components and modifying them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants