Skip to content

Commit 4b81aea

Browse files
authored
housekeeping: prevent log warning for missing getComponent in production (#5919)
* prevent log warning for missing getComponent in production * ft: new optional config parameter for getComponent
2 parents 12e86da + b7ad2e4 commit 4b81aea

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/core/json-schema-components.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ export class JsonSchemaForm extends Component {
5050
schema = schema.toJS()
5151

5252
let { type, format="" } = schema
53-
54-
let Comp = (format ? getComponent(`JsonSchema_${type}_${format}`) : getComponent(`JsonSchema_${type}`)) || getComponent("JsonSchema_string")
53+
// In the json schema rendering code, we optimistically query our system for a number of components.
54+
// If the component doesn't exist, we optionally suppress these warnings.
55+
let getComponentSilently = (name) => getComponent(name, false, { failSilently: true })
56+
let Comp = (format ? getComponentSilently(`JsonSchema_${type}_${format}`) : getComponentSilently(`JsonSchema_${type}`)) || getComponentSilently("JsonSchema_string")
5557
return <Comp { ...this.props } errors={errors} fn={fn} getComponent={getComponent} value={value} onChange={onChange} schema={schema} disabled={disabled}/>
5658
}
5759

src/core/plugins/view/root-injects.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,20 @@ const wrapRender = (component) => {
101101
}
102102

103103

104-
export const getComponent = (getSystem, getStore, getComponents, componentName, container) => {
104+
export const getComponent = (getSystem, getStore, getComponents, componentName, container, config = {}) => {
105105

106106
if(typeof componentName !== "string")
107107
throw new TypeError("Need a string, to fetch a component. Was given a " + typeof componentName)
108108

109+
// getComponent has a config object as a third, optional parameter
110+
// using the config object requires the presence of the second parameter, container
111+
// e.g. getComponent("JsonSchema_string_whatever", false, { failSilently: true })
109112
let component = getComponents(componentName)
110113

111114
if(!component) {
112-
getSystem().log.warn("Could not find component", componentName)
115+
if (!config.failSilently) {
116+
getSystem().log.warn("Could not find component:", componentName)
117+
}
113118
return null
114119
}
115120

0 commit comments

Comments
 (0)