-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
useIsomorphicLayoutEffect flag set wrongly #1492
Comments
Fix condition to work in Node even when the window object is defined Closes reduxjs#1492
Can you clarify when you are seeing this under Node? Is this specifically in a Jest test environment or similar? |
I'm emulating the browser env in Node to be able to run DOMPurify and other libs in SSR: const { JSDOM } = require('jsdom');
const DOM = new JSDOM('', { pretendToBeVisual: true });
global.document = DOM.window.document;
global.window = DOM.window; What I did on the linked commit removes false positives for cases like the exemplified above. |
It's sad just how specific we're having to feature-detect this. Yeah, can you file a PR to add that change here? |
I made it less specific now, just adding the check for the property |
If you're defining Over time, JSDOM is going to get closer and closer to the DOM spec, so things like the Is it reasonable to make your code not rely on |
@timdorr I agree with you and thanks for the call out! I'm already doing some refactoring on the app. |
Closing the issue |
I arrived here with the same question as @patricksmms. The above post is a partially reasonable response in my view but I'm confused habout what the intended "correct" way of creating a virtual DOM is. Jest sets up a JSDOM environment with a |
What is the current behavior?
useIsomorphicLayoutEffect
is set to true when running on a Node.js instance, where the window object is defined.This is a common scenario when you need to emulate a subset of a web browser for tests or DOM manipulation, then you define the object perhaps with JSDom.
It's resulting in console warnings and issues when hydrating the SSR code.
What is the expected behavior?
useIsomorphicLayoutEffect
flag is set to false when running in Node.js, always, not relying only on the window object being undefined.Ref: https://github.com/reduxjs/react-redux/blob/master/src/utils/useIsomorphicLayoutEffect.js#L12
Used versions
This used to work without issues, in
[email protected]
.The text was updated successfully, but these errors were encountered: