diff --git a/packages/scratch-gui/src/components/stage-header/stage-header.jsx b/packages/scratch-gui/src/components/stage-header/stage-header.jsx index 5c69607fd97..dbcb3b8bd9a 100644 --- a/packages/scratch-gui/src/components/stage-header/stage-header.jsx +++ b/packages/scratch-gui/src/components/stage-header/stage-header.jsx @@ -214,7 +214,7 @@ StageHeaderComponent.propTypes = { onSetStageSmall: PropTypes.func.isRequired, onSetStageUnFull: PropTypes.func.isRequired, onUpdateProjectThumbnail: PropTypes.func, - projectId: PropTypes.number.isRequired, + projectId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), showBranding: PropTypes.bool.isRequired, stageSizeMode: PropTypes.oneOf(Object.keys(STAGE_SIZE_MODES)), vm: PropTypes.instanceOf(VM).isRequired diff --git a/packages/scratch-gui/src/index-standalone.tsx b/packages/scratch-gui/src/index-standalone.tsx index 39cfdd45981..50aca780a7a 100644 --- a/packages/scratch-gui/src/index-standalone.tsx +++ b/packages/scratch-gui/src/index-standalone.tsx @@ -1,3 +1,4 @@ +import './lib/log-suppression'; import React from 'react'; import ReactDOM from 'react-dom'; import GUI from './containers/gui'; diff --git a/packages/scratch-gui/src/index.ts b/packages/scratch-gui/src/index.ts index 922693bc0f1..e2961883f17 100644 --- a/packages/scratch-gui/src/index.ts +++ b/packages/scratch-gui/src/index.ts @@ -1,3 +1,4 @@ +import './lib/log-suppression'; import {buildInitialState} from './reducers/gui'; import {legacyConfig} from './legacy-config'; diff --git a/packages/scratch-gui/src/lib/log-suppression.js b/packages/scratch-gui/src/lib/log-suppression.js new file mode 100644 index 00000000000..06dc3280bb5 --- /dev/null +++ b/packages/scratch-gui/src/lib/log-suppression.js @@ -0,0 +1,50 @@ +/** + * Suppress certain console warnings that are known upstream issues or intentional. + */ + +const ignoredWarnings = [ + 'Object freezing is not supported by Opal', + 'Canvas2D: Multiple readback operations using getImageData are faster ' + + 'with the willReadFrequently attribute set to true', + 'Support for defaultProps will be removed from function components', + 'React does not recognize the', + 'The prop `projectId` is marked as required in `StageHeaderComponent`, but its value is `null`', + 'Invalid prop `projectId` of type `string` supplied to `StageHeaderComponent`, expected `number`', + 'The prop projectId is marked as required in StageHeaderComponent, but its value is null', + 'Invalid prop projectId of type string supplied to StageHeaderComponent, expected number', + 'componentWillMount has been renamed', + 'componentWillReceiveProps has been renamed', + 'componentWillUpdate has been renamed', + 'findDOMNode is deprecated', + 'The AudioContext was not allowed to start', + 'apple-mobile-web-app-capable', + 'GenerateSW has been called multiple times' +]; + +/** + * Check if a message should be ignored. + * @param {string} message The message to check. + * @param {Array} args Additional arguments. + * @returns {boolean} True if the message should be ignored. + */ +const shouldIgnore = (message, ...args) => { + const allStrings = [message, ...args].filter(arg => typeof arg === 'string'); + return allStrings.some(str => + ignoredWarnings.some(ignored => str.includes(ignored)) + ); +}; + +/* eslint-disable no-console */ +const originalWarn = console.warn; +const originalError = console.error; + +console.warn = function (message, ...args) { + if (shouldIgnore(message, ...args)) return; + originalWarn.apply(console, [message, ...args]); +}; + +console.error = function (message, ...args) { + if (shouldIgnore(message, ...args)) return; + originalError.apply(console, [message, ...args]); +}; +/* eslint-enable no-console */ diff --git a/packages/scratch-gui/src/playground/blocks-only.jsx b/packages/scratch-gui/src/playground/blocks-only.jsx index 584af11e9f0..08e64a7ac6b 100644 --- a/packages/scratch-gui/src/playground/blocks-only.jsx +++ b/packages/scratch-gui/src/playground/blocks-only.jsx @@ -1,3 +1,4 @@ +import '../lib/log-suppression'; import React from 'react'; import ReactDomClient from 'react-dom/client'; import {connect} from 'react-redux'; diff --git a/packages/scratch-gui/src/playground/compatibility-testing.jsx b/packages/scratch-gui/src/playground/compatibility-testing.jsx index b33bfec164d..19b931381ff 100644 --- a/packages/scratch-gui/src/playground/compatibility-testing.jsx +++ b/packages/scratch-gui/src/playground/compatibility-testing.jsx @@ -1,3 +1,4 @@ +import '../lib/log-suppression'; import React from 'react'; import ReactDomClient from 'react-dom/client'; diff --git a/packages/scratch-gui/src/playground/index.ejs b/packages/scratch-gui/src/playground/index.ejs index a2fabaffb09..8b7514bac67 100644 --- a/packages/scratch-gui/src/playground/index.ejs +++ b/packages/scratch-gui/src/playground/index.ejs @@ -13,6 +13,8 @@ <% } %> + +