You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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://fb.me/react-uselayouteffect-ssr for common fixes.%s
My test suite is configured to consider warnings to be failures, so tests like this are a problem. The warning doesn't happen when I used react-redux6.x, but when I upgrade to 7.x it does.
Based on this thread, I would assume the problem is that react and react-redux disagree about whether this is server-side rendering or not. react thinks it's server-side. react-redux thinks it's client-side. This is probably because jest creates a window object.
They provide a solution: switch the jestenvironment to node. This doesn't work in my case since my tests do rely on the window object in practice.
What is the expected behavior?
React and React-Redux should agree about whether server-side rendering is occurring. No warning should be produced when running tests with jest and enzyme.
I imagine this could be a problem for legitimate server-side rendering as well if they're using jsdom.
The text was updated successfully, but these errors were encountered:
nickretallack
changed the title
Needs better client/server side detection in test cases
Needs better client/server side detection for test cases
Mar 5, 2020
As I stated in that issue, if you're creating a global window object, you are effectively creating a browser environment. That's going to affect a lot of libraries, not just us.
We also use the exact same logic as React to detect the browser vs server:
I think what's likely happening is you're setting up that browser environment incorrectly. We shouldn't disagree with React, so your window is created at the wrong time or in the wrong way. I'm not sure without seeing your full project. This doesn't appear to be a bug in React Redux, though.
What is the current behavior?
If I run this
jest
test:I get a warning:
My test suite is configured to consider warnings to be failures, so tests like this are a problem. The warning doesn't happen when I used
react-redux
6.x
, but when I upgrade to7.x
it does.Based on this thread, I would assume the problem is that
react
andreact-redux
disagree about whether this is server-side rendering or not.react
thinks it's server-side.react-redux
thinks it's client-side. This is probably becausejest
creates awindow
object.They provide a solution: switch the
jest
environment
tonode
. This doesn't work in my case since my tests do rely on thewindow
object in practice.What is the expected behavior?
React and React-Redux should agree about whether server-side rendering is occurring. No warning should be produced when running tests with
jest
andenzyme
.I imagine this could be a problem for legitimate server-side rendering as well if they're using jsdom.
The text was updated successfully, but these errors were encountered: