fix: fix render module state expression initialization exception

This commit is contained in:
liujuping 2022-08-04 17:58:24 +08:00 committed by LeoYuan 袁力皓
parent f859752118
commit 5bd68ee6b4
2 changed files with 9 additions and 5 deletions

View File

@ -4,7 +4,7 @@ import cn from 'classnames';
import { Node } from '@alilc/lowcode-designer';
import LowCodeRenderer from '@alilc/lowcode-react-renderer';
import { observer } from 'mobx-react';
import { getClosestNode, isFromVC } from '@alilc/lowcode-utils';
import { getClosestNode, isFromVC, isReactComponent } from '@alilc/lowcode-utils';
import { GlobalEvent } from '@alilc/lowcode-types';
import { SimulatorRendererContainer, DocumentInstance } from './renderer';
import { host } from './host';
@ -241,6 +241,11 @@ class Renderer extends Component<{
});
}
if (!isReactComponent(Component)) {
console.error(`${viewProps._componentName} is not a react component!`);
return null;
}
return createElement(
getDeviceView(Component, device, designMode),
viewProps,

View File

@ -20,10 +20,9 @@ export default function pageRendererFactory(): IBaseRenderComponent {
async componentDidUpdate(prevProps: IBaseRendererProps, _prevState: {}, snapshot: unknown) {
const { __ctx } = this.props;
const prevState = this.__parseData(prevProps.__schema.state, __ctx);
const newState = this.__parseData(this.props.__schema.state, __ctx);
// 当编排的时候修改schema.state值需要将最新 schema.state 值 setState
if (JSON.stringify(newState) != JSON.stringify(prevState)) {
if (JSON.stringify(prevProps.__schema.state) != JSON.stringify(this.props.__schema.state)) {
const newState = this.__parseData(this.props.__schema.state, __ctx);
this.setState(newState);
}