Skip to content

LibWeb: Resolve substituted relative URLs against the style sheet - #10792

Open
tcl3 wants to merge 3 commits into
LadybirdBrowser:masterfrom
tcl3:libweb_unresolved_stylevalue_stylesheet_url
Open

LibWeb: Resolve substituted relative URLs against the style sheet#10792
tcl3 wants to merge 3 commits into
LadybirdBrowser:masterfrom
tcl3:libweb_unresolved_stylevalue_stylesheet_url

Conversation

@tcl3

@tcl3 tcl3 commented Jul 21, 2026

Copy link
Copy Markdown
Member

Declarations containing substitution functions are re-parsed at computed-value time. Previously, this re-parse only knew about the document, so any relative URL produced by substitution was resolved against the document base URL instead of the URL of the style sheet containing the declaration.

We now capture the style sheet's base URL on unresolved values when they are attached to their style sheet, and give that context to the parser when resolving them, so URL values created during substitution resolve and serialize like their literally-specified equivalents.

Fixes #10771

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: df4bf124-58a8-455d-8dd8-a8c2ceabb678

📥 Commits

Reviewing files that changed from the base of the PR and between d04d0cb and 7d5c76b.

📒 Files selected for processing (14)
  • Libraries/LibWeb/Animations/KeyframeEffect.h
  • Libraries/LibWeb/CSS/CSSNestedDeclarations.cpp
  • Libraries/LibWeb/CSS/CSSNestedDeclarations.h
  • Libraries/LibWeb/CSS/CSSStyleProperties.cpp
  • Libraries/LibWeb/CSS/StyleComputer.cpp
  • Libraries/LibWeb/CSS/StyleScope.cpp
  • Libraries/LibWeb/Rust/src/css/cascaded_properties.rs
  • Libraries/LibWeb/Rust/src/css/style_compute.rs
  • Tests/LibWeb/Text/expected/css/url-substitution-resolves-relative-to-stylesheet.txt
  • Tests/LibWeb/Text/expected/wpt-import/css/css-mixins/function-attr.txt
  • Tests/LibWeb/Text/expected/wpt-import/css/css-values/urls/resolve-relative-to-base.sub.txt
  • Tests/LibWeb/Text/expected/wpt-import/css/css-values/urls/resolve-relative-to-stylesheet.txt
  • Tests/LibWeb/Text/input/css/support/url-substitution-base.css
  • Tests/LibWeb/Text/input/css/url-substitution-resolves-relative-to-stylesheet.html
🚧 Files skipped from review as they are similar to previous changes (10)
  • Tests/LibWeb/Text/expected/wpt-import/css/css-mixins/function-attr.txt
  • Tests/LibWeb/Text/expected/css/url-substitution-resolves-relative-to-stylesheet.txt
  • Libraries/LibWeb/CSS/CSSNestedDeclarations.h
  • Tests/LibWeb/Text/input/css/url-substitution-resolves-relative-to-stylesheet.html
  • Tests/LibWeb/Text/expected/wpt-import/css/css-values/urls/resolve-relative-to-stylesheet.txt
  • Libraries/LibWeb/CSS/StyleScope.cpp
  • Libraries/LibWeb/CSS/CSSStyleProperties.cpp
  • Libraries/LibWeb/CSS/CSSNestedDeclarations.cpp
  • Tests/LibWeb/Text/expected/wpt-import/css/css-values/urls/resolve-relative-to-base.sub.txt
  • Libraries/LibWeb/CSS/StyleComputer.cpp

📝 Walkthrough

Walkthrough

This change propagates stylesheet context through CSS declarations, nested declarations, cascaded values, shorthand expansion, substituted values, and keyframe animations. Rust bulk-cascade callbacks now pass declaration source IDs to C++. Keyframe sets retain their source stylesheets. New tests validate stylesheet-relative URL substitution across nested rules, shorthands, keyframes, CSSOM updates, and imported WPT cases.

Sequence Diagram(s)

sequenceDiagram
  participant CSSStyleSheet
  participant StyleComputer
  participant RustCascadedProperties
  participant StyleValue
  CSSStyleSheet->>StyleComputer: provide declaration source
  RustCascadedProperties->>StyleComputer: pass source_id during cascade
  StyleComputer->>CSSStyleSheet: resolve parent stylesheet
  StyleComputer->>StyleValue: attach stylesheet context
  StyleComputer-->>RustCascadedProperties: return resolved value
Loading

Possibly related PRs

Suggested reviewers: awesomekling

Mergeability Score: ⚪ Minimal · up to 7d5c7

