Skip to content

Commit

Permalink
Make DevTools check document.contentType before injecting
Browse files Browse the repository at this point in the history
It should only inject the global hook into HTML documents. This will avoid breaking syntax highlighting for e.g. XML documents.
  • Loading branch information
Brian Vaughn committed Dec 29, 2019
1 parent 0eac01a commit 02f13a4
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/react-devtools-extensions/src/injectGlobalHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

0 comments on commit 02f13a4

Please sign in to comment.