fix(react-dom): Fix crash during server render (#14103)
Check for existence of `setTimeout` and `clearTimeout` in the runtime before using them, to ensure runtimes without them (like .NET ClearScript) do not crash just by importing `react-dom`.
Tiago Nunes committed
Nov 5, 2018 at 17:08 UTC
b305c4e034bbb3b13df2028c0503a84f91e57455
1 file changed
+7
-2
packages/react-dom/src/client/ReactDOMHostConfig.js
+7
-2
@@ -284,8 +284,13 @@ export function createTextInstance(
284
}
285
286
export const isPrimaryRenderer = true;
287
-export const scheduleTimeout = setTimeout;
288
-export const cancelTimeout = clearTimeout;
287
+// This initialization code may run even on server environments
288
+// if a component just imports ReactDOM (e.g. for findDOMNode).
289
+// Some environments might not have setTimeout or clearTimeout.
290
+export const scheduleTimeout =
291
+ typeof setTimeout === 'function' ? setTimeout : (undefined: any);
292
+export const cancelTimeout =
293
+ typeof clearTimeout === 'function' ? clearTimeout : (undefined: any);
294
export const noTimeout = -1;
295
296
// -------------------