fix: 完善异常组件渲染逻辑 to #48596877

This commit is contained in:
龙彦 2023-05-24 19:05:22 +08:00
parent 5f7db9d10a
commit 52272c020f
2 changed files with 26 additions and 18 deletions

View File

@ -421,14 +421,15 @@ export default function baseRendererFactory() {
if (!Comp) {
console.error(`${schema.componentName} is not found! component list is:`, components || this.props.__container?.components);
return engine.createElement(
engine.getNotFoundComponent(),
{
componentName: schema.componentName,
componentId: schema.id,
},
this.__getSchemaChildrenVirtualDom(schema, scope, Comp),
);
// return engine.createElement(
// engine.getNotFoundComponent(),
// {
// componentName: schema.componentName,
// componentId: schema.id,
// },
// this.__getSchemaChildrenVirtualDom(schema, scope, Comp),
// );
Comp = engine.getNotFoundComponent();
}
if (schema.hidden && (engine?.props?.designMode && engine?.props?.designMode !== 'design')) {

View File

@ -18,27 +18,34 @@ export default function rendererFactory() {
const debug = Debug('renderer:entry');
const exceptionStyle = {
width: '100%',
height: '50px',
lineHeight: '50px',
textAlign: 'center',
fontSize: '15px',
color: '#ff0000',
border: '2px solid #ff0000',
borderRadius: '4px',
};
class FaultComponent extends PureComponent {
render() {
console.error(this.props.error);
console.error('render error', this.props);
return createElement(Div, {
style: {
width: '100%',
height: '50px',
lineHeight: '50px',
textAlign: 'center',
fontSize: '15px',
color: '#ff0000',
border: '2px solid #ff0000',
},
className: 'engine-fault-component',
style: exceptionStyle,
}, '组件渲染异常,请查看控制台日志');
}
}
class NotFoundComponent extends PureComponent {
render() {
return createElement(Div, this.props, this.props.children || 'Component Not Found');
return createElement(Div, {
className: 'engine-unknown-component',
style: exceptionStyle,
}, this.props.children || '组件未找到');
}
}