-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
fix(css): should not wrap with double quote when the url rebase feature bailed out #20068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(css): should not wrap with double quote when the url rebase feature bailed out #20068
Conversation
if (rawUrl === newUrl) { | ||
return matched | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could add a comment here that says that the replacer will bail out when checking the first variable in the case of a concat and this is why it works? I think it would be better to check this in skipUrlReplacer
but I understand it is a big refactoring to pass the variablePrefix
to it. So good to go for me if we add the comment to avoid confusion later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be better. Added a comment for now 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I see the comment, what happens when rawUrl
has a space and rawUrl === newUrl
? Don't we still need to re-wrap it in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the rawUrl
contains a space and rawUrl
is not quoted, the input is not valid. The value in url()
should be quoted to contain a space. So this code will keep the invalid code as-is when rawUrl === newUrl
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rawUrl
can originally have a space and be quoted, and we are removing the quotes here in that case https://github.com/vitejs/vite/pull/20068/files#diff-2cfbd4f4d8c32727cd8e1a561cffbde0b384a3ce0789340440e144f9d64c10f6R2053
Or am I reading this wrong? I think it is probably good to have a local unquotedUrl
instead of overriding rawUrl
, as this is indeed confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I overlooked that 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me come up with a more proper way to fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the impl to allow returning false
from CssUrlReplacer
. The previous impl didn't handle interpolation properly and that is not possible to have it inside skipUrlReplacer
because the behavior is different for each preprocessors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now that the comment confused me as it was
// If the replacer output is same with the input, we don't need to wrap it with quotes.
but the code was returning matched
, so it was working before but the new code is way better and you fixed other issues so this was good in the end :)
if (skipUrlReplacer(unquotedUrl)) { | ||
return matched | ||
} | ||
if (isExternalUrl(rawUrl) || isDataUrl(rawUrl) || rawUrl[0] === '#') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now checks functionCallRE.test(unquotedUrl)
additionally.
The following code works and the URL replacement should be skipped.
@function foo() {
@return 'foo.css';
}
@import url(foo());
const skipRebaseUrls = (unquotedUrl: string, rawUrl: string) => { | ||
const isQuoted = rawUrl[0] === '"' || rawUrl[0] === "'" | ||
// matches `url($foo)` | ||
if (!isQuoted && unquotedUrl[0] === '$') { | ||
return true | ||
} | ||
// matches `url(#{foo})` and `url('#{foo}')` | ||
return unquotedUrl.startsWith('#{') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
rebaseUrl
was replacingurl($var-c1 + $var-c2)
withurl("$var-c1 + $var-c2")
.fixes #19196