Skip to content
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

url not handled when mixed with image-set in css multiple backgrounds #18859

Closed
7 tasks done
L1Q opened this issue Dec 2, 2024 · 1 comment · Fixed by #18868
Closed
7 tasks done

url not handled when mixed with image-set in css multiple backgrounds #18859

L1Q opened this issue Dec 2, 2024 · 1 comment · Fixed by #18868
Labels
feat: css p2-edge-case Bug, but has workaround or limited in scope (priority)

Comments

@L1Q
Copy link

L1Q commented Dec 2, 2024

Describe the bug

All url backgrounds are ignored in background-image when there is image-set present among multiple backgrounds.

By ignored I mean vite doesn't handle them, leaving the url as it was as opposed to either embeding the image or updating the url with appropriate path for dev or production. This happens in simple css templates and with sass. I haven't tested more cases.

Reproduction

https://stackblitz.com/edit/vitejs-vite-a7wff4?file=src%2Fstyle.css

Steps to reproduce

  1. install a template
$ pnpm create vite -t vanilla vite-css-bug
$ cd vite-css-bug/
$ pnpm install
  1. append the following to ./src/style.css:
body {
  background-image:
    image-set(url('./javascript.svg')),
    url('./javascript.svg')
    ;
  background-size: 50px 50px;
  background-position:
    20px 20px,
    70px 70px;
  background-repeat: no-repeat;
}
  1. observe only one javascript logo in the top left corner
  2. make background-image sources both either image-set or url
  3. observe two logos

If you pnpm run build and check the dist .css file, you'll most likely find the image-set svg url inlined, while the non image-set url is left as is and the svg file is not copied to the dist directory.

vite-css-bug.tar.gz

System Info

System:
    OS: Linux 6.11 Arch Linux
    CPU: (12) x64 AMD Ryzen 5 5600U with Radeon Graphics
    Memory: 7.89 GB / 30.67 GB
    Container: Yes
    Shell: 5.2.37 - /usr/bin/bash
  Binaries:
    Node: 22.10.0 - /usr/bin/node
    npm: 10.9.0 - /usr/bin/npm
    pnpm: 9.12.2 - /usr/bin/pnpm
  npmPackages:
    vite: ^6.0.1 => 6.0.2

Used Package Manager

pnpm

Logs

No response

Validations

@sapphi-red sapphi-red added feat: css p2-edge-case Bug, but has workaround or limited in scope (priority) labels Dec 2, 2024
@pguilbert
Copy link

I think the issue comes from the following code:

const rewriterToUse = isCssImageSet

Vite is expecting image-set or url but not both. We could probably chain rewriteCssImageSet and rewriteCssUrls in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: css p2-edge-case Bug, but has workaround or limited in scope (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants