Skip to content

fix(typecheck): log experimental feature warning once per run#10033

Open
bwyard wants to merge 4 commits intovitest-dev:mainfrom
bwyard:fix/experimental-warning-once
Open

fix(typecheck): log experimental feature warning once per run#10033
bwyard wants to merge 4 commits intovitest-dev:mainfrom
bwyard:fix/experimental-warning-once

Conversation

@bwyard
Copy link
Copy Markdown

@bwyard bwyard commented Mar 31, 2026

When using Vitest with multiple projects that have typecheck.enabled: true, the experimental feature warning is logged once per project config resolved. In a large monorepo this can mean 30+ identical warnings per run. Fixes #9823.

Changed the deduplication key from a string in a module-level Set to the Logger instance in a WeakSet. The logger is constructed per Vitest instance, so the warning fires once per run regardless of how many project configs are resolved - and correctly resets between separate runs.

Added a test: two projects with typecheck.enabled: true in a single run produce exactly one occurrence of the warning.

Noticed the same pattern in the benchmark() function in cac.ts. Left it out, out of scope.

AI assisted: Claude

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 31, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit d7d3e60
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69cbe2bc1acda900087e51ba
😎 Deploy Preview https://deploy-preview-10033--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 project configuration.

Replaces the module-level Set<string> with a WeakSet<Logger>. The Set
persisted across runVitest calls in the same process, suppressing the
warning for subsequent runs. WeakSet keyed by logger instance scopes
dedup to one warning per Vitest run while still deduplicating across
multiple projects in the same run.

Adds a regression test: two projects with typecheck.enabled: true in a
single runVitest call produce exactly one occurrence of the warning.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bwyard bwyard changed the title fix(typecheck): log experimental feature warning once per process fix(typecheck): log experimental feature warning once per run Mar 31, 2026
@bwyard
Copy link
Copy Markdown
Author

bwyard commented Mar 31, 2026

The Rolldown&Test: node-22, macos-latest failure looks like a pre-existing flaky UI test (test/ui/test/ui.spec.ts locator timeout). Same job is also failing on main and on other unrelated PRs (e.g. #7100). Flagging in case it's worth a look before reviewing. Will appreciate any guidance on how to proceed.

travisbreaks

This comment was marked as low quality.

@bwyard
Copy link
Copy Markdown
Author

bwyard commented Apr 2, 2026

Thanks I actually started with set as a fix and off the top of my head can't remember but I ran into issue or tests or something that caused set to not work how I washed to so swapped to weak set. Not at computer now but the regression and the gc are good observations, when I'm at my computer I'll sit down and double check things based on your feedback as well just to be sure I covered everything.

@bwyard
Copy link
Copy Markdown
Author

bwyard commented Apr 4, 2026

Thanks. Checked the Logger lifecycle: logger is declared public readonly on the Vitest class, assigned once in the constructor, and accessed in resolveConfig as const logger = vitest.logger. Should be good on GC.

On the test: I believe the original did cover it, but replaced it with a version that makes the intent clearer. PROJECT_COUNT = 5 projects, each triggering a separate resolveConfig call via TestProject._configureServer. Without the fix that would be 5 warnings. Assertion is still toBe(1). The const makes it easy to push the number higher to verify.

if (resolved.typecheck.enabled) {
if (resolved.typecheck.enabled && !loggedExperimentalWarnings.has(logger)) {
loggedExperimentalWarnings.add(logger)
logger.console.warn(
Copy link
Copy Markdown
Member

@sheremet-va sheremet-va Apr 7, 2026

Choose a reason for hiding this comment

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

I think we should define logger.warnOnce like vite does. And maybe we should use it for all experimental warning

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm definitely not against that, and id prefer that as well was just trying to keep the pr small and to scope since it's first contribution. But I'll go ahead and work on doing it that's way it's probably cleaner.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Got real sick I'll look at this again this weekend

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.

Option to disable "Testing types with tsc and vue-tsc is an experimental feature." logs

3 participants