Skip to content

Commit c4b5885

Browse files
author
Dustin Masters
committed
This fixes a crash that only occurs in react-dom 16.4.1.
setTimeout and clearTimeout may not be available in some server-render environments (such as ChakraCore in React.NET), and loading ReactScheduler.js will cause a crash unless the existence of the variables are checked via a typeof comparison. reactjs/React.NET#555 The crash did not occur in 16.4.0, and the change appears to have been introduced here: https://github.com/facebook/react/pull/12931/files#diff-bbebc3357e1fb99ab13ad796e04b69a6L47 I tested this by using yarn link and running it with a local copy of React.NET. I am unsure the best way to unit test this change, since assigning null to `setTimeout` causes an immediate crash within the Node REPL.
1 parent 5b3d17a commit c4b5885

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/react-scheduler/src/ReactScheduler.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ if (__DEV__) {
6060
// this module is initially evaluated.
6161
// We want to be using a consistent implementation.
6262
const localDate = Date;
63-
const localSetTimeout = setTimeout;
64-
const localClearTimeout = clearTimeout;
63+
const localSetTimeout = typeof setTimeout === 'function' ? setTimeout : null;
64+
const localClearTimeout =
65+
typeof clearTimeout === 'function' ? clearTimeout : null;
6566

6667
const hasNativePerformanceNow =
6768
typeof performance === 'object' && typeof performance.now === 'function';

0 commit comments

Comments
 (0)