Skip to content

Commit

Permalink
fix: recover component lifecycle and avoid execute from scope __proto__
Browse files Browse the repository at this point in the history
  • Loading branch information
1ncounter committed Nov 22, 2023
1 parent 7c72261 commit fb8ef33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
5 changes: 5 additions & 0 deletions packages/renderer-core/src/renderer/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 0 additions & 21 deletions packages/renderer-core/src/renderer/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`);
}
};
}

0 comments on commit fb8ef33

Please sign in to comment.