From 6553e50840b0a0dbf05056a9461f588004d544d3 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 26 Sep 2018 12:03:57 +0100 Subject: [PATCH 1/4] Ensure addEventListener exists on "window" --- packages/scheduler/src/Scheduler.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/scheduler/src/Scheduler.js b/packages/scheduler/src/Scheduler.js index 412f96930eb36..e816cc6ce878a 100644 --- a/packages/scheduler/src/Scheduler.js +++ b/packages/scheduler/src/Scheduler.js @@ -573,8 +573,12 @@ if (typeof window === 'undefined') { } }; // Assumes that we have addEventListener in this environment. Might need - // something better for old IE. - window.addEventListener('message', idleTick, false); + // something better for old IE. Furthermore, "addEventListener" might not + // be available on the window object (if this is a RN mocked window), + // so we should check that it's a function before attaching the listener. + if (typeof window.addEventListener === 'function') { + window.addEventListener('message', idleTick, false); + } var animationTick = function(rafTime) { isAnimationFrameScheduled = false; From f968b8418be7846cb43d71c008c992af5d8cd3d0 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 26 Sep 2018 12:45:11 +0100 Subject: [PATCH 2/4] Update conditional as per feedback --- packages/scheduler/src/Scheduler.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/scheduler/src/Scheduler.js b/packages/scheduler/src/Scheduler.js index e816cc6ce878a..3b2c081511c88 100644 --- a/packages/scheduler/src/Scheduler.js +++ b/packages/scheduler/src/Scheduler.js @@ -468,7 +468,9 @@ var requestHostCallback; var cancelHostCallback; var getFrameDeadline; -if (typeof window === 'undefined') { +// "addEventListener" might not be available on the window object +// if this is a mocked "window" object. So we need to validate that too. +if (typeof window === 'undefined' || typeof window.addEventListener === 'function') { // If this accidentally gets imported in a non-browser environment, fallback // to a naive implementation. var timeoutID = -1; @@ -573,12 +575,8 @@ if (typeof window === 'undefined') { } }; // Assumes that we have addEventListener in this environment. Might need - // something better for old IE. Furthermore, "addEventListener" might not - // be available on the window object (if this is a RN mocked window), - // so we should check that it's a function before attaching the listener. - if (typeof window.addEventListener === 'function') { - window.addEventListener('message', idleTick, false); - } + // something better for old IE. + window.addEventListener('message', idleTick, false); var animationTick = function(rafTime) { isAnimationFrameScheduled = false; From 1e99062145c331f0e258c9a6feaebf1cddaee18e Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 26 Sep 2018 12:54:05 +0100 Subject: [PATCH 3/4] fix typo --- packages/scheduler/src/Scheduler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scheduler/src/Scheduler.js b/packages/scheduler/src/Scheduler.js index 3b2c081511c88..cfcbc405856c5 100644 --- a/packages/scheduler/src/Scheduler.js +++ b/packages/scheduler/src/Scheduler.js @@ -470,7 +470,7 @@ var getFrameDeadline; // "addEventListener" might not be available on the window object // if this is a mocked "window" object. So we need to validate that too. -if (typeof window === 'undefined' || typeof window.addEventListener === 'function') { +if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') { // If this accidentally gets imported in a non-browser environment, fallback // to a naive implementation. var timeoutID = -1; From c35bf9f2aa1add950bd30bebbf0d8e5bfc1ebef8 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 26 Sep 2018 13:07:45 +0100 Subject: [PATCH 4/4] run prettier --- packages/scheduler/src/Scheduler.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/scheduler/src/Scheduler.js b/packages/scheduler/src/Scheduler.js index cfcbc405856c5..2c692d7dfe79c 100644 --- a/packages/scheduler/src/Scheduler.js +++ b/packages/scheduler/src/Scheduler.js @@ -470,7 +470,10 @@ var getFrameDeadline; // "addEventListener" might not be available on the window object // if this is a mocked "window" object. So we need to validate that too. -if (typeof window === 'undefined' || typeof window.addEventListener !== 'function') { +if ( + typeof window === 'undefined' || + typeof window.addEventListener !== 'function' +) { // If this accidentally gets imported in a non-browser environment, fallback // to a naive implementation. var timeoutID = -1;