fix: warm Vite entries before exposing dev server#61
Merged
Conversation
Vite's depsOptimizer.entries scan kicks off on server creation but doesn't block request handling, so the first inspector iframe load can race the optimizer and produce a 504 with a blank widget — exactly when a developer is forming a first impression. Warm each resource and tool entry, then await requests-idle, before runMCPServer starts. Adds ~300ms to startup against the template (4 resources + 7 tools); skipped under --prod-resources where the Vite server isn't used.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Vite's
depsOptimizer.entriesscan kicks off on server creation but doesn't block request handling, so the first inspector iframe load can race the optimizer and produce a 504 with a blank widget. This change callswarmupRequest()for every resource and tool entry in parallel, then awaitswaitForRequestsIdle()beforerunMCPServerstarts, so pre-bundling has fully settled before any host can hit the server. Adds ~300ms to startup against the template (4 resources + 7 tools); skipped under--prod-resourceswheremcpViteServeris created but unused. Production servers (production-server.ts) have no Vite in the loop and are unaffected.Test plan
pnpm --filter sunpeak lintpnpm --filter sunpeak typecheckpnpm --filter sunpeak test -- --run(367 passed)sunpeak devagainst the template — loggedWarmed Vite (11 entries) in 315ms, MCP listened, inspector connected