Skip to content

useIsomorphicLayoutEffect cannot pass test cases in non-web environment #1436

Closed
@malash

Description

@malash

Do you want to request a feature or report a bug?

Report a bug.

What is the current behavior?

const useIsomorphicLayoutEffect =
typeof window !== 'undefined' &&
typeof window.document !== 'undefined' &&
typeof window.document.createElement !== 'undefined'
? useLayoutEffect
: useEffect

const useIsomorphicLayoutEffect =
typeof window !== 'undefined' &&
typeof window.document !== 'undefined' &&
typeof window.document.createElement !== 'undefined'
? useLayoutEffect
: useEffect

These two files implement the useIsomorphicLayoutEffect hook to prevent the React warning by using useEffect instead of useLayoutEffect. But it could break on non-web environment, like React Native, and etc.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to a CodeSandbox (https://codesandbox.io/s/new) or RN Snack (https://snack.expo.io/) example below:

I tested by these steps:

  1. Clone the react-redux repo
  2. Modify useIsomorphicLayoutEffect to const useIsomorphicLayoutEffect = useEffect
  3. Run npx jest

image

What is the expected behavior?

  1. We should add some test cases for non-web environment. For example @testing-library/react-native provides the way to test react-native in jest.
  2. We should review the implement of useIsomorphicLayoutEffect and fix it if there did have some bugs.

Which versions of React, ReactDOM/React Native, Redux, and React Redux are you using? Which browser and OS are affected by this issue? Did this work in previous versions of React Redux?

react-redux@7.1.1

cc

@byunicorn

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions