mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-17 04:22:28 +00:00
Merge branch 'hotfix/rax-simulator' into 'release/1.0.63'
修复 Rax Simulator 的两个问题 1. Rax 模式下报错信息丢失的问题 2. 使用 rax v1.2.0 或更高版本时因为 `__parentInstance` 被压缩掉而导致无法选中组件的问题 See merge request !1360597
This commit is contained in:
commit
e861c301c2
@ -410,7 +410,9 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
instance = Instance.get(dom);
|
instance = Instance.get(dom);
|
||||||
while (instance && instance[INTERNAL]) {
|
|
||||||
|
let loopNum = 0; // 防止由于某种意外而导致死循环
|
||||||
|
while (instance && instance[INTERNAL] && loopNum < 1000) {
|
||||||
if (isValidDesignModeRaxComponentInstance(instance)) {
|
if (isValidDesignModeRaxComponentInstance(instance)) {
|
||||||
// if (instance && SYMBOL_VNID in instance) {
|
// if (instance && SYMBOL_VNID in instance) {
|
||||||
// const docId = (instance.props as any).schema.docId;
|
// const docId = (instance.props as any).schema.docId;
|
||||||
@ -422,7 +424,8 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
instance = instance[INTERNAL].__parentInstance;
|
instance = getRaxVDomParentInstance(instance);
|
||||||
|
loopNum += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -636,4 +639,21 @@ function getLowCodeComponentProps(props: any) {
|
|||||||
return newProps;
|
return newProps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 Rax 里面 VDOM 的上一级的实例
|
||||||
|
* 注意:Rax 的 development 的包是带有 __parentInstance,
|
||||||
|
* 但是 production 的包 __parentInstance 会被压缩掉,
|
||||||
|
* 所以这里遍历下其中的所有值,尝试找到有 _internal 的那个(别的值不会带有这个属性的)
|
||||||
|
*/
|
||||||
|
function getRaxVDomParentInstance(instance: { _internal: any }) {
|
||||||
|
const internalInstance = instance._internal;
|
||||||
|
return internalInstance.__parentInstance ||
|
||||||
|
Object.values(internalInstance).find(v => (
|
||||||
|
v !== null &&
|
||||||
|
v !== instance &&
|
||||||
|
typeof v === 'object' &&
|
||||||
|
typeof (v as {_internal: unknown})._internal === 'object'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
export default new SimulatorRendererContainer();
|
export default new SimulatorRendererContainer();
|
||||||
|
|||||||
@ -111,9 +111,17 @@ export default function rendererFactory() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SetComponent.patchedCatch = true;
|
SetComponent.patchedCatch = true;
|
||||||
SetComponent.getDerivedStateFromError = (error: Error) => {
|
|
||||||
return { engineRenderError: true, error };
|
// Rax 的 getDerivedStateFromError 有 BUG,这里先用 componentDidCatch 来替代
|
||||||
|
// @see https://github.com/alibaba/rax/issues/2211
|
||||||
|
const originalDidCatch = SetComponent.prototype.componentDidCatch;
|
||||||
|
SetComponent.prototype.componentDidCatch = function didCatch(this: any, error: Error, errorInfo: any) {
|
||||||
|
this.setState({ engineRenderError: true, error });
|
||||||
|
if (originalDidCatch && typeof originalDidCatch === 'function') {
|
||||||
|
originalDidCatch.call(this, error, errorInfo);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const engine = this;
|
const engine = this;
|
||||||
const originRender = SetComponent.prototype.render;
|
const originRender = SetComponent.prototype.render;
|
||||||
SetComponent.prototype.render = function () {
|
SetComponent.prototype.render = function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user