Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sapphi-red
Copy link
Member

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.

ssrOptimizeCheck: environment.config.consumer === 'server',

That makes this condition to be used and
(importer && isInNodeModules(importer)) ||

because we pass the absolute/path/to/foo/package.json as a importer
path.resolve(basedir, 'package.json'),

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.

@sapphi-red sapphi-red added the p3-minor-bug An edge case that only affects very specific usage (priority) label Oct 29, 2024
@sapphi-red sapphi-red changed the title fix: allow nested dependencies to be optimized for SSR fix: allow nested dependency selector to be used for optimizeDeps.include for SSR Oct 29, 2024
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor!

@sapphi-red sapphi-red requested a review from patak-dev October 31, 2024 04:52
Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great to see __vite_skip_optimization deleted ❤️

@patak-dev patak-dev merged commit 826c81a into vitejs:main Oct 31, 2024
@sapphi-red sapphi-red deleted the refactor/ssr-optimize-check branch October 31, 2024 08:03
moonlitusun pushed a commit to moonlitusun/vite that referenced this pull request May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p3-minor-bug An edge case that only affects very specific usage (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants