fix: allow nested dependency selector to be used for optimizeDeps.include
for SSR
#18506
+17
−66
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
I started this PR as a refactor but turned out that I can fix a bug that will simplify the code more.
The bug is that
optimizeDeps.include: ['foo > bar']
was not working only for SSR.ssrOptimizeCheck
is set at this line.vite/packages/vite/src/node/optimizer/resolve.ts
Line 18 in 2c10f9a
That makes this condition to be used and
vite/packages/vite/src/node/plugins/resolve.ts
Line 896 in 2c10f9a
because we pass the
absolute/path/to/foo/package.json
as a importervite/packages/vite/src/node/optimizer/resolve.ts
Line 38 in 2c10f9a
that condition is always
true
for nested selectors.So all dependencies specified with nested selectors in
optimizeDeps.include
will be skipped.The purpose of using
skipOptimization
for SSR seems to be to only optimize CJS deps (#8932). But this is not the case anymore since #18358 and probably can be removed.Commits in this PR other than 817640e should not change any behavior.