File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed
packages/react-devtools-shared/src/backend/views/Highlighter Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -184,7 +184,7 @@ export default function setupHighlighter(
184184 // $FlowFixMe[method-unbinding]
185185 if ( typeof node . scrollIntoView === 'function' ) {
186186 node . scrollIntoView ( {
187- block : 'start ' ,
187+ block : 'nearest ' ,
188188 inline : 'nearest' ,
189189 behavior : 'smooth' ,
190190 } ) ;
@@ -246,11 +246,23 @@ export default function setupHighlighter(
246246 y = rect . y ;
247247 }
248248 }
249- window . scrollTo ( {
250- top : y ,
251- left : x ,
252- behavior : 'smooth' ,
253- } ) ;
249+ const element = document . documentElement ;
250+ if ( ! element ) {
251+ return ;
252+ }
253+ // Check if the target corner is already in the viewport.
254+ if (
255+ x < window . scrollX ||
256+ y < window . scrollY ||
257+ x > window . scrollX + element . clientWidth ||
258+ y > window . scrollY + element . clientHeight
259+ ) {
260+ window . scrollTo ( {
261+ top : y ,
262+ left : x ,
263+ behavior : 'smooth' ,
264+ } ) ;
265+ }
254266 // It's possible that after mount, we're able to scroll deeper once the new nodes
255267 // have mounted. Let's try again after mount. Ideally we'd know which commit this
256268 // is going to be but for now we just try after 100ms.
You can’t perform that action at this time.
0 commit comments