From 02f13a482a9d78e095f1e076a442bf4e58771cef Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sun, 29 Dec 2019 09:11:33 -0800 Subject: [PATCH] Make DevTools check document.contentType before injecting It should only inject the global hook into HTML documents. This will avoid breaking syntax highlighting for e.g. XML documents. --- .../src/injectGlobalHook.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/react-devtools-extensions/src/injectGlobalHook.js b/packages/react-devtools-extensions/src/injectGlobalHook.js index ea41a6c9688f7..dd38c8ce1b587 100644 --- a/packages/react-devtools-extensions/src/injectGlobalHook.js +++ b/packages/react-devtools-extensions/src/injectGlobalHook.js @@ -86,8 +86,14 @@ if (sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') { injectCode(rendererCode); } -// Inject a `__REACT_DEVTOOLS_GLOBAL_HOOK__` global so that React can detect that the -// devtools are installed (and skip its suggestion to install the devtools). -injectCode( - ';(' + installHook.toString() + '(window))' + saveNativeValues + detectReact, -); +// Inject a __REACT_DEVTOOLS_GLOBAL_HOOK__ global for React to interact with. +// Only do this for HTML documents though, to avoid e.g. breaking syntax highlighting for XML docs. +if (document.contentType === 'text/html') { + injectCode( + ';(' + + installHook.toString() + + '(window))' + + saveNativeValues + + detectReact, + ); +}