Skip to content

[css-values-4] [css-cascade-4] [css-color-5] [css-fonts-4] [css-images-4] [css-shapes-2] Clean up fetching - #12261

Merged
noamr merged 4 commits into
w3c:mainfrom
noamr:fix-fetching
Jun 3, 2025
Merged

[css-values-4] [css-cascade-4] [css-color-5] [css-fonts-4] [css-images-4] [css-shapes-2] Clean up fetching#12261
noamr merged 4 commits into
w3c:mainfrom
noamr:fix-fetching

Conversation

@noamr

@noamr noamr commented Jun 2, 2025

Copy link
Copy Markdown
Collaborator

This fixes a few cases around fetching external URLs for style resources:

  • The base URL is the sheet's base URL if exists, otherwise the sheet's location, otherwise the document base URL.
  • The algorithm can take either a rule or declaration block, and derive the correct stylesheet and base URL from that. Updated the calling sites to take that onto account.
  • Removed redundant URL parsing in "@import".

Closes #12065
Closes #12068
Closes #12086
Closes #12147

…s-4] [css-shapes-2] Clean up fetching

This fixes a few cases around fetching external URLs for style resources:
- The base URL is the sheet's base URL if exists, otherwise the sheet's location, otherwise the document
  base URL.
- The algorithm can take either a rule or declaration block, and derive the correct stylesheet and base
  URL from that.
  Updated the calling sites to take that onto account.

- Removed redundant URL parsing in "@import".

Closes w3c#12065
Closes w3c#12068
Closes w3c#12086
Closes w3c#12147
@noamr
noamr requested a review from tabatkins June 2, 2025 19:39
@noamr

noamr commented Jun 2, 2025

Copy link
Copy Markdown
Collaborator Author

/cc @AtkinsSJ @weinig, please check that this change is sane :)

@noamr noamr changed the title [css-vlaues-4] [css-cascade-4] [css-color-5] [css-fonts-4] [css-images-4] [css-shapes-2] Clean up fetching [css-values-4] [css-cascade-4] [css-color-5] [css-fonts-4] [css-images-4] [css-shapes-2] Clean up fetching Jun 2, 2025
@noamr noamr added the css-values-4 Current Work label Jun 2, 2025

@svgeesus svgeesus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM but others should review in detail

@AtkinsSJ AtkinsSJ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, this looks pretty solid to me.

One thing that I've been alerted to this morning, (see LadybirdBrowser/ladybird#4972) that's related to this, is that the fetch algorithms operate on relative URLs (and expect them to not be resolved yet) but the values spec requires that the computed value of an URL is absolute:

When a appears in the computed value of a property, it is resolved to an absolute URL, as described in the preceding paragraph. The computed value of a URL that the UA cannot resolve to an absolute URL is the specified value.
https://drafts.csswg.org/css-values-4/#relative-urls

That suggests that either we're absolutizing URLs in two different places with potentially different rules, or that the absolutization in fetch is redundant as the URL will already be absolute. (Or I'm missing something.) Sorry for not catching this earlier!

@noamr

noamr commented Jun 3, 2025

Copy link
Copy Markdown
Collaborator Author

Thanks, this looks pretty solid to me.

One thing that I've been alerted to this morning, (see LadybirdBrowser/ladybird#4972) that's related to this, is that the fetch algorithms operate on relative URLs (and expect them to not be resolved yet) but the values spec requires that the computed value of an URL is absolute:

When a appears in the computed value of a property, it is resolved to an absolute URL, as described in the preceding paragraph. The computed value of a URL that the UA cannot resolve to an absolute URL is the specified value.
https://drafts.csswg.org/css-values-4/#relative-urls

That suggests that either we're absolutizing URLs in two different places with potentially different rules, or that the absolutization in fetch is redundant as the URL will already be absolute. (Or I'm missing something.) Sorry for not catching this earlier!

Good spotting, thanks to both you and to the Ladybird project for keeping the specs honest!

I've extracted out the "resolve to absolute URL" bit, and referred to it from https://drafts.csswg.org/css-values-4/#relative-urls. IO think it should make a lot more sense now.

@AtkinsSJ AtkinsSJ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One typo nit, otherwise I think this is good! Thank you. :^)

Comment thread css-values-4/Overview.bs Outdated
@noamr
noamr merged commit 034a433 into w3c:main Jun 3, 2025
@noamr
noamr deleted the fix-fetching branch June 3, 2025 13:03
@AtkinsSJ

AtkinsSJ commented Jun 5, 2025

Copy link
Copy Markdown
Contributor

Arg, I missed a thing until I now tried to implement this! 😅

I think this:

given an CSS rule or a css declaration cssRuleOrDeclaration

...is referring to the wrong definition of "CSS declaration". style resource base URL checks for CSSStyleDeclaration and that seems to be the one we want. The naming of these is unhelpful.

@noamr

noamr commented Jun 5, 2025

Copy link
Copy Markdown
Collaborator Author

Arg, I missed a thing until I now tried to implement this! 😅

I think this:

given an CSS rule or a css declaration cssRuleOrDeclaration

...is referring to the wrong definition of "CSS declaration". style resource base URL checks for CSSStyleDeclaration and that seems to be the one we want. The naming of these is unhelpful.

Ah yes it needs to be a CSS declaration block.

Comment thread css-values-4/Overview.bs

<div algorithm="resolve a style resource URL">
To <dfn>resolve a style resource URL</dfn> from a [=/url=] or <<url>> |urlValue|,
and a a [=CSS rule=] or a [=CSS declaration=] |cssRuleOrDeclaration|:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"a a"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, fixed

AtkinsSJ added a commit to AtkinsSJ/ladybird that referenced this pull request Jun 5, 2025
AtkinsSJ added a commit to AtkinsSJ/ladybird that referenced this pull request Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

css-values-4 Current Work

Projects

None yet

3 participants