-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
fix(glob): fix HMR for array patterns with exclusions #20872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+78
−14
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes HMR not triggering when files are added or deleted that match import.meta.glob array patterns with exclusions. The bug was in the hotUpdate hook where negated patterns were being passed to picomatch with the '!' prefix still attached. Picomatch expects negated patterns without the '!' prefix for proper matching. When a file was added/deleted that matched a glob like: ["./modules/*.js", "!./modules/_excluded.js"] The matcher would fail because it was trying to match against "!/path/to/_excluded.js" instead of "/path/to/_excluded.js". The fix strips the '!' prefix from negated patterns before passing them to picomatch, allowing the matcher to correctly identify files that match the affirmed patterns but not the negated ones.
Move array pattern test into main index.html to avoid page navigation issues in the test environment. The test was failing with 'Cannot navigate to invalid URL' when trying to use page.goto(). Also added a separate test to verify exclusion patterns work correctly.
- Add cleanup at start of HMR test to ensure clean state - Make static test more flexible by checking properties instead of strict equality - Move array-result element earlier in HTML to match test expectations This fixes test failures caused by file persistence across test runs.
Move array pattern test to end of HTML to avoid breaking existing test selectors and page structure.
Use expect.poll() to wait for content to load before parsing, preventing JSON.parse errors when content isn't ready yet.
Remove .resolves which is not supported with expect.poll(). Use .toMatchObject() directly on polled value instead.
Add expect.poll() to subpath imports, #alias imports, and import base glob raw tests to handle timing issues with async content loading.
Add expect.poll() to wait for async content loading in the escape test which was failing intermittently on macOS.
7 tasks
sapphi-red
approved these changes
Oct 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
1 task
renovate bot
added a commit
to andrei-picus-tink/auto-renovate
that referenced
this pull request
Oct 3, 2025
| datasource | package | from | to | | ---------- | ------- | ----- | ----- | | npm | vite | 7.1.7 | 7.1.8 | ## [v7.1.8](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-718-2025-10-02-small) ##### Bug Fixes - **css:** improve url escape characters handling ([#20847](vitejs/vite#20847)) ([24a61a3](vitejs/vite@24a61a3)) - **deps:** update all non-major dependencies ([#20855](vitejs/vite#20855)) ([788a183](vitejs/vite@788a183)) - **deps:** update artichokie to 0.4.2 ([#20864](vitejs/vite#20864)) ([e670799](vitejs/vite@e670799)) - **dev:** skip JS responses for document requests ([#20866](vitejs/vite#20866)) ([6bc6c4d](vitejs/vite@6bc6c4d)) - **glob:** fix HMR for array patterns with exclusions ([#20872](vitejs/vite#20872)) ([63e040f](vitejs/vite@63e040f)) - keep ids for virtual modules as-is ([#20808](vitejs/vite#20808)) ([d4eca98](vitejs/vite@d4eca98)) - **server:** drain stdin when not interactive ([#20837](vitejs/vite#20837)) ([bb950e9](vitejs/vite@bb950e9)) - **server:** improve malformed URL handling in middlewares ([#20830](vitejs/vite#20830)) ([d65a983](vitejs/vite@d65a983)) ##### Documentation - **create-vite:** provide deno example ([#20747](vitejs/vite#20747)) ([fdb758a](vitejs/vite@fdb758a)) ##### Miscellaneous Chores - **deps:** update rolldown-related dependencies ([#20810](vitejs/vite#20810)) ([ea68a88](vitejs/vite@ea68a88)) - **deps:** update rolldown-related dependencies ([#20854](vitejs/vite#20854)) ([4dd06fd](vitejs/vite@4dd06fd)) - update url of `create-react-app` license ([#20865](vitejs/vite#20865)) ([166a178](vitejs/vite@166a178))
renovate bot
added a commit
to andrei-picus-tink/auto-renovate
that referenced
this pull request
Oct 3, 2025
| datasource | package | from | to | | ---------- | ------- | ----- | ----- | | npm | vite | 7.1.7 | 7.1.9 | ## [v7.1.9](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-719-2025-10-03-small) ##### Reverts - **server:** drain stdin when not interactive ([#20885](vitejs/vite#20885)) ([12d72b0](vitejs/vite@12d72b0)) ## [v7.1.8](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-718-2025-10-02-small) ##### Bug Fixes - **css:** improve url escape characters handling ([#20847](vitejs/vite#20847)) ([24a61a3](vitejs/vite@24a61a3)) - **deps:** update all non-major dependencies ([#20855](vitejs/vite#20855)) ([788a183](vitejs/vite@788a183)) - **deps:** update artichokie to 0.4.2 ([#20864](vitejs/vite#20864)) ([e670799](vitejs/vite@e670799)) - **dev:** skip JS responses for document requests ([#20866](vitejs/vite#20866)) ([6bc6c4d](vitejs/vite@6bc6c4d)) - **glob:** fix HMR for array patterns with exclusions ([#20872](vitejs/vite#20872)) ([63e040f](vitejs/vite@63e040f)) - keep ids for virtual modules as-is ([#20808](vitejs/vite#20808)) ([d4eca98](vitejs/vite@d4eca98)) - **server:** drain stdin when not interactive ([#20837](vitejs/vite#20837)) ([bb950e9](vitejs/vite@bb950e9)) - **server:** improve malformed URL handling in middlewares ([#20830](vitejs/vite#20830)) ([d65a983](vitejs/vite@d65a983)) ##### Documentation - **create-vite:** provide deno example ([#20747](vitejs/vite#20747)) ([fdb758a](vitejs/vite@fdb758a)) ##### Miscellaneous Chores - **deps:** update rolldown-related dependencies ([#20810](vitejs/vite#20810)) ([ea68a88](vitejs/vite@ea68a88)) - **deps:** update rolldown-related dependencies ([#20854](vitejs/vite#20854)) ([4dd06fd](vitejs/vite@4dd06fd)) - update url of `create-react-app` license ([#20865](vitejs/vite#20865)) ([166a178](vitejs/vite@166a178))
renovate bot
added a commit
to andrei-picus-tink/auto-renovate
that referenced
this pull request
Oct 4, 2025
| datasource | package | from | to | | ---------- | ------- | ----- | ----- | | npm | vite | 7.1.7 | 7.1.9 | ## [v7.1.9](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-719-2025-10-03-small) ##### Reverts - **server:** drain stdin when not interactive ([#20885](vitejs/vite#20885)) ([12d72b0](vitejs/vite@12d72b0)) ## [v7.1.8](https://github.com/vitejs/vite/blob/HEAD/packages/vite/CHANGELOG.md#small-718-2025-10-02-small) ##### Bug Fixes - **css:** improve url escape characters handling ([#20847](vitejs/vite#20847)) ([24a61a3](vitejs/vite@24a61a3)) - **deps:** update all non-major dependencies ([#20855](vitejs/vite#20855)) ([788a183](vitejs/vite@788a183)) - **deps:** update artichokie to 0.4.2 ([#20864](vitejs/vite#20864)) ([e670799](vitejs/vite@e670799)) - **dev:** skip JS responses for document requests ([#20866](vitejs/vite#20866)) ([6bc6c4d](vitejs/vite@6bc6c4d)) - **glob:** fix HMR for array patterns with exclusions ([#20872](vitejs/vite#20872)) ([63e040f](vitejs/vite@63e040f)) - keep ids for virtual modules as-is ([#20808](vitejs/vite#20808)) ([d4eca98](vitejs/vite@d4eca98)) - **server:** drain stdin when not interactive ([#20837](vitejs/vite#20837)) ([bb950e9](vitejs/vite@bb950e9)) - **server:** improve malformed URL handling in middlewares ([#20830](vitejs/vite#20830)) ([d65a983](vitejs/vite@d65a983)) ##### Documentation - **create-vite:** provide deno example ([#20747](vitejs/vite#20747)) ([fdb758a](vitejs/vite@fdb758a)) ##### Miscellaneous Chores - **deps:** update rolldown-related dependencies ([#20810](vitejs/vite#20810)) ([ea68a88](vitejs/vite@ea68a88)) - **deps:** update rolldown-related dependencies ([#20854](vitejs/vite#20854)) ([4dd06fd](vitejs/vite@4dd06fd)) - update url of `create-react-app` license ([#20865](vitejs/vite#20865)) ([166a178](vitejs/vite@166a178))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
fix(import-glob): fix HMR for array patterns with exclusions
fix #20852
Description
Fixes HMR not triggering when files are added or deleted that match
import.meta.glob
array patterns with exclusions.Problem
When using array patterns with exclusions like:
HMR would fail to trigger when:
Root Cause
The bug was in the
hotUpdate
hook inpackages/vite/src/node/plugins/importMetaGlob.ts
where negated patterns were being passed topicomatch
with the!
prefix still attached.Picomatch expects negated patterns without the
!
prefix for proper matching. When a file was added/deleted, the matcher would try to match against"!/path/to/_excluded.js"
instead of"/path/to/_excluded.js"
, causing the matcher to always returnfalse
.Solution
Strip the
!
prefix from negated patterns before passing them topicomatch
:Verification
Using the Reproduction Repo
You can verify this fix using the reproduction repository: https://github.com/MoritzLoewenstein/vite-import-glob-repro
git clone https://github.com/MoritzLoewenstein/vite-import-glob-repro.git cd vite-import-glob-repro npm install
✅ Expected: The page should HMR automatically and show both
included_a.js
andincluded_b.js
✅ Expected: The page should HMR automatically and show only
included_a.js
(no errors)Manual Verification
main.js
:vite
and verify:included.js
appears in the output (excluded.js is filtered)modules/
triggers HMRmodules/
triggers HMR without errorsTest Coverage
Added comprehensive test coverage in
playground/glob-import/__tests__/glob-import.spec.ts
:Related Issues
This fix resolves the issue reported in the reproduction repository and ensures that array patterns with exclusions work correctly with HMR, matching the behavior of single-pattern globs.