Skip to content

LibWeb: Invalidate viewport-relative lengths nested in math functions - #10869

Merged
awesomekling merged 1 commit into
LadybirdBrowser:masterfrom
awesomekling:yoot
Jul 25, 2026
Merged

LibWeb: Invalidate viewport-relative lengths nested in math functions#10869
awesomekling merged 1 commit into
LadybirdBrowser:masterfrom
awesomekling:yoot

Conversation

@awesomekling

Copy link
Copy Markdown
Member

Style invalidation on viewport resize only touches elements whose computed values recorded a viewport metric dependency. Lengths resolved by the Rust calc simplification had no way to report that dependency back, so calc(50vh - 10px), min(50vh, ...), clamp() and anything reaching them through var() kept their stale pixel values after a resize until something else dirtied the element's style. On sites like YouTube that made a window resize appear to do nothing until a later unrelated invalidation moved everything at once.

Carry the resolution context's tracking flag across the FFI boundary so the Rust length absolutization records viewport (and viewport-dependent font metric) resolutions the same way the C++ path does. Adds a test resizing an iframe and checking each construct picks up the new viewport height.

Style invalidation on viewport resize only touches elements whose
computed values recorded a viewport metric dependency. Lengths resolved
by the Rust calc simplification had no way to report that dependency
back, so `calc(50vh - 10px)`, `min(50vh, ...)`, `clamp()` and anything
reaching them through var() kept their stale pixel values after a
resize until something else dirtied the element's style. On sites like
YouTube that made a window resize appear to do nothing until a later
unrelated invalidation moved everything at once.

Carry the resolution context's tracking flag across the FFI boundary so
the Rust length absolutization records viewport (and viewport-dependent
font metric) resolutions the same way the C++ path does. Adds a test
resizing an iframe and checking each construct picks up the new
viewport height.
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Viewport-relative length resolution now propagates a dependency flag through the C++/Rust context, including font-relative and viewport-relative cases. A new iframe resize test verifies recalculation for direct lengths and lengths nested in CSS math functions.

Changes

Viewport dependency tracking

Layer / File(s) Summary
Length-resolution dependency propagation
Libraries/LibWeb/CSS/Length.h, Libraries/LibWeb/CSS/StyleComputeFFI.h, Libraries/LibWeb/CSS/Rust/src/style_compute.rs, Libraries/LibWeb/CSS/Rust/src/animation.rs
The resolution context exposes a nullable dependency flag, maps it across the C++/Rust boundary, and marks it when font-relative or viewport-relative metrics are resolved.
Iframe resize validation
Tests/LibWeb/Text/input/css/viewport-relative-length-in-math-function-invalidation.html, Tests/LibWeb/Text/expected/css/viewport-relative-length-in-math-function-invalidation.txt
The test measures direct and nested viewport-relative lengths before and after iframe resizing, with updated expected values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description matches the changeset, describing the FFI tracking flag update and the viewport-resize test.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
Libraries/LibWeb/CSS/Rust/src/style_compute.rs (1)

56-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Exercise the new write-through path in a Rust unit test.

test_context() always supplies null_mut(), so the current tests do not execute record_viewport_relative_length_resolution()’s unsafe pointer write. Add a test with a local boolean pointer and verify both a viewport unit and a viewport-dependent font unit set it.

Also applies to: 3860-3860

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Libraries/LibWeb/CSS/Rust/src/style_compute.rs` around lines 56 - 68, Add a
Rust unit test alongside the existing tests that creates a local boolean,
assigns its pointer to an FfiLengthResolutionContext derived from
test_context(), and verifies viewport-unit resolution sets the flag. Reset the
flag and resolve a viewport-dependent font unit, asserting that
record_viewport_relative_length_resolution() sets it there as well.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@Libraries/LibWeb/CSS/Rust/src/style_compute.rs`:
- Around line 56-68: Add a Rust unit test alongside the existing tests that
creates a local boolean, assigns its pointer to an FfiLengthResolutionContext
derived from test_context(), and verifies viewport-unit resolution sets the
flag. Reset the flag and resolve a viewport-dependent font unit, asserting that
record_viewport_relative_length_resolution() sets it there as well.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a76f2efb-17af-4326-b953-a8be53ee5c17

📥 Commits

Reviewing files that changed from the base of the PR and between 27d11da and 0d754f1.

📒 Files selected for processing (6)
  • Libraries/LibWeb/CSS/Length.h
  • Libraries/LibWeb/CSS/Rust/src/animation.rs
  • Libraries/LibWeb/CSS/Rust/src/style_compute.rs
  • Libraries/LibWeb/CSS/StyleComputeFFI.h
  • Tests/LibWeb/Text/expected/css/viewport-relative-length-in-math-function-invalidation.txt
  • Tests/LibWeb/Text/input/css/viewport-relative-length-in-math-function-invalidation.html

@awesomekling
awesomekling merged commit 0167bcc into LadybirdBrowser:master Jul 25, 2026
13 of 14 checks passed
@awesomekling
awesomekling deleted the yoot branch July 25, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant