Skip to content

Commit b2e4271

Browse files
committed
Adjust event loop yield time depending on dev or prod
1 parent cae48ec commit b2e4271

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
"@babel/preset-react"
3636
]
3737
},
38+
"jest": {
39+
"globals": {
40+
"__DEV__": true
41+
}
42+
},
3843
"lint-staged": {
3944
"**/*.js": [
4045
"flow focus-check",

src/__tests__/suspense.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('renderPrepass', () => {
1818

1919
const Outer = () => {
2020
const start = Date.now()
21-
while (Date.now() - start < 6) {}
21+
while (Date.now() - start < 21) {}
2222
return <Inner />
2323
}
2424

src/visitor.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ import {
5858
REACT_LAZY_TYPE
5959
} from './symbols'
6060

61+
// Time in ms after which the otherwise synchronous visitor yields so that
62+
// the event loop is not interrupted for too long
63+
const YIELD_AFTER_MS = __DEV__ ? 20 : 5
64+
6165
const render = (
6266
type: ComponentType<DefaultProps> & ComponentStatics,
6367
props: DefaultProps,
@@ -172,7 +176,7 @@ const visitLoop = (
172176
) => {
173177
const start = Date.now()
174178

175-
while (traversalChildren.length > 0 && Date.now() - start <= 5) {
179+
while (traversalChildren.length > 0 && Date.now() - start <= YIELD_AFTER_MS) {
176180
const currChildren = traversalChildren[traversalChildren.length - 1]
177181
const currIndex = traversalIndex[traversalIndex.length - 1]++
178182

0 commit comments

Comments
 (0)