From c4b5885c2d87d9d92b181877e21f3726498d5d09 Mon Sep 17 00:00:00 2001 From: Dustin Masters Date: Thu, 21 Jun 2018 11:45:23 -0700 Subject: [PATCH] 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. https://github.com/reactjs/React.NET/issues/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. --- packages/react-scheduler/src/ReactScheduler.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/react-scheduler/src/ReactScheduler.js b/packages/react-scheduler/src/ReactScheduler.js index 2b016f1275739..4ee113f74b932 100644 --- a/packages/react-scheduler/src/ReactScheduler.js +++ b/packages/react-scheduler/src/ReactScheduler.js @@ -60,8 +60,9 @@ if (__DEV__) { // this module is initially evaluated. // We want to be using a consistent implementation. const localDate = Date; -const localSetTimeout = setTimeout; -const localClearTimeout = clearTimeout; +const localSetTimeout = typeof setTimeout === 'function' ? setTimeout : null; +const localClearTimeout = + typeof clearTimeout === 'function' ? clearTimeout : null; const hasNativePerformanceNow = typeof performance === 'object' && typeof performance.now === 'function';