LibWeb: Turn Window.scroll(0, 0) into a no-op when possible

For unscrolled viewports (already at 0, 0), we can short-circuit here
and avoid doing a synchronous relayout of the page.

This avoids a bunch of synchronous layouts on Speedometer3's NewsSite
(Nuxt version) subtests.
This commit is contained in:
Andreas Kling 2025-04-22 00:42:41 +02:00 committed by Andreas Kling
parent 1242b9152e
commit 9840a8c750
Notes: github-actions[bot] 2025-04-22 10:10:50 +00:00

View file

@ -1465,6 +1465,10 @@ void Window::scroll(ScrollToOptions const& options)
x = HTML::normalize_non_finite_values(x);
y = HTML::normalize_non_finite_values(y);
// OPTIMIZATION: If we're asked to scroll to (0, 0) and we're already there, do nothing.
if (x == 0 && y == 0 && navigable->viewport_scroll_offset().is_zero())
return;
// 5. Let viewport width be the width of the viewport excluding the width of the scroll bar, if any.
auto viewport_width = viewport_rect.width();