Skip to content

Commit 750d282

Browse files
haloworld007LeoYuan
authored andcommitted
fix: 修复React17选中组件bug
1 parent 57657fd commit 750d282

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/rax-simulator-renderer/src/renderer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ function cacheReactKey(el: Element): Element {
7373
if (REACT_KEY !== '') {
7474
return el;
7575
}
76-
REACT_KEY = Object.keys(el).find((key) => key.startsWith('__reactInternalInstance$')) || '';
76+
// react17 采用 __reactFiber 开头
77+
REACT_KEY = Object.keys(el).find(
78+
(key) => key.startsWith('__reactInternalInstance$') || key.startsWith('__reactFiber$'),
79+
) || '';
7780
if (!REACT_KEY && (el as HTMLElement).parentElement) {
7881
return cacheReactKey((el as HTMLElement).parentElement!);
7982
}

packages/react-simulator-renderer/src/renderer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,10 @@ function cacheReactKey(el: Element): Element {
530530
if (REACT_KEY !== '') {
531531
return el;
532532
}
533-
REACT_KEY = Object.keys(el).find((key) => key.startsWith('__reactInternalInstance$')) || '';
533+
// react17 采用 __reactFiber 开头
534+
REACT_KEY = Object.keys(el).find(
535+
(key) => key.startsWith('__reactInternalInstance$') || key.startsWith('__reactFiber$'),
536+
) || '';
534537
if (!REACT_KEY && (el as HTMLElement).parentElement) {
535538
return cacheReactKey((el as HTMLElement).parentElement!);
536539
}

0 commit comments

Comments
 (0)