Substituted relative URLs will resolve against the containing stylesheet as intended. The remaining notes concern formatting and preserving an existing interface, with no actionable user or production impact; no merge-blocking risk remains after normal checks.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description directly explains the stylesheet-relative URL resolution fix implemented by the changeset.
Linked Issues check ✅ Passed The changes capture stylesheet context and propagate it during substitution, addressing incorrect relative url() resolution in issue [#10771].
Out of Scope Changes check ✅ Passed The implementation and related tests remain focused on stylesheet-relative URL resolution and contain no unrelated changes.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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.

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@Libraries/LibWeb/CSS/CSSStyleProperties.cpp`:
- Around line 447-449: Propagate stylesheet context to custom-property values on
every declaration path: in CSSStyleProperties.cpp lines 447-449, move the
style-sheet assignment before the custom-property early return; in
CSSStyleProperties.cpp lines 1654-1658, update values in m_custom_properties as
well as m_properties; and in CSSKeyframeRule.cpp lines 33-40, propagate context
to keyframe custom properties, preferably by reusing the shared
declaration-block helper.

In `@Tests/LibWeb/Text/input/css/support/url-substitution-base.css`:
- Line 17: Add the required blank line immediately before the background-image
declaration using the --url custom property, preserving the declaration itself
unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a13ac9fb-c442-4263-836e-656a8d24a183

📥 Commits

Reviewing files that changed from the base of the PR and between dd7e441 and f56913f.

📒 Files selected for processing (26)
  • Libraries/LibWeb/CSS/CSSImportRule.cpp
  • Libraries/LibWeb/CSS/CSSKeyframeRule.cpp
  • Libraries/LibWeb/CSS/CSSKeyframeRule.h
  • Libraries/LibWeb/CSS/CSSKeyframesRule.cpp
  • Libraries/LibWeb/CSS/CSSKeyframesRule.h
  • Libraries/LibWeb/CSS/CSSNestedDeclarations.cpp
  • Libraries/LibWeb/CSS/CSSNestedDeclarations.h
  • Libraries/LibWeb/CSS/CSSStyleProperties.cpp
  • Libraries/LibWeb/CSS/CSSStyleSheet.cpp
  • Libraries/LibWeb/CSS/CSSStyleSheet.h
  • Libraries/LibWeb/CSS/Parser/Parser.h
  • Libraries/LibWeb/CSS/Parser/ValueParsing.cpp
  • Libraries/LibWeb/CSS/StyleSheetList.cpp
  • Libraries/LibWeb/CSS/StyleSheetResourceContext.h
  • Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h
  • Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.cpp
  • Libraries/LibWeb/CSS/StyleValues/UnresolvedStyleValue.h
  • Tests/LibWeb/Text/expected/css/url-substitution-resolves-relative-to-stylesheet.txt
  • Tests/LibWeb/Text/expected/wpt-import/css/css-mixins/function-attr.txt
  • Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/parsing/marker-supported-properties-in-animation.txt
  • Tests/LibWeb/Text/expected/wpt-import/css/css-values/urls/resolve-relative-to-base.sub.txt
  • Tests/LibWeb/Text/expected/wpt-import/css/css-values/urls/resolve-relative-to-stylesheet.txt
  • Tests/LibWeb/Text/input/css/support/url-substitution-base.css
  • Tests/LibWeb/Text/input/css/url-substitution-resolves-relative-to-stylesheet.html

Comment thread Libraries/LibWeb/CSS/CSSStyleProperties.cpp
Comment thread Tests/LibWeb/Text/input/css/support/url-substitution-base.css
@tcl3
tcl3 force-pushed the libweb_unresolved_stylevalue_stylesheet_url branch from f56913f to 24240b4 Compare July 21, 2026 21:54
@tcl3
tcl3 marked this pull request as draft July 22, 2026 22:36
@tcl3
tcl3 force-pushed the libweb_unresolved_stylevalue_stylesheet_url branch from 24240b4 to 0ac454f Compare July 22, 2026 23:08
@tcl3

tcl3 commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

My latest push updates this branch to make sure it works correctly with the Rust changes introduced in #10811.

@tcl3
tcl3 marked this pull request as ready for review July 22, 2026 23:08
@github-actions github-actions Bot added the conflicts Pull request has merge conflicts that need resolution label Jul 23, 2026
@github-actions

Copy link
Copy Markdown

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@tcl3
tcl3 force-pushed the libweb_unresolved_stylevalue_stylesheet_url branch from 0ac454f to 66d32ba Compare August 9, 2026 20:27
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@github-actions github-actions Bot removed the conflicts Pull request has merge conflicts that need resolution label Aug 9, 2026
Comment thread Libraries/LibWeb/Animations/KeyframeEffect.h Outdated
@github-actions github-actions Bot added the conflicts Pull request has merge conflicts that need resolution label Aug 13, 2026
@github-actions

Copy link
Copy Markdown

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

@tcl3
tcl3 marked this pull request as draft August 13, 2026 15:44
tcl3 added 3 commits August 13, 2026 17:08
Previously, relative URLs in declarations following a nested rule were
resolved against the document base URL instead of the style sheet's
base URL.
Previously, relative URLs in declaration values set through the CSSOM
were resolved against the document base URL instead of the base URL of
the style sheet containing the declaration.
Declarations containing substitution functions are re-parsed at
computed-value time. Previously, this re-parse only knew about the
document, so any relative URL produced by substitution was resolved
against the document base URL instead of the base URL of the style
sheet containing the declaration.

The cascade already tracks the source declaration of each applied
block. We now pass that source through the substitution callbacks and
attach the source's style sheet to each freshly resolved value. The
existing source slot machinery restores this context whenever the
value is materialized again. Shorthand expansion forwards the context
marker to each longhand, so values substituted into a shorthand are
restored as well. Keyframe values are resolved outside the cascade.
Each keyframe set now remembers the style sheet containing its rule,
and animated values receive that context when they are materialized.
@tcl3
tcl3 force-pushed the libweb_unresolved_stylevalue_stylesheet_url branch from 66d32ba to 7d5c76b Compare August 13, 2026 17:09
@github-actions github-actions Bot removed the conflicts Pull request has merge conflicts that need resolution label Aug 13, 2026
@tcl3
tcl3 marked this pull request as ready for review August 13, 2026 17:09
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@tcl3

tcl3 commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

Rebased to resolve conflicts.

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.

Incorrect CSS url() URL resolution base

2 participants