Clamp viewport and element scroll offsets after layout when scrollable overflow shrinks

Open
#1,600 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #1602 by @GoCoder7 — closed without merging

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
rust
Domain
frontend, web-dev

Research direction

Start with BaseDocument::resolve() in packages/blitz-dom/src/resolve.rs and the scroll state in packages/blitz-dom/src/scrolling.rs; the issue identifies layout and transform resolution as the point where updated bounds become available. Trace how viewport and element offsets, including in-flight animation targets, relate to those bounds. Done means offsets and animation targets stay within the updated range, with collapsed or non-scrolling containers reset as described. A pull request is already linked.

Written by the indexing model from the issue text.

Description

A-Events A-Layout C-Bug

Problem Summary

When scrollable overflow shrinks due to DOM mutations, style changes, or viewport resizing, Blitz Native leaves both viewport (viewport_scroll) and element (node.scroll_offset) scroll offsets at their previous positions instead of clamping them against the updated post-layout scrollable bounds.

This causes rendered views to remain translated past their maximum scroll boundary, pushing visible content off-screen and leaving blank empty strips at the bottom or right edges of the window or container.

Web vs Blitz Native unclamped scroll offset after layout shrink

Concrete Reproduction & Observed Metrics

  1. Open a window with a 1027px-tall viewport rendering a scrollable view of height 1166px.
  2. Scroll to the bottom of the page: viewport_scroll reaches (0.0, 139.0).
  3. Trigger a DOM mutation or navigation that changes the rendered content to a shorter view of height 480px.
  4. The root layout height shrinks to fit the viewport (1027px), where max_scroll.y == 0.0.
  5. However, viewport_scroll remains at (0.0, 139.0).
  6. During painting in blitz-paint (packages/blitz-paint/src/render.rs), the root layer continues applying a translation of -139px along the Y axis. Top content is pushed off the top of the viewport, leaving a 139px blank strip at the bottom of the window (as illustrated in the comparison screenshot above against Web behavior).

The same behavior occurs for element-level scroll containers (overflow: auto / overflow: scroll) when their child elements are removed or shrink in size.

Root Causes in blitz-dom

  1. Missing Post-Layout Clamping in BaseDocument::resolve():
    BaseDocument::resolve() (packages/blitz-dom/src/resolve.rs) invokes resolve_layout() and resolve_transforms() (which updates scrollable_overflow at resolve.rs:248), but never clamps viewport_scroll or element node.scroll_offset afterwards before building the paint tree or performing hit-testing.
  2. Premature Viewport Clamping during Device Change Flushing:
    BaseDocument::flush_pending_device_changes() (packages/blitz-dom/src/document.rs:2930) calls self.scroll_viewport_by(0.0, 0.0) at resolve.rs:79 before resolve_stylist() (L82) and resolve_layout() (L118). As a result, viewport resize events clamp against stale pre-resize dimensions, while DOM or stylesheet mutations skip clamping entirely.
  3. Unclamped In-Flight Smooth Scroll Animations:
    In-flight ScrollAnimationState::ScrollTo (packages/blitz-dom/src/scrolling.rs) retains unclamped start and end target offsets if scrollable overflow shrinks mid-animation, causing animation ticks to drive scroll offsets beyond the new bounds.

Expected Behavior

In accordance with CSS Overflow Module Level 3 and CSSOM View specifications:

  • After layout and transform resolution, both the viewport and all element scroll containers must clamp their scroll offsets to the updated [min, max] scroll range.
  • Containers transitioning to non-scrolling overflow (overflow: visible | clip) or boxless states (display: none, display: contents) should reset their scroll offset to (0.0, 0.0).
  • Active smooth scroll animations should have their start and end targets clamped to the updated [min, max] range (or be cancelled if collapsed).
Dominant language
Rust
Stars
4.5k
Forks
281
Avg merge
6h 6m
Merged PRs (30d)
184

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DioxusLabs/blitz

All issues in DioxusLabs/blitz

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.