Skip to content

Commit

Permalink
Fix vite file path bug (#398)
Browse files Browse the repository at this point in the history
* Strip the used thing off the file path if it exists

* Add changeset
  • Loading branch information
benjervis committed Oct 6, 2021
1 parent d34d1f6 commit 63f4ed0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .changeset/ninety-pears-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@vanilla-extract/vite-plugin': patch
---

Fixes a bug with vite where "?used" is appended to the file path of css files.

This could cause different class name hashes to be generated between SSR and client builds.
This was introduced in vite 2.6.0.
9 changes: 6 additions & 3 deletions packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,19 @@ export function vanillaExtractPlugin({
return null;
}

const usedIndex = id.indexOf('?used');
const fixedId = usedIndex > 0 ? id.substring(0, usedIndex) : id;

if (ssr || useRuntime) {
return addFileScope({
source: code,
filePath: normalizePath(path.relative(packageInfo.dirname, id)),
filePath: normalizePath(path.relative(packageInfo.dirname, fixedId)),
packageInfo,
}).source;
}

const { source, watchFiles } = await compile({
filePath: id,
filePath: fixedId,
cwd: config.root,
});

Expand All @@ -90,7 +93,7 @@ export function vanillaExtractPlugin({

return processVanillaFile({
source,
filePath: id,
filePath: fixedId,
outputCss: !ssr,
identOption:
identifiers ?? (config.mode === 'production' ? 'short' : 'debug'),
Expand Down

0 comments on commit 63f4ed0

Please sign in to comment.