Skip to content

Commit

Permalink
fix(react-dom): Fix crash during server render (#14103)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
tnunes authored and gaearon committed Nov 5, 2018
1 parent ce90ffd commit b305c4e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

// -------------------
Expand Down

0 comments on commit b305c4e

Please sign in to comment.