fix: 修复React17选中组件bug

This commit is contained in:
tanruhuo 2022-04-14 00:20:04 +08:00 committed by LeoYuan 袁力皓
parent 57657fd76d
commit 750d282c03
2 changed files with 8 additions and 2 deletions

View File

@ -73,7 +73,10 @@ function cacheReactKey(el: Element): Element {
if (REACT_KEY !== '') {
return el;
}
REACT_KEY = Object.keys(el).find((key) => key.startsWith('__reactInternalInstance$')) || '';
// react17 采用 __reactFiber 开头
REACT_KEY = Object.keys(el).find(
(key) => key.startsWith('__reactInternalInstance$') || key.startsWith('__reactFiber$'),
) || '';
if (!REACT_KEY && (el as HTMLElement).parentElement) {
return cacheReactKey((el as HTMLElement).parentElement!);
}

View File

@ -530,7 +530,10 @@ function cacheReactKey(el: Element): Element {
if (REACT_KEY !== '') {
return el;
}
REACT_KEY = Object.keys(el).find((key) => key.startsWith('__reactInternalInstance$')) || '';
// react17 采用 __reactFiber 开头
REACT_KEY = Object.keys(el).find(
(key) => key.startsWith('__reactInternalInstance$') || key.startsWith('__reactFiber$'),
) || '';
if (!REACT_KEY && (el as HTMLElement).parentElement) {
return cacheReactKey((el as HTMLElement).parentElement!);
}