forked from reduxjs/react-redux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix RN batching and effect behavior (reduxjs#1444)
* Add React Native deps for testing * Add a Jest config to run tests in an RN environment * Add initial RN tests * Add test for RN batch export * Add jest-native testing assertions * Extract useIsomorphicLayoutEffect utility * Add additional RN batching-related tests * 7.1.2-alpha.0
- Loading branch information
1 parent
73bdd29
commit ad4c333
Showing
8 changed files
with
3,699 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const defaults = { | ||
coverageDirectory: './coverage/', | ||
collectCoverage: true, | ||
testURL: 'http://localhost' | ||
} | ||
|
||
const testFolderPath = folderName => `<rootDir>/test/${folderName}/**/*.js` | ||
|
||
const NORMAL_TEST_FOLDERS = ['components', 'hooks', 'integration', 'utils'] | ||
|
||
const standardConfig = { | ||
...defaults, | ||
displayName: 'ReactDOM', | ||
testMatch: NORMAL_TEST_FOLDERS.map(testFolderPath) | ||
} | ||
|
||
const rnConfig = { | ||
...defaults, | ||
displayName: 'React Native', | ||
testMatch: [testFolderPath('react-native')], | ||
preset: 'react-native', | ||
transform: { | ||
'^.+\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js' | ||
} | ||
} | ||
|
||
module.exports = { | ||
projects: [standardConfig, rnConfig] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useEffect, useLayoutEffect } from 'react' | ||
|
||
// React currently throws a warning when using useLayoutEffect on the server. | ||
// To get around it, we can conditionally useEffect on the server (no-op) and | ||
// useLayoutEffect in the browser. We need useLayoutEffect to ensure the store | ||
// subscription callback always has the selector from the latest render commit | ||
// available, otherwise a store update may happen between render and the effect, | ||
// which may cause missed updates; we also must ensure the store subscription | ||
// is created synchronously, otherwise a store update may occur before the | ||
// subscription is created and an inconsistent state may be observed | ||
|
||
const isHopefullyDomEnvironment = | ||
typeof window !== 'undefined' && | ||
typeof window.document !== 'undefined' && | ||
typeof window.document.createElement !== 'undefined' | ||
|
||
export const useIsomorphicLayoutEffect = isHopefullyDomEnvironment | ||
? useLayoutEffect | ||
: useEffect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { useLayoutEffect } from 'react' | ||
|
||
// Under React Native, we know that we always want to use useLayoutEffect | ||
|
||
export const useIsomorphicLayoutEffect = useLayoutEffect |
Oops, something went wrong.