fix: fiberkey compatibility

This commit is contained in:
Qi 2023-03-16 15:18:06 +08:00 committed by 刘菊萍(絮黎)
parent ba6bdda6a2
commit fb3aea4f27
2 changed files with 6 additions and 4 deletions

View File

@ -4,7 +4,7 @@ import { host } from './host';
import SimulatorRendererView from './renderer-view';
import { computed, observable as obx, untracked, makeObservable, configure } from 'mobx';
import { getClientRects } from './utils/get-client-rects';
import { reactFindDOMNodes, FIBER_KEY } from './utils/react-find-dom-nodes';
import { reactFindDOMNodes, getReactInternalFiber } from './utils/react-find-dom-nodes';
import {
Asset,
isElement,
@ -565,7 +565,7 @@ function getClosestNodeInstance(
if (isElement(el)) {
el = cacheReactKey(el);
} else {
return getNodeInstance(el[FIBER_KEY], specId);
return getNodeInstance(getReactInternalFiber(el), specId);
}
}
while (el) {

View File

@ -3,7 +3,9 @@ import { findDOMNode } from 'react-dom';
import { isElement } from '@alilc/lowcode-utils';
import { isDOMNode } from './is-dom-node';
export const FIBER_KEY = '_reactInternalFiber';
export const getReactInternalFiber = (el: any) => {
return el._reactInternals || el._reactInternalFiber;
};
function elementsFromFiber(fiber: any, elements: Array<Element | Text>) {
if (fiber) {
@ -28,7 +30,7 @@ export function reactFindDOMNodes(elem: ReactInstance | null): Array<Element | T
return [elem];
}
const elements: Array<Element | Text> = [];
const fiberNode = (elem as any)[FIBER_KEY];
const fiberNode = getReactInternalFiber(elem);
elementsFromFiber(fiberNode?.child, elements);
if (elements.length > 0) return elements;
try {