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,12 +18,7 @@ export default function rendererFactory() {
const debug = Debug('renderer:entry'); const debug = Debug('renderer:entry');
class FaultComponent extends PureComponent { const exceptionStyle = {
render() {
console.error(this.props.error);
console.error('render error', this.props);
return createElement(Div, {
style: {
width: '100%', width: '100%',
height: '50px', height: '50px',
lineHeight: '50px', lineHeight: '50px',
@ -31,14 +26,26 @@ export default function rendererFactory() {
fontSize: '15px', fontSize: '15px',
color: '#ff0000', color: '#ff0000',
border: '2px solid #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, {
className: 'engine-fault-component',
style: exceptionStyle,
}, '组件渲染异常,请查看控制台日志'); }, '组件渲染异常,请查看控制台日志');
} }
} }
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 || '组件未找到');
} }
} }