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`.
This commit is contained in:
Tiago Nunes
2018-11-05 17:08:07 +00:00
committed by Dan Abramov
parent ce90ffd045
commit b305c4e034
+7 -2
View File
@@ -284,8 +284,13 @@ export function createTextInstance(
}
export const isPrimaryRenderer = true;
export const scheduleTimeout = setTimeout;
export const cancelTimeout = clearTimeout;
// This initialization code may run even on server environments
// if a component just imports ReactDOM (e.g. for findDOMNode).
// Some environments might not have setTimeout or clearTimeout.
export const scheduleTimeout =
typeof setTimeout === 'function' ? setTimeout : (undefined: any);
export const cancelTimeout =
typeof clearTimeout === 'function' ? clearTimeout : (undefined: any);
export const noTimeout = -1;
// -------------------