Skip to content
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

fix: re-apply default conditions if using vite 6 or later #7071

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thebanjomatic
Copy link
Contributor

@thebanjomatic thebanjomatic commented Dec 11, 2024

Fixes #7070

Description

Vite 6 no longer applies default conditions when you override resolve.conditions. This PR adds them back conditionally based on the vite version.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Dec 11, 2024

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 3c7604d
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/6759f3a037b5740008c2d208
😎 Deploy Preview https://deploy-preview-7071--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Vite 6 no longer applies default conditions when you override resolve.conditions.
This PR adds them back conditionally based on the vite version.

Fixes vitest-dev#7070
// we add back "node" explicitly in both client and server conditions.
// this ensures that the conditions we pass on to vite doesn't include
// both browser and node at the same time, or node twice in the server case.
return conditions.filter(c => c !== 'browser' && c !== 'node')
Copy link
Contributor Author

@thebanjomatic thebanjomatic Dec 11, 2024

Choose a reason for hiding this comment

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

I don't love that the vite migration docs say:

For example, if you previously specified ['custom'] for resolve.conditions, you need to specify ['custom', ...defaultClientConditions] instead.

which implies that we should just be doing:

clientConditions: ['node', ...defaultClientConditions],

but there is some subtlety in that in vite 5, 'node' and 'browser' weren't actually part of the default conditions, but instead it used the browser option for the resolve function as follows:

resolve({
  ...
  browser: targetWeb && !additionalConditions.has('node')
  conditions,
  ...
});

So in the case of vitest passing "node" as an additional condition it would disable the browser resolve, but if node wasn't passed in, it would infer 'browser' resolve behavior from that rather than using conditions. You couldn't previously get in a case where you had both "browser" and "node" conditions, but when just using conditions in vite 6 you can.

If you want the same behavior as before, we need to remove "browser" from vite's default conditions, and add the node condition instead.

@thebanjomatic
Copy link
Contributor Author

@sheremet-va assuming this change looks good for the vitest 3.x release, is there any chance of back-patching it to 2.1.9 while waiting for the official 3.x release?

@sheremet-va
Copy link
Member

Vitest 2 doesn’t support Vite 6

@thebanjomatic
Copy link
Contributor Author

The 2.1.7 release notes implied a soft support:

We will enable support for it later. In the meantime, you can still use pnpm.overrides or yarn resolutions to override the vite version in the vitest package - the APIs are compatible.

But that was under the assumption the api's were compatible which doesn't appear to be the case. I'm ok waiting, but thought I'd ask.

@sheremet-va
Copy link
Member

The API is compatible, only default config values have breaking changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vite 6 compatibility issue
2 participants