fix: recover component lifecycle and avoid execute from scope __proto__

This commit is contained in:
1ncounter 2023-11-22 19:50:22 +08:00 committed by 刘菊萍(絮黎)
parent 7c72261fef
commit 394b56d0ce
2 changed files with 5 additions and 21 deletions

View File

@ -50,6 +50,11 @@ export function executeLifeCycleMethod(context: any, schema: IPublicTypeNodeSche
return;
}
// avoid execute lifeCycle method from __proto__'s method (it is React class Component Class lifeCycle)
if (!Object.prototype.hasOwnProperty.call(context, method) && method !== 'constructor') {
return;
}
// TODO: cache
if (isJSExpression(fn) || isJSFunction(fn)) {
fn = thisRequiredInJSE ? parseThisRequiredExpression(fn, context) : parseExpression(fn, context);

View File

@ -46,26 +46,5 @@ export default function componentRendererFactory(): IBaseRenderComponent {
return this.__renderComp(Component, this.__renderContextProvider({ compContext: this }));
}
getComponentName() {
return this.props?.componentName;
}
/** 需要重载下面几个方法,如果在低代码组件中绑定了对应的生命周期时会出现死循环 */
componentDidMount() {
this.__debug(`componentDidMount - ${this.getComponentName()}`);
}
getSnapshotBeforeUpdate() {
this.__debug(`getSnapshotBeforeUpdate - ${this.getComponentName()}`);
}
componentDidUpdate() {
this.__debug(`componentDidUpdate - ${this.getComponentName()}`);
}
componentWillUnmount() {
this.__debug(`componentWillUnmount - ${this.getComponentName()}`);
}
componentDidCatch() {
this.__debug(`componentDidCatch - ${this.getComponentName()}`);
}
};
}