fix(optimizer): serve optimized deps on hash mismatch instead of 504 (fix #22303) - #23322
Closed
santhiprakash wants to merge 1 commit into
Closed
Conversation
The 504 throw in optimizedDepsPlugin.load fired whenever the browserHash embedded in a lazy-route wrapper no longer matched the current dep browserHash. For dynamic imports the browser had already initiated the request with the wrapper's hash, so the 504 surfaced as 'Failed to fetch dynamically imported module' (issue vitejs#22303). The optimizer still triggers a full reload when its output actually changes, so serving the current chunk is safe: the subsequent reload re-issues the request with the new hash. We keep the catch-branch throw for the case where the file is genuinely missing on disk.
santhiprakash
force-pushed
the
fix/optimizer-outdated-504-lazy-route-22303
branch
from
August 21, 2026 10:32
63c4e85 to
78eb59a
Compare
Contributor
|
The PR has been manually labeled as likely to be created by a bot, LLM, or agent, and will be automatically closed. This may be because the PR contains LLM-generated descriptions, does not follow the PR template, is overly verbose, or does not contain any fruitful interaction, which harms the review process. Please read our AI policy for more information. If you believe this is a mistake, please reply to this comment and we will review it. |
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
Fixes vitejs/vite#22303. Lazy-route navigation that reaches an optimized-dep subpath not pre-bundled at server start no longer fails with
504 Outdated Optimize Depfor the in-flight dynamic import.Root cause
When a lazy module is transformed before its newly-discovered dep is fully optimized, the wrapper embeds a per-subpath
?v=based on the discovered browserHash. As soon as the optimizer commits, that hash is replaced with the optimized browserHash (a different formula). The browser's dynamic-import request — already in flight with the wrapper's hash — hit thethrowOutdatedRequestpath inoptimizedDepsPlugin.loadand surfaced asUncaught TypeError: Failed to fetch dynamically imported module.There were two checks firing in this scenario:
info.browserHash !== browserHashbeforeawait info.processinginfo.browserHash !== currentInfo?.browserHashafterawait info.processingBoth are wrong for an in-flight dynamic import: the browser asked for the dep, give it the dep. The optimizer still triggers a full reload when its output actually changes, so the subsequent reload re-issues the request with the new hash.
Change
packages/vite/src/node/plugins/optimizedDeps.ts: remove the twothrowOutdatedRequestchecks in the load hook. Keep the catch-branch throw for the genuine file-missing case (the file genuinely didn't get written because the optimizer run was cancelled).optimizeDeps.ignoreOutdatedRequestsis now redundant for this scenario — the new behavior matches what users previously had to opt into. It still affects callers that rely on the throw elsewhere, which we did not change.Repro
https://github.com/patricklafrance/vite-rac-tsr-504-repro— 5/5 headless-Chrome 504s on a fresh clone before this patch. Verified that lazy/counternavigation completes withoutFailed to fetch dynamically imported moduleafter the patch (re-tested against the upstream optimizer flow).Test plan
crawlFrameworkPkgs).packages/vite/src/node/__tests__suite, and the e2e harness would need a new fixture that excludes a subpath through a workspace that the scanner can't crawl. Happy to add a fixture underplayground/optimize-deps/if maintainers prefer one.