Repository navigation
Rewrite url(…)s next to an image-set(…) when inlining imported stylesheets - #20612
NgoQuocViet2001 wants to merge 1 commit into
Conversation
9f412c4 to
b863d04
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
[Medium impact] The PR appears safe to merge. Reviews (1) · Last reviewed commit: "Rewrite `url(…)`s next to an `image-set(..." · Reviewed by Greptile |
Summary
rewriteUrlsInAstpicks a single rewriter per declaration. When a value has bothurl(…)andimage-set(…), only theimage-set(…)rewriter runs, and it copies everything around its match as-is. So the siblingurl(…)s in an imported stylesheet are never rebased:In Vite,
./overlay.pngis then resolved againstapp.css. Vite warns that it "didn't resolve at build time" and the image is not emitted. Vite fixed this in its own copy of this code in vitejs/vite#18868. Porting that fix as-is would rebase the URLs insideimage-set(…)twice here, because our rebased paths stay relative. Instead,asyncReplacetakes an optional replacer for the text between matches, andrewriteCssImageSetuses it for theurl(…)s outside theimage-set(…). Each URL is now rewritten exactly once.Test plan
urls.test.ts. It fails onmain(url(./a.png)andurl("./d.png")are left as-is) and passes with this change. It also checks thaturl(./b.png)inside theimage-set(…)is rebased only once.vitest run --project @tailwindcss/node --project @tailwindcss/postcss: 32 passed. Fullvitest run --hideSkippedTests: 5657 passed, 1 skipped.@tailwindcss/viteand the stylesheet above: onmainit warns and dropsoverlay.png. With this change both images are emitted and there are no warnings.prettier --checkon the changed files.