From cbd376c7fa4473a039ab2038b6bf76e9c3c36f55 Mon Sep 17 00:00:00 2001 From: Helegbedey Date: Fri, 6 Nov 2020 15:44:35 +0100 Subject: [PATCH 01/11] Improved dev experience when DevTools hook is disabled --- packages/react-refresh/src/ReactFreshRuntime.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index 9cf8af21182b9..0efa03b21b13a 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -464,6 +464,15 @@ export function injectIntoGlobalHook(globalObject: any): void { onCommitFiberUnmount() {}, }; } + // Checks if DevTools hook is disabled + if (hook.isDisabled) { + if (__DEV__) { + console.warn( + 'React DevTools hook is disabled. Try to enable the hook ' + + 'or update your React DevTools. ', + ); + } + } // Here, we just want to get a reference to scheduleRefresh. const oldInject = hook.inject; From fb7136d2797f823bd25add6d92c88875210fab40 Mon Sep 17 00:00:00 2001 From: Helegbedey Date: Fri, 6 Nov 2020 16:10:57 +0100 Subject: [PATCH 02/11] Improved dev experience when DevTools hook is disabled --- packages/react-refresh/src/ReactFreshRuntime.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index 0efa03b21b13a..b334c4d98a734 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -467,7 +467,8 @@ export function injectIntoGlobalHook(globalObject: any): void { // Checks if DevTools hook is disabled if (hook.isDisabled) { if (__DEV__) { - console.warn( + warning( + false, 'React DevTools hook is disabled. Try to enable the hook ' + 'or update your React DevTools. ', ); From 237286f113f32ca474527cd40bee30e21c996211 Mon Sep 17 00:00:00 2001 From: Helegbedey Date: Fri, 6 Nov 2020 16:21:48 +0100 Subject: [PATCH 03/11] Improved dev experience when DevTools hook is disabled --- packages/react-refresh/src/ReactFreshRuntime.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index b334c4d98a734..53286afb4c477 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -467,11 +467,8 @@ export function injectIntoGlobalHook(globalObject: any): void { // Checks if DevTools hook is disabled if (hook.isDisabled) { if (__DEV__) { - warning( - false, - 'React DevTools hook is disabled. Try to enable the hook ' + - 'or update your React DevTools. ', - ); + console.error('React DevTools hook is disabled. Try to enable the hook ' + + 'or update your React DevTools. ',); } } From 46b66924430bac29e6c94119222249a9c36c3128 Mon Sep 17 00:00:00 2001 From: Helegbedey Date: Fri, 6 Nov 2020 16:31:01 +0100 Subject: [PATCH 04/11] Improved dev experience when DevTools hook is disabled --- packages/react-refresh/src/ReactFreshRuntime.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index 53286afb4c477..115b9e965564d 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -20,6 +20,7 @@ import type { import type {ReactNodeList} from 'shared/ReactTypes'; import {REACT_MEMO_TYPE, REACT_FORWARD_REF_TYPE} from 'shared/ReactSymbols'; +import warning from 'fbjs/lib/warning'; type Signature = {| ownKey: string, @@ -467,8 +468,9 @@ export function injectIntoGlobalHook(globalObject: any): void { // Checks if DevTools hook is disabled if (hook.isDisabled) { if (__DEV__) { - console.error('React DevTools hook is disabled. Try to enable the hook ' + - 'or update your React DevTools. ',); + warning('React DevTools hook is disabled. Try to enable the hook ' + + 'or update your React DevTools. ', +); } } From 9cdc308899ada1cfbdb28293d4ec15ed08bbc4a1 Mon Sep 17 00:00:00 2001 From: Helegbedey Date: Fri, 6 Nov 2020 16:49:35 +0100 Subject: [PATCH 05/11] Improved dev experience when DevTools hook is disabled --- packages/react-refresh/src/ReactFreshRuntime.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index 115b9e965564d..fbf5cafbbc10f 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -20,7 +20,6 @@ import type { import type {ReactNodeList} from 'shared/ReactTypes'; import {REACT_MEMO_TYPE, REACT_FORWARD_REF_TYPE} from 'shared/ReactSymbols'; -import warning from 'fbjs/lib/warning'; type Signature = {| ownKey: string, @@ -465,12 +464,13 @@ export function injectIntoGlobalHook(globalObject: any): void { onCommitFiberUnmount() {}, }; } + // Checks if DevTools hook is disabled if (hook.isDisabled) { if (__DEV__) { - warning('React DevTools hook is disabled. Try to enable the hook ' + + console.error('React DevTools hook is disabled. Try to enable the hook ' + 'or update your React DevTools. ', -); + ); } } From 1d833fa124f9a947a63a226ee15db37be7be3c30 Mon Sep 17 00:00:00 2001 From: Helegbedey Date: Fri, 6 Nov 2020 17:14:20 +0100 Subject: [PATCH 06/11] Improved dev experience when DevTools hook is disabled --- packages/react-refresh/src/ReactFreshRuntime.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index fbf5cafbbc10f..f7a11007a0a81 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -464,16 +464,13 @@ export function injectIntoGlobalHook(globalObject: any): void { onCommitFiberUnmount() {}, }; } - // Checks if DevTools hook is disabled if (hook.isDisabled) { - if (__DEV__) { - console.error('React DevTools hook is disabled. Try to enable the hook ' + - 'or update your React DevTools. ', - ); - } + throw new Error( + 'React DevTools hook is disabled. Try to enable the hook ' + + 'or update your React DevTools. ', + ); } - // Here, we just want to get a reference to scheduleRefresh. const oldInject = hook.inject; hook.inject = function(injected) { From 6115e23262db2eca5fcb38992237386202e1d0c9 Mon Sep 17 00:00:00 2001 From: Helegbedey Date: Mon, 9 Nov 2020 19:09:55 +0100 Subject: [PATCH 07/11] Improved dev experience when DevTools hook is disabled --- packages/react-refresh/src/ReactFreshRuntime.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index f7a11007a0a81..681ccd2e439d8 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -467,8 +467,8 @@ export function injectIntoGlobalHook(globalObject: any): void { // Checks if DevTools hook is disabled if (hook.isDisabled) { throw new Error( - 'React DevTools hook is disabled. Try to enable the hook ' + - 'or update your React DevTools. ', + 'Something has shimmed the React DevTools global hook (REACT_DEVTOOLS_GLOBAL_HOOK).' + + 'Fast Refresh is not compatible with this shim and will be disabled. ', ); } // Here, we just want to get a reference to scheduleRefresh. From 700ca1cd18ec8ac2d8780b5d3c897b8c5068ef87 Mon Sep 17 00:00:00 2001 From: Helegbedey Date: Mon, 9 Nov 2020 22:33:05 +0100 Subject: [PATCH 08/11] Improved dev experience when DevTools hook is disabled --- packages/react-refresh/src/ReactFreshRuntime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index 681ccd2e439d8..6429479fc6cc4 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -466,7 +466,7 @@ export function injectIntoGlobalHook(globalObject: any): void { } // Checks if DevTools hook is disabled if (hook.isDisabled) { - throw new Error( + console['warn']( 'Something has shimmed the React DevTools global hook (REACT_DEVTOOLS_GLOBAL_HOOK).' + 'Fast Refresh is not compatible with this shim and will be disabled. ', ); From a581a3b90fe112e8a5e752ba10edba0b42f302ea Mon Sep 17 00:00:00 2001 From: Alphabet Codes <40604284+alphabet-codes@users.noreply.github.com> Date: Tue, 10 Nov 2020 17:36:58 +0100 Subject: [PATCH 09/11] Update packages/react-refresh/src/ReactFreshRuntime.js Fixed warning message spacing. Co-authored-by: Brian Vaughn --- packages/react-refresh/src/ReactFreshRuntime.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index 6429479fc6cc4..269aaf72ebf5c 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -467,8 +467,8 @@ export function injectIntoGlobalHook(globalObject: any): void { // Checks if DevTools hook is disabled if (hook.isDisabled) { console['warn']( - 'Something has shimmed the React DevTools global hook (REACT_DEVTOOLS_GLOBAL_HOOK).' + - 'Fast Refresh is not compatible with this shim and will be disabled. ', + 'Something has shimmed the React DevTools global hook (REACT_DEVTOOLS_GLOBAL_HOOK). ' + + 'Fast Refresh is not compatible with this shim and will be disabled.', ); } // Here, we just want to get a reference to scheduleRefresh. From 493715536853418b7328565e2ba89e1b8fb064a0 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 11 Nov 2020 09:11:49 -0500 Subject: [PATCH 10/11] Actually disable Fast Refresh --- packages/react-refresh/src/ReactFreshRuntime.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index 269aaf72ebf5c..9057b75b0ebb8 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -464,13 +464,18 @@ export function injectIntoGlobalHook(globalObject: any): void { onCommitFiberUnmount() {}, }; } - // Checks if DevTools hook is disabled + if (hook.isDisabled) { + // This isn't a real property on the hook, but it can be set to opt out + // of DevTools integration and associated warnings and logs. + // Using console['warn'] to evade Babel and ESLint console['warn']( 'Something has shimmed the React DevTools global hook (REACT_DEVTOOLS_GLOBAL_HOOK). ' + 'Fast Refresh is not compatible with this shim and will be disabled.', ); + return; } + // Here, we just want to get a reference to scheduleRefresh. const oldInject = hook.inject; hook.inject = function(injected) { From 8527d9d135ace0a5de6c169ce91008ae7d1803d1 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 11 Nov 2020 09:14:00 -0500 Subject: [PATCH 11/11] Correct name of global hook variable. --- packages/react-refresh/src/ReactFreshRuntime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index 9057b75b0ebb8..669eb7c1520f0 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -470,7 +470,7 @@ export function injectIntoGlobalHook(globalObject: any): void { // of DevTools integration and associated warnings and logs. // Using console['warn'] to evade Babel and ESLint console['warn']( - 'Something has shimmed the React DevTools global hook (REACT_DEVTOOLS_GLOBAL_HOOK). ' + + 'Something has shimmed the React DevTools global hook (__REACT_DEVTOOLS_GLOBAL_HOOK__). ' + 'Fast Refresh is not compatible with this shim and will be disabled.', ); return;