Skip to content

Commit fa24a7d

Browse files
authored
fix: restore sandbox hint on mouse leave (#288)
1 parent 7f1dad6 commit fa24a7d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/sandbox.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const state = {
1616
settings: {
1717
testIdAttribute: 'data-testid',
1818
},
19+
pointerInside: false,
1920
};
2021

2122
function postMessage(action) {
@@ -106,12 +107,16 @@ function Sandbox() {
106107
<div
107108
className="pr-1 relative w-screen h-screen overflow-hidden"
108109
onMouseEnter={() => {
110+
state.pointerInside = true;
109111
state.highlighter?.clear();
110112
state.highlighter?.start({ stopOnClick: false, blockEvents: false });
111113
}}
112114
onMouseLeave={() => {
113115
state.highlighter?.stop();
114116
state.highlighter.highlight({ nodes: state.queriedNodes });
117+
state.pointerInside = false;
118+
119+
postMessage({ type: 'HOVER_NODE', payload: null });
115120
}}
116121
>
117122
<Scrollable forwardedRef={setRootNode} id="sandbox" />
@@ -120,7 +125,11 @@ function Sandbox() {
120125
}
121126

122127
function onSelectNode(node, { origin }) {
123-
if (!origin || origin === 'script') {
128+
// onSelectNode can be triggered after onMouseLeave has already been called.
129+
// This makes it impossible to clear hover state. That's why we maintain and
130+
// check a boolean to see if the pointer is inside the sandbox, before
131+
// dispatching events.
132+
if (!origin || origin === 'script' || !state.pointerInside) {
124133
return;
125134
}
126135

0 commit comments

Comments
 (0)