Skip to content

Fix CSS url() asset references#515

Draft
Luca Schneider (Mad-Kat) wants to merge 11 commits into
mainfrom
fix/vite-css-url-resolution
Draft

Fix CSS url() asset references#515
Luca Schneider (Mad-Kat) wants to merge 11 commits into
mainfrom
fix/vite-css-url-resolution

Conversation

@Mad-Kat
Copy link
Copy Markdown
Collaborator

Fixes #513

Root cause: The \0 prefix on virtual module IDs prevents Vite's CSS pipeline from determining the correct directory for url() resolution.

Fix: Drop the \0 prefix and use a .yak.css suffix instead. resolveId now returns /abs/path/Component.tsx.yak.css, giving Vite the correct directory context to resolve relative url() paths. This follows the same convention as vanilla-extract, Linaria, and Pigment CSS. Vite docs confirms that \0 isn't needed for file-derived modules.

Cross-file url() references: A second issue exists with url() paths inside cross-file mixins. When a mixin is inlined into a consuming component, relative url() paths still point relative to the mixin's original directory, not the consuming file's directory. To fix this, relative url() paths are now rewritten during cross-file resolution so they resolve correctly from the consumer's location.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 19, 2026

🦋 Changeset detected

Latest commit: aa16a28

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
next-yak Patch
storybook-addon-yak Patch
next-yak-example Patch
@example/storybook Patch
vite-yak-example Patch
benchmarks Patch
docs Patch
yak-swc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread packages/next-yak/cross-file-resolver/resolveCrossFileConstant.ts Outdated
Comment thread packages/next-yak/cross-file-resolver/resolveCrossFileConstant.ts Outdated
Comment thread packages/next-yak/cross-file-resolver/resolveCrossFileConstant.ts Outdated
Comment thread packages/next-yak/loaders/vite-plugin.ts Outdated
@Mad-Kat Luca Schneider (Mad-Kat) changed the base branch from e2e/css-url-asset to main March 23, 2026 14:43
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 23, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks
⏩ 12 skipped benchmarks1


Comparing fix/vite-css-url-resolution (fd0a523) with main (2da1696)

Open in CodSpeed

Footnotes

  1. 12 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@jantimon
Copy link
Copy Markdown
Collaborator

nextjs with webpack fails because of a bug in mini-css-extract plugin which was resolved by Luca Schneider (@Mad-Kat) in webpack/mini-css-extract-plugin#1161 and merged - so we have to wait for a new next.js release with mini-css-extract-plugin 2.10.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Vite: relative url() paths in CSS don't resolve correctly

2 participants