Conversation
|
I think it would be better to do a review of the current flow. In MDN, there is an example without using background-image: image-set(
"large-balloons.avif" type("image/avif"),
"large-balloons.jpg" type("image/jpeg"));Maybe the regex could be extended like: to So we stop processing image sets that have |
packages/vite/src/node/utils.ts
Outdated
| .trim() | ||
| .split(' ', 2) | ||
| return { url, descriptor } | ||
| .split(' ') |
There was a problem hiding this comment.
Should we split after ), ', " here? What happens if we have something like var( --my-var)?
There was a problem hiding this comment.
Thanks for review!
Yes, the space inside var() or url() will cause some trouble.Maybe I can clean space inside it.
There was a problem hiding this comment.
Thank you for pushing forward with a fix! ;)
Maybe a regex is better to match the first part? var(), url(), '...', "..." ?
There was a problem hiding this comment.
Update.
According to spec, support 2 condition.
- function call like
var(),url(),linear-gradient() - url like
'test.png',"test.png"
| .css-image-set-multiple-descriptor { | ||
| background-image: -webkit-image-set( | ||
| '../nested/asset.png' type('image/png') 1x, | ||
| '../nested/asset.png' type('image/png') 2x | ||
| ); | ||
| background-size: 10px; | ||
| } |
There was a problem hiding this comment.
I think this needs to test inline CSS in HTML because it doesn't have url( and also needs to compile, may have had a problem with inline CSS in HTML.
There was a problem hiding this comment.
Would you share a failing example to add to the PR?
There was a problem hiding this comment.
vite/packages/vite/src/node/plugins/html.ts
Lines 359 to 365 in 8e1d6ae
There was a problem hiding this comment.
Nice! It is working though, are we good then?
There was a problem hiding this comment.
because I no add the assertion. 😂
There was a problem hiding this comment.
@poyoho gotcha. Should the fix for this case be part of this PR, though? This wasn't working before even without var. I think we could merge this PR and then create a new PR or issue for inline style support, no?
There was a problem hiding this comment.
OK, I think this issue had two solutions. one is to remove the judge. other is add the judge. remove this judge may be better. But anyway it is also not part of this PR. (it seems to part of html instead of css).
|
@patak-dev @poyoho The fail test seems not related, could you plz rerun it? |
|
Thanks again @Bigfish8! |
|
Thanks for the work 👍 |
Description
fix #7874
Additional context
the case in #7874
input:
background-image: image-set(var(--hero--image-webp) 1x, var(--hero--image-jpg) 1x);output:
background-image: image-set(url(var(--hero--image-webp) ) 1x, var(--hero--image-jpg) 1x);step:
cssImageSetREmatch theimage-set(var(--hero--image-webp)(note: there only one))var(--hero--image-webptourl(var(--hero--image-webp)it means that if the css is:
.some-class { --some-var: './a.png'; background-image: -webkit-image-set(var(--some-var) 1x, './b.png' 2x)The
cssImageSetREwill only matchimage-set(var(--some-var)and do not handle'./b.png'.But I think this is OK, because of the demo metioned in #7874. Url like
'./b.png'in image-set is invalid, onlyurl('./b.png')is valid.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).