-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Vite dependency optimization re-evaluates server modules during in-flight requests #18130
Copy link
Copy link
Open
Labels
- P4: importantViolate documented behavior or significantly impacts performance (priority)Violate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)Related to the core `astro` package (scope)pkg: cloudflareRelated to the Cloudflare adapterRelated to the Cloudflare adaptertriage: fix verifiedReporter confirmed the triage bot fix worksReporter confirmed the triage bot fix works
Description
Activity
Metadata
Metadata
Assignees
Labels
- P4: importantViolate documented behavior or significantly impacts performance (priority)Violate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)Related to the core `astro` package (scope)pkg: cloudflareRelated to the Cloudflare adapterRelated to the Cloudflare adaptertriage: fix verifiedReporter confirmed the triage bot fix worksReporter confirmed the triage bot fix works
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
After switching from astro 5 to workers and astro 7, we started seeing a lot of issues with local development and optimize deps.
This is one of the issues we have been able to reliably reproduce so far.
During development, Vite can discover and optimize a new dependency while a server request is already being processed. This can happen with a dynamic import or when calling an Astro action directly from an
.astrofile.The request then spans two module generations.
In the reproduction, middleware stores a request ID using
AsyncLocalStorage. After dependency optimization reloads the server, later code sees a new module instance and the request context is lost.The reproduction also demonstrates the same behavior with a plain exported object: a value stored by middleware is missing after optimization. This shows that the issue is caused by module re-evaluation, not
AsyncLocalStorageitself.We are seeing this specifically when using the Cloudflare plugin.
What's the expected result?
Any context or in-memory state set before optimization should still be available afterward.
Link to Minimal Reproducible Example
https://github.com/TorbjornHoltmon/vite-cloudflare-optimize-deps-repro
Participation