vite: fix SVG watch ignore regex for query/hash(#issue 19401) #19402
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixed SVG watch filter regex in the Vite plugin to correctly ignore files with query parameters or hash fragments.
Problem: The regex /[#?].*.svg$/ only matches when # or ? appears before .svg and the string ends with .svg. This fails to match typical Vite import paths like icons/foo.svg?component or icons/foo.svg#sprite, allowing those files to remain watched and potentially crash Vite during file scanning.
Solution: Updated the regex to /.svg(?:[#?].*)?$/ to match .svg, .svg?…, and .svg#… patterns, ensuring the workaround reliably prevents watch crashes on SVG files with query/hash suffixes.
Test plan:
Create a test SVG with query parameter
echo '' > src/icons/test.svg
Import it with a query in your CSS/JS
import Icon from './icons/test.svg?component'
Start dev server and modify the SVG
pnpm dev
Should NOT crash; watch correctly ignores the SVG file.
closed(#19401 )