Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOM-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,26 @@ describe('ReactDOM', () => {
}
});

it('should suppress DevTools console message when __REACT_DEVTOOLS_HIDE_CONSOLE__ is set', () => {
try {
global.__REACT_DEVTOOLS_HIDE_CONSOLE__ = true;
jest.resetModules();

const infoSpy = jest.spyOn(console, 'info').mockImplementation(() => {});

require('react-dom/client');

const devToolsMessage = infoSpy.mock.calls.find(call =>
call[0]?.includes?.('Download the React DevTools'),
);
expect(devToolsMessage).toBeUndefined();

infoSpy.mockRestore();
} finally {
delete global.__REACT_DEVTOOLS_HIDE_CONSOLE__;
}
});

it('should not crash calling findDOMNode inside a function component', async () => {
class Component extends React.Component {
render() {
Expand Down
9 changes: 8 additions & 1 deletion packages/react-dom/src/client/ReactDOMClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ export {ReactVersion as version, createRoot, hydrateRoot};
const foundDevTools = injectIntoDevTools();

if (__DEV__) {
if (!foundDevTools && canUseDOM && window.top === window.self) {
if (
!foundDevTools &&
canUseDOM &&
window.top === window.self &&
// Allow suppressing this message via __REACT_DEVTOOLS_HIDE_CONSOLE__ in
// environments like CEP or nwjs where the DevTools extension cannot be installed.
typeof __REACT_DEVTOOLS_HIDE_CONSOLE__ === 'undefined'
) {
// If we're in Chrome or Firefox, provide a download link if not installed.
if (
(navigator.userAgent.indexOf('Chrome') > -1 &&
Expand Down
9 changes: 8 additions & 1 deletion packages/react-dom/src/client/ReactDOMClientFB.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,14 @@ Internals.Events /* Events */ = [
const foundDevTools = injectIntoDevTools();

if (__DEV__) {
if (!foundDevTools && canUseDOM && window.top === window.self) {
if (
!foundDevTools &&
canUseDOM &&
window.top === window.self &&
// Allow suppressing this message via __REACT_DEVTOOLS_HIDE_CONSOLE__ in
// environments like CEP or nwjs where the DevTools extension cannot be installed.
typeof __REACT_DEVTOOLS_HIDE_CONSOLE__ === 'undefined'
) {
// If we're in Chrome or Firefox, provide a download link if not installed.
if (
(navigator.userAgent.indexOf('Chrome') > -1 &&
Expand Down
2 changes: 2 additions & 0 deletions scripts/flow/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ declare const __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{
inject: ?((stuff: Object) => void)
};*/

declare const __REACT_DEVTOOLS_HIDE_CONSOLE__: void | true;

declare const reportError: (error: mixed) => void;

declare module 'create-react-class' {
Expand Down