From 9aca239f11f31109dc1a229aa1571c2bf02f5524 Mon Sep 17 00:00:00 2001 From: Alphabet Codes <40604284+alphabet-codes@users.noreply.github.com> Date: Wed, 11 Nov 2020 15:36:51 +0100 Subject: [PATCH] Improved dev experience when DevTools hook is disabled (#20208) Co-authored-by: Brian Vaughn --- packages/react-refresh/src/ReactFreshRuntime.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/react-refresh/src/ReactFreshRuntime.js b/packages/react-refresh/src/ReactFreshRuntime.js index 9cf8af21182b9..669eb7c1520f0 100644 --- a/packages/react-refresh/src/ReactFreshRuntime.js +++ b/packages/react-refresh/src/ReactFreshRuntime.js @@ -465,6 +465,17 @@ export function injectIntoGlobalHook(globalObject: any): void { }; } + 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) {