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) { if (!Comp) {
console.error(`${schema.componentName} is not found! component list is:`, components || this.props.__container?.components); console.error(`${schema.componentName} is not found! component list is:`, components || this.props.__container?.components);
return engine.createElement( // return engine.createElement(
engine.getNotFoundComponent(), // engine.getNotFoundComponent(),
{ // {
componentName: schema.componentName, // componentName: schema.componentName,
componentId: schema.id, // componentId: schema.id,
}, // },
this.__getSchemaChildrenVirtualDom(schema, scope, Comp), // this.__getSchemaChildrenVirtualDom(schema, scope, Comp),
); // );
Comp = engine.getNotFoundComponent();
} }
if (schema.hidden && (engine?.props?.designMode && engine?.props?.designMode !== 'design')) { 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 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 { class FaultComponent extends PureComponent {
render() { render() {
console.error(this.props.error); console.error(this.props.error);
console.error('render error', this.props); console.error('render error', this.props);
return createElement(Div, { return createElement(Div, {
style: { className: 'engine-fault-component',
width: '100%', style: exceptionStyle,
height: '50px',
lineHeight: '50px',
textAlign: 'center',
fontSize: '15px',
color: '#ff0000',
border: '2px solid #ff0000',
},
}, '组件渲染异常,请查看控制台日志'); }, '组件渲染异常,请查看控制台日志');
} }
} }
class NotFoundComponent extends PureComponent { class NotFoundComponent extends PureComponent {
render() { render() {
return createElement(Div, this.props, this.props.children || 'Component Not Found'); return createElement(Div, {
className: 'engine-unknown-component',
style: exceptionStyle,
}, this.props.children || '组件未找到');
} }
} }