File tree Expand file tree Collapse file tree 1 file changed +28
-6
lines changed
packages/react-devtools-shared/src/backend/views/Highlighter Expand file tree Collapse file tree 1 file changed +28
-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 } ) ;
@@ -226,6 +226,7 @@ export default function setupHighlighter(
226226 }
227227
228228 if ( attemptScrollToHostInstance ( renderer , id ) ) {
229+ console . log ( 'scrolling into node' ) ;
229230 return ;
230231 }
231232
@@ -246,11 +247,32 @@ export default function setupHighlighter(
246247 y = rect . y ;
247248 }
248249 }
249- window . scrollTo ( {
250- top : y ,
251- left : x ,
252- behavior : 'smooth' ,
253- } ) ;
250+ const element = document . documentElement ;
251+ if ( ! element ) {
252+ return ;
253+ }
254+ // Check if the target corner is already in the viewport.
255+ console . log (
256+ 'scroll into rect' ,
257+ x ,
258+ y ,
259+ window . scrollX ,
260+ window . scrollY ,
261+ element . clientWidth ,
262+ element . clientHeight ,
263+ ) ;
264+ if (
265+ x < window . scrollX ||
266+ y < window . scrollY ||
267+ x > window . scrollX + element . clientWidth ||
268+ y > window . scrollY + element . clientHeight
269+ ) {
270+ window . scrollTo ( {
271+ top : y ,
272+ left : x ,
273+ behavior : 'smooth' ,
274+ } ) ;
275+ }
254276 // It's possible that after mount, we're able to scroll deeper once the new nodes
255277 // have mounted. Let's try again after mount. Ideally we'd know which commit this
256278 // is going to be but for now we just try after 100ms.
You can’t perform that action at this time.
0 commit comments