fix: do not append version query param when scanning for dependencies #11961
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.
Description
Ensure dependency scanner does not skip over bare imports for which there's an alias to an absolute path configured in the
vite.config.js
. Previously this would trigger expensive "full reloads", and invalidate all of the modules in the module graph when a missing dependency is found while "crawling" (see optimizer.ts). This does not seem to be necessary in this case, as it should be able to figure out all of the used dependencies during the initial pass.This used to happen because a version query param was appended to the resolved path, when resolving aliased module id (an absolute path, see resolve.ts). In which case the dependency optimizer would skip over such dependencies as it would not match the regex that specifically checks that the path ends with a file extension (see isOptimizable() @ utils.ts).
Additional context
I've added a missing setup to handle this test scenario in the
optimize-deps
playground, but could not figure out a reliable way to check for unnecessary full reloads in tests.FWIW, the existing test suite started to fail because of unexpected reloads, and to fix it I had to add the
index.html
to the entries, so all of the dependencies are pre-bundled for the first page load.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).