Skip to content

Commit b305c4e

Browse files
tnunesgaearon
authored andcommitted
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`.
1 parent ce90ffd commit b305c4e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

packages/react-dom/src/client/ReactDOMHostConfig.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,13 @@ export function createTextInstance(
284284
}
285285

286286
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);
289294
export const noTimeout = -1;
290295

291296
// -------------------

0 commit comments

Comments
 (0)