From 6b3ae6459819065b047244db43d432da2a7be6a1 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sun, 4 Aug 2019 14:33:38 -0700 Subject: [PATCH] Suppress known/expected warnings and errors in local DEV shell --- shells/dev/app/console.js | 27 +++++++++++++++++++++++++++ shells/dev/app/index.js | 11 +++++++++++ 2 files changed, 38 insertions(+) create mode 100644 shells/dev/app/console.js diff --git a/shells/dev/app/console.js b/shells/dev/app/console.js new file mode 100644 index 0000000000000..9e5f01401aa39 --- /dev/null +++ b/shells/dev/app/console.js @@ -0,0 +1,27 @@ +// @flow + +function ignoreStrings( + methodName: string, + stringsToIgnore: Array +): void { + const originalMethod = console[methodName]; + console[methodName] = (...args) => { + const maybeString = args[0]; + if (typeof maybeString === 'string') { + for (let i = 0; i < stringsToIgnore.length; i++) { + if (maybeString.startsWith(stringsToIgnore[i])) { + return; + } + } + } + originalMethod(...args); + }; +} + +export function ignoreErrors(errorsToIgnore: Array): void { + ignoreStrings('error', errorsToIgnore); +} + +export function ignoreWarnings(warningsToIgnore: Array): void { + ignoreStrings('warn', warningsToIgnore); +} diff --git a/shells/dev/app/index.js b/shells/dev/app/index.js index b0609a877ca2f..4115c1c4807fc 100644 --- a/shells/dev/app/index.js +++ b/shells/dev/app/index.js @@ -19,9 +19,20 @@ import ReactNativeWeb from './ReactNativeWeb'; import ToDoList from './ToDoList'; import Toggle from './Toggle'; import SuspenseTree from './SuspenseTree'; +import { ignoreErrors, ignoreWarnings } from './console'; import './styles.css'; +// DevTools intentionally tests compatibility with certain legacy APIs. +// Suppress their error messages in the local dev shell, +// because they might mask other more serious error messages. +ignoreErrors([ + 'Warning: Legacy context API', + 'Warning: Unsafe lifecycle methods', + 'Warning: %s is deprecated in StrictMode.', // findDOMNode +]); +ignoreWarnings(['Warning: componentWillReceiveProps is deprecated']); + const roots = []; function mountHelper(App) {