GeezerVison is showing github.com — fix: fiberkey compatibility · bruceywave/lowcode-engine@fb3aea4
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/react-simulator-renderer/src
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/react-simulator-renderer/src/renderer.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,7 @@ import { host } from './host'; |
4 | 4 | import SimulatorRendererView from './renderer-view'; |
5 | 5 | import { computed, observable as obx, untracked, makeObservable, configure } from 'mobx'; |
6 | 6 | import { getClientRects } from './utils/get-client-rects'; |
7 | | -import { reactFindDOMNodes, FIBER_KEY } from './utils/react-find-dom-nodes'; |
| 7 | +import { reactFindDOMNodes, getReactInternalFiber } from './utils/react-find-dom-nodes'; |
8 | 8 | import { |
9 | 9 | Asset, |
10 | 10 | isElement, |
@@ -565,7 +565,7 @@ function getClosestNodeInstance( |
565 | 565 | if (isElement(el)) { |
566 | 566 | el = cacheReactKey(el); |
567 | 567 | } else { |
568 | | - return getNodeInstance(el[FIBER_KEY], specId); |
| 568 | + return getNodeInstance(getReactInternalFiber(el), specId); |
569 | 569 | } |
570 | 570 | } |
571 | 571 | while (el) { |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/react-simulator-renderer/src/utils/react-find-dom-nodes.ts +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,9 @@ import { findDOMNode } from 'react-dom'; |
3 | 3 | import { isElement } from '@alilc/lowcode-utils'; |
4 | 4 | import { isDOMNode } from './is-dom-node'; |
5 | 5 |
|
6 | | -export const FIBER_KEY = '_reactInternalFiber'; |
| 6 | +export const getReactInternalFiber = (el: any) => { |
| 7 | + return el._reactInternals || el._reactInternalFiber; |
| 8 | +}; |
7 | 9 |
|
8 | 10 | function elementsFromFiber(fiber: any, elements: Array<Element | Text>) { |
9 | 11 | if (fiber) { |
@@ -28,7 +30,7 @@ export function reactFindDOMNodes(elem: ReactInstance | null): Array<Element | T |
28 | 30 | return [elem]; |
29 | 31 | } |
30 | 32 | const elements: Array<Element | Text> = []; |
31 | | - const fiberNode = (elem as any)[FIBER_KEY]; |
| 33 | + const fiberNode = getReactInternalFiber(elem); |
32 | 34 | elementsFromFiber(fiberNode?.child, elements); |
33 | 35 | if (elements.length > 0) return elements; |
34 | 36 | try { |
|