fix: 🐛 解决 rax v1.2.0 中因为 __parentInstance 被压缩掉而导致无法选中组件的问题

This commit is contained in:
牧毅 2021-08-13 02:24:14 +08:00
parent 19d0f1c5ed
commit 20a7fab565

View File

@ -410,7 +410,9 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
};
}
instance = Instance.get(dom);
while (instance && instance[INTERNAL]) {
let loopNum = 0; // 防止由于某种意外而导致死循环
while (instance && instance[INTERNAL] && loopNum < 1000) {
if (isValidDesignModeRaxComponentInstance(instance)) {
// if (instance && SYMBOL_VNID in instance) {
// 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;
@ -636,4 +639,21 @@ function getLowCodeComponentProps(props: any) {
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();