Make DevTools check document.contentType before injecting (#17739)
It should only inject the global hook into HTML documents. This will avoid breaking syntax highlighting for e.g. XML documents.
Brian Vaughn committed
Dec 29, 2019 at 13:02 UTC
2b903da355fa53b3ac5a7f340134575119de2f40
1 file changed
+11
-5
packages/react-devtools-extensions/src/injectGlobalHook.js
+11
-5
@@ -86,8 +86,14 @@ if (sessionStorageGetItem(SESSION_STORAGE_RELOAD_AND_PROFILE_KEY) === 'true') {
86
injectCode(rendererCode);
87
}
88
89
-// Inject a `__REACT_DEVTOOLS_GLOBAL_HOOK__` global so that React can detect that the
90
-// devtools are installed (and skip its suggestion to install the devtools).
91
-injectCode(
92
- ';(' + installHook.toString() + '(window))' + saveNativeValues + detectReact,
93
-);
89
+// Inject a __REACT_DEVTOOLS_GLOBAL_HOOK__ global for React to interact with.
90
+// Only do this for HTML documents though, to avoid e.g. breaking syntax highlighting for XML docs.
91
+if (document.contentType === 'text/html') {
92
+ injectCode(
93
+ ';(' +
94
+ installHook.toString() +
95
+ '(window))' +
96
+ saveNativeValues +
97
+ detectReact,
98
+ );
99
+}