Bug 190807 - CSS variables with url() don't use correct base URL
Summary: CSS variables with url() don't use correct base URL
Status: RESOLVED DUPLICATE of bug 198512
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: Safari Technology Preview
Hardware: Mac macOS 10.14
: P2 Major
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-10-22 14:30 PDT by Craig Hockenberry
Modified: 2021-04-02 03:54 PDT (History)
10 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Craig Hockenberry 2018-10-22 14:30:27 PDT
CSS variables for a url(), when placed in a subfolder of a website, do not work correctly.

To reproduce this problem, create a "test.css" file in /mysite/tests/stylesheets:

:root {
	
	--configuration-icon: url('../images/test.png');
}

section button {
	background-image: var(--configuration-icon);
}


Create an image called "test.png" in /mysite/tests/images/

In the latest Safari Technology Preview, the Network tab in the Web Inspector will show "test.png" highlighted in red. The 404 response is caused because the browser is trying to load "/images/gear_light.png" instead of "/tests/images/gear_light.png". The CSS 3 documentation states:

"For CSS style sheets, the base URL is that of the style sheet itself, not that of the styled source document."

I'm assuming that this applies even though they're specified through CSS variables.

Additionally, if you do any CSS animation on the page, you'll see *many* of these failed requests (one for each frame of the animation.)

A live example can be found here: https://furbo.org/stuff/DarkModeCSS/ - there should be an icon next to "Click to Switch Themes". If you click on the button, you'll see many failed "gear_light.png" requests during the transition.

Tested with STP: Release 67 (Safari 12.1, WebKit 14607.1.9.0.1).
Chrome Version 69.0.3497.100 (Official Build) (64-bit) handles the url() variables correctly.
Comment 1 Radar WebKit Bug Importer 2018-10-22 16:44:23 PDT
<rdar://problem/45470981>
Comment 2 Chris Burgin 2020-04-07 07:50:59 PDT
I am also having this problem. It seems to be present if a `var` is present anywhere in `background`. Causing it to look at the document not the relative url as specified below.

> https://www.w3.org/TR/CSS1/ 6.4 "Partial URLs are interpreted relative to the source of the style sheet, not relative to the document".


background: url(../images/chevron-down-faded-0845b94284a0a5a42493e703d7ab4a8b.svg) no-repeat center,linear-gradient(to bottom, var(--color-white) 53%, #e2e2e2 98%)


If I replace `var(--color-white)` with `#fff` the image is loaded correctly.
Comment 3 Tyler Wilcock 2020-10-03 21:49:25 PDT
This is a duplicate of https://bugs.webkit.org/show_bug.cgi?id=198512 (technically the other way around, but other bugs are linking to 198512 so I think we should use that one).
Comment 4 Sam Sneddon [:gsnedders] 2021-04-02 03:54:18 PDT

*** This bug has been marked as a duplicate of bug 198512 ***