Skip to content

fix(vite): include no-result load hooks in module timings - #606

Merged
webfansplz merged 2 commits into
vitejs:mainfrom
SaKaNa-Y:fix/vite-declined-load-timing
Oct 9, 2026
Merged

webfansplz merged 2 commits into
vitejs:mainfrom
SaKaNa-Y:fix/vite-declined-load-timing

Conversation

@SaKaNa-Y

@SaKaNa-Y SaKaNa-Y commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Important

Please take a moment to read this. Thank you!

I should include a brief explanation of the problem in my own words in every PR. If that explanation is missing, please @mention me and do not merge this PR until I have added it. You may also leave this PR unaddressed (because this means I have not fulfilled my responsibilities as the author).

If my explanation is unclear or difficult to follow, please ask me to clarify or provide reproduction steps or supporting evidence.

I welcome suggestions and counterarguments, especially questions about anything I may have overlooked. (Your feedback helps me learn and improve. 🙏)

I hold myself to this standard for every PR, regardless of its size.

When investigating slow module processing in the Vite module graph, time spent in a load hook can disappear from the module summary. This happens when the hook returns undefined or null and a later plugin or Vite's file reader supplies the code. Plugin details retain the call, but the module summary only receives loads with code results.

Store these load timings separately from code and include them when the module receives its source. Tie pending timings to the enclosing transform request and discard uncommitted timings when that request ends. A later request replaces the prior snapshot, including an error result from a failed load. This also applies when Vite reads a file directly and when writes share a batch. Module invalidation clears the timing data.

Related fixes: #599 includes timings from transform hooks that return no code. #607 includes timings from successful resolveId calls that return the input ID. Each PR targets main and can be reviewed and merged independently.

Validation on this branch:

  • Real Vite tests for empty load results fail with the old implementation and pass with this change, with both plugin-provided code and native file reads.
  • Memory and disk tests cover request isolation, invalidation, source preservation, and batched writes. A controlled-clock retry keeps the successful request's 5 ms and source code while plugin details retain both the failed 80 ms call and the successful call.
  • pnpm test --run: 52 files passed, 366 tests passed, 2 skipped.
  • pnpm lint, pnpm typecheck, and pnpm build passed.

Timings follow the enclosing transform request. This change does not define separate timing snapshots for repeated nested this.load() calls within that request.

Keep load calls without code results in separate timing records tied to the request that produces the module snapshot. Clear pending records when requests finish or modules invalidate.

Preserve request identity through batched writes and replace stale code snapshots on native file-read retries so failed attempts do not pollute successful loads.
@pkg-pr-new

pkg-pr-new Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@606

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@606

@vitejs/devtools-oxc

npm i https://pkg.pr.new/@vitejs/devtools-oxc@606

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@606

@vitejs/devtools-vite

npm i https://pkg.pr.new/@vitejs/devtools-vite@606

@vitejs/devtools-vitest

npm i https://pkg.pr.new/@vitejs/devtools-vitest@606

commit: e13d837

@webfansplz webfansplz changed the title fix(vite): include declined loads in module timings fix(vite): include no-result load hooks in module timings Oct 9, 2026
@webfansplz
webfansplz merged commit 4cfb4d3 into vitejs:main Oct 9, 2026
7 checks passed
@SaKaNa-Y
SaKaNa-Y deleted the fix/vite-declined-load-timing branch October 9, 2026 13:40
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.

2 participants