fix: image-set() URL rewrite truncates on nested parentheses
Author: scs0209Created Sep 12, 2026Updated Sep 24, 2026
Labelsfeat: cssp2-edge-case
Describe the bug
cssImageSetRE in packages/vite/src/node/plugins/css.ts extracts image-set(...) contents with a [^)]*-style pattern (plus a single-level func(...) alternative). Nested CSS functions that contain their own ) — e.g. linear-gradient(... rgba(...)) or cross-fade(url(...), url(...)) — cause the capture to end early.
Example input:
background: image-set(
url("a.png") 1x,
linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,1)) 2x
);The regex capture stops inside the gradient, so URL rewriting / processSrcSet sees truncated candidates and can leave broken CSS after rewrite.
Reproduction
const cssImageSetRE = /(?<=image-set\()((?:[\w-]{1,256}\([^)]*\)|[^)])*)(?=\))/
const css = 'image-set(url("a.png") 1x, linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,1)) 2x)'
cssImageSetRE.exec(css)[1]
// => ends at rgba(0,0,0,1) — missing gradient close + " 2x"System Info
Vite main (current).
Used Package Manager
pnpm
Logs
N/A (unit-reproducible)
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines
- Read the docs
- Check that there isn't already an issue that reports the same bug
- Make sure this is a Vite issue and not a framework-specific issue
- Check that this is a concrete bug
- The provided reproduction is a minimal reproducible example of the bug
Source: vitejs/vite