Skip to content

Commit a8b64f3

Browse files
Vite: Work around crash when .svg file contains # or ? (#16957)
Closes #16877 This PR works around #16877 by not registering `.svg` files containing a `#` or `?` as a watch dependency for now. ## Test plan - Add a file to the Vite playground called `src/c#.svg` - Observe Vite no longer prints errors
1 parent 4c11001 commit a8b64f3

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Ensure `not-*` does not remove `:is(…)` from variants ([#16825](https://github.com/tailwindlabs/tailwindcss/pull/16825))
2525
- Ensure `@keyframes` are correctly emitted when using a prefixed setup ([#16850](https://github.com/tailwindlabs/tailwindcss/pull/16850))
2626
- Don't swallow `@utility` declarations when `@apply` is used in nested rules ([#16940](https://github.com/tailwindlabs/tailwindcss/pull/16940))
27-
- Ensure `outline-hidden` behaves like `outline-none` in non-`forced-colors` mode ([#](https://github.com/tailwindlabs/tailwindcss/pull/))
27+
- Ensure `outline-hidden` behaves like `outline-none` in non-`forced-colors` mode ([#16943](https://github.com/tailwindlabs/tailwindcss/pull/16943))
2828
- Allow `!important` on CSS variables again ([#16873](https://github.com/tailwindlabs/tailwindcss/pull/16873))
29+
- Vite: Do not crash when encountering an `.svg` file with `#` or `?` in the filename ([#16957](https://github.com/tailwindlabs/tailwindcss/pull/16957))
2930

3031
### Changed
3132

packages/@tailwindcss-vite/src/index.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,20 @@ class Root {
218218
// not considered a Tailwind root. When this happened, the root can be GCed.
219219
public async generate(
220220
content: string,
221-
addWatchFile: (file: string) => void,
221+
_addWatchFile: (file: string) => void,
222222
I: Instrumentation,
223223
): Promise<string | false> {
224+
function addWatchFile(file: string) {
225+
// Scanning `.svg` file containing a `#` or `?` in the path will
226+
// crash Vite. We work around this for now by ignoring updates to them.
227+
//
228+
// https://github.com/tailwindlabs/tailwindcss/issues/16877
229+
if (/[\#\?].*\.svg$/.test(file)) {
230+
return
231+
}
232+
_addWatchFile(file)
233+
}
234+
224235
let requiresBuildPromise = this.requiresBuild()
225236
let inputPath = idToPath(this.id)
226237
let inputBase = path.dirname(path.resolve(inputPath))

0 commit comments

Comments
 (0)