Skip to content

Commit 3801fc3

Browse files
Biki-dasBiki das
authored andcommitted
Fix:- Fixed dev tools inspect mode on Shadow dom (facebook#26888)
Fixes facebook#26200 ### PR explanation I tried to induce the change by the `event.composed` to check whether the event was created in a ShadowRoot, And replaced `pointerOver` with `pointerMove`, pointerOver event did not fired correctly Before PR:- https://github.com/facebook/react/assets/72331432/67a33dcd-447f-4c68-9c3c-ad954baddeb8 After PR:- https://github.com/facebook/react/assets/72331432/9f986ff2-785f-4cba-a504-44f82ea9fc5a --------- Co-authored-by: Biki das <bikidas@Bikis-MacBook-Pro.local>
1 parent 7ca9e6b commit 3801fc3

File tree

1 file changed

+16
-5
lines changed
  • packages/react-devtools-shared/src/backend/views/Highlighter

1 file changed

+16
-5
lines changed

packages/react-devtools-shared/src/backend/views/Highlighter/index.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function setupHighlighter(
4646
window.addEventListener('mouseover', onMouseEvent, true);
4747
window.addEventListener('mouseup', onMouseEvent, true);
4848
window.addEventListener('pointerdown', onPointerDown, true);
49-
window.addEventListener('pointerover', onPointerOver, true);
49+
window.addEventListener('pointermove', onPointerMove, true);
5050
window.addEventListener('pointerup', onPointerUp, true);
5151
} else {
5252
agent.emit('startInspectingNative');
@@ -74,7 +74,7 @@ export default function setupHighlighter(
7474
window.removeEventListener('mouseover', onMouseEvent, true);
7575
window.removeEventListener('mouseup', onMouseEvent, true);
7676
window.removeEventListener('pointerdown', onPointerDown, true);
77-
window.removeEventListener('pointerover', onPointerOver, true);
77+
window.removeEventListener('pointermove', onPointerMove, true);
7878
window.removeEventListener('pointerup', onPointerUp, true);
7979
} else {
8080
agent.emit('stopInspectingNative');
@@ -151,14 +151,17 @@ export default function setupHighlighter(
151151
event.preventDefault();
152152
event.stopPropagation();
153153

154-
selectFiberForNode(((event.target: any): HTMLElement));
154+
selectFiberForNode(getEventTarget(event));
155155
}
156156

157-
function onPointerOver(event: MouseEvent) {
157+
let lastHoveredNode: HTMLElement | null = null;
158+
function onPointerMove(event: MouseEvent) {
158159
event.preventDefault();
159160
event.stopPropagation();
160161

161-
const target = ((event.target: any): HTMLElement);
162+
const target: HTMLElement = getEventTarget(event);
163+
if (lastHoveredNode === target) return;
164+
lastHoveredNode = target;
162165

163166
if (target.tagName === 'IFRAME') {
164167
const iframe: HTMLIFrameElement = (target: any);
@@ -197,4 +200,12 @@ export default function setupHighlighter(
197200
// because those are usually unintentional as you lift the cursor.
198201
{leading: false},
199202
);
203+
204+
function getEventTarget(event: MouseEvent): HTMLElement {
205+
if (event.composed) {
206+
return (event.composedPath()[0]: any);
207+
}
208+
209+
return (event.target: any);
210+
}
200211
}

0 commit comments

Comments
 (0)