Skip to content

Commit 63f4ed0

Browse files
author
Ben Jervis
authored
Fix vite file path bug (#398)
* Strip the used thing off the file path if it exists * Add changeset
1 parent d34d1f6 commit 63f4ed0

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

.changeset/ninety-pears-march.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@vanilla-extract/vite-plugin': patch
3+
---
4+
5+
Fixes a bug with vite where "?used" is appended to the file path of css files.
6+
7+
This could cause different class name hashes to be generated between SSR and client builds.
8+
This was introduced in vite 2.6.0.

packages/vite-plugin/src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,19 @@ export function vanillaExtractPlugin({
7171
return null;
7272
}
7373

74+
const usedIndex = id.indexOf('?used');
75+
const fixedId = usedIndex > 0 ? id.substring(0, usedIndex) : id;
76+
7477
if (ssr || useRuntime) {
7578
return addFileScope({
7679
source: code,
77-
filePath: normalizePath(path.relative(packageInfo.dirname, id)),
80+
filePath: normalizePath(path.relative(packageInfo.dirname, fixedId)),
7881
packageInfo,
7982
}).source;
8083
}
8184

8285
const { source, watchFiles } = await compile({
83-
filePath: id,
86+
filePath: fixedId,
8487
cwd: config.root,
8588
});
8689

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

9194
return processVanillaFile({
9295
source,
93-
filePath: id,
96+
filePath: fixedId,
9497
outputCss: !ssr,
9598
identOption:
9699
identifiers ?? (config.mode === 'production' ? 'short' : 'debug'),

0 commit comments

Comments
 (0)