DEV: Skip missing icon warnings in production (#11334)

The list of SVG icons is unavailable in production, and the previous
refactor here was causing incorrect and noisy console warnings.

This also parses the `svgIconList` string in a dev environment, icons
should now match more accurately.
This commit is contained in:
Penar Musaraj 2020-11-23 21:41:54 -05:00 committed by GitHub
parent 0d8d568654
commit 4b538e7cb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import I18n from "I18n"; import I18n from "I18n";
import { h } from "virtual-dom"; import { h } from "virtual-dom";
import attributeHook from "discourse-common/lib/attribute-hook"; import attributeHook from "discourse-common/lib/attribute-hook";
import { isDevelopment } from "discourse-common/config/environment";
const SVG_NAMESPACE = "http://www.w3.org/2000/svg"; const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
let _renderers = []; let _renderers = [];
@ -115,13 +116,11 @@ export function setIconList(iconList) {
} }
export function isExistingIconId(id) { export function isExistingIconId(id) {
// TODO: investigate why _iconList is actually an array as a string: '["foo", "bar"]'
// in local and a real array in production
return _iconList && _iconList.indexOf(id) >= 0; return _iconList && _iconList.indexOf(id) >= 0;
} }
function warnIfMissing(id) { function warnIfMissing(id) {
if (warnMissingIcons && !isExistingIconId(id)) { if (warnMissingIcons && isDevelopment() && !isExistingIconId(id)) {
console.warn(`The icon "${id}" is missing from the SVG subset.`); // eslint-disable-line no-console console.warn(`The icon "${id}" is missing from the SVG subset.`); // eslint-disable-line no-console
} }
} }

View File

@ -95,7 +95,7 @@ export default {
session.userDarkSchemeId = parseInt(setupData.userDarkSchemeId, 10) || -1; session.userDarkSchemeId = parseInt(setupData.userDarkSchemeId, 10) || -1;
if (isDevelopment()) { if (isDevelopment()) {
setIconList(setupData.svgIconList); setIconList(JSON.parse(setupData.svgIconList));
} }
if (setupData.s3BaseUrl) { if (setupData.s3BaseUrl) {