-
Notifications
You must be signed in to change notification settings - Fork 11
SPIKE: Fix console warnings when loading UI #1386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
eb2af99
e3ecbaf
e37efbe
c01d480
2bb8232
6614735
cd57ff5
2ba7350
f7b96a6
bf24876
54483aa
d61e1c9
aa9fcb8
0e7f5bf
0b1136d
ec5d060
bac78c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| const designSystemWarningsKey = "__designSystemWarningsDeduped"; | ||
| const designSystemIconWarning = | ||
| "DEPRECATED: icons as React elements will not be supported in future releases"; | ||
|
|
||
| const dedupeDesignSystemWarnings = () => { | ||
| if ( | ||
| process.env.NODE_ENV !== "development" || | ||
| typeof window !== "object" || | ||
| window[designSystemWarningsKey] | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| window[designSystemWarningsKey] = true; | ||
|
|
||
| const originalWarn = console.warn.bind(console); | ||
| let didWarnIcon = false; | ||
|
|
||
| console.warn = (...args) => { | ||
| if (args[0] === designSystemIconWarning) { | ||
| if (didWarnIcon) { | ||
| return; | ||
| } | ||
|
|
||
| didWarnIcon = true; | ||
| } | ||
|
|
||
| originalWarn(...args); | ||
| }; | ||
| }; | ||
|
|
||
| export default dedupeDesignSystemWarnings; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| const scratchWarningsKey = "__scratchWarningsDeduped"; | ||
|
|
||
| const scratchWarningMatchers = { | ||
| error: [ | ||
| [ | ||
| "Support for defaultProps will be removed", | ||
| "React 18 compatibility warnings about function-component defaultProps", | ||
| ], | ||
| [ | ||
| "React does not recognize the `%s` prop on a DOM element", | ||
| "React warnings about scratch-editor props leaking onto DOM nodes", | ||
| ], | ||
| [ | ||
| "Unknown event handler property `%s`", | ||
| "React warnings about unsupported event handler props", | ||
| ], | ||
| [ | ||
| "findDOMNode is deprecated", | ||
| "React warnings about deprecated findDOMNode usage", | ||
| ], | ||
| ], | ||
| warn: [ | ||
| [ | ||
| "componentWillMount has been renamed", | ||
| "React warnings about legacy componentWillMount usage", | ||
| ], | ||
| [ | ||
| "componentWillReceiveProps has been renamed", | ||
| "React warnings about legacy componentWillReceiveProps usage", | ||
| ], | ||
| ], | ||
| }; | ||
|
|
||
| const dedupeScratchWarnings = () => { | ||
| if ( | ||
| process.env.NODE_ENV !== "development" || | ||
| typeof window !== "object" || | ||
| window[scratchWarningsKey] | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| window[scratchWarningsKey] = true; | ||
|
|
||
| const seenSummaries = new Set(); | ||
| const originalWarn = console.warn.bind(console); | ||
|
|
||
| const wrapConsoleMethod = (method) => { | ||
| const originalMethod = console[method].bind(console); | ||
|
|
||
| return (...args) => { | ||
| const message = typeof args[0] === "string" ? args[0] : ""; | ||
| const summary = scratchWarningMatchers[method]?.find(([needle]) => | ||
| message.includes(needle), | ||
| ); | ||
|
|
||
| if (!summary) { | ||
| originalMethod(...args); | ||
| return; | ||
| } | ||
|
|
||
| const [, text] = summary; | ||
|
|
||
| if (seenSummaries.has(text)) { | ||
| return; | ||
| } | ||
|
|
||
| seenSummaries.add(text); | ||
| originalWarn( | ||
| `[scratch-editor] emitted ${text}. Further duplicates suppressed.`, | ||
| ); | ||
| }; | ||
| }; | ||
|
|
||
| console.error = wrapConsoleMethod("error"); | ||
| console.warn = wrapConsoleMethod("warn"); | ||
| }; | ||
|
|
||
| export default dedupeScratchWarnings; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,18 @@ | ||
| import i18n from "./i18n"; | ||
|
|
||
| const UNTITLED_PROJECT_NAME = "Untitled project"; | ||
|
|
||
| export const defaultPythonProject = { | ||
| project_type: "python", | ||
| name: i18n.t("project.untitled"), | ||
| name: UNTITLED_PROJECT_NAME, | ||
| locale: null, | ||
| components: [{ extension: "py", name: "main", content: "", default: true }], | ||
| image_list: [], | ||
| }; | ||
|
|
||
| export const defaultHtmlProject = { | ||
| project_type: "html", | ||
| name: i18n.t("project.untitled"), | ||
| name: UNTITLED_PROJECT_NAME, | ||
| components: [ | ||
| { | ||
| extension: "html", | ||
|
|
@@ -25,3 +27,39 @@ export const DEFAULT_PROJECTS = { | |
| python: defaultPythonProject, | ||
| html: defaultHtmlProject, | ||
| }; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The changes in this file are the only ones that aren't obviously clear to me - Will this have any user facing behaviour change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the most complicated change imho. There is a race condition:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| export const createDefaultPythonProject = async (locale = i18n.language) => { | ||
| try { | ||
| if (locale && i18n.resolvedLanguage !== locale) { | ||
| await i18n.changeLanguage?.(locale); | ||
| } | ||
| } catch { | ||
| // Fall back to the default untitled name if locale files fail. | ||
| } | ||
|
|
||
| return { | ||
| ...defaultPythonProject, | ||
| name: i18n.t("project.untitled", { | ||
| lng: locale, | ||
| defaultValue: UNTITLED_PROJECT_NAME, | ||
| }), | ||
| }; | ||
| }; | ||
|
|
||
| export const createDefaultHtmlProject = async (locale = i18n.language) => { | ||
| try { | ||
| if (locale && i18n.resolvedLanguage !== locale) { | ||
| await i18n.changeLanguage?.(locale); | ||
| } | ||
| } catch { | ||
| // Fall back to the default untitled name if locale files fail. | ||
| } | ||
|
|
||
| return { | ||
| ...defaultHtmlProject, | ||
| name: i18n.t("project.untitled", { | ||
| lng: locale, | ||
| defaultValue: UNTITLED_PROJECT_NAME, | ||
| }), | ||
| }; | ||
| }; | ||

Uh oh!
There was an error while loading. Please reload this page.