Repository navigation
Description
Astro Info
Astro v6.1.7
Node v24.11.1
System macOS (arm64)
Package Manager unknown
Output static
Adapter none
Integrations @astrojs/react
@astrojs/vue
@astrojs/svelte
If this issue only occurs in one browser, which browser is a problem?
N/A
Describe the Bug
astro build produces different output filenames across consecutive runs with identical source code. This breaks CDN caching — every deploy invalidates cached JS files even when nothing changed.
Reproduction
https://github.com/issueset/astro_build_order_issue.git
pnpm install
pnpm test # runs 10 builds, compares outputRunning 10 builds and comparing output...
Temp dir: /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn
Build 1: 7c17b92b2df44911065cc8e19abf7622
Build 2: 7c17b92b2df44911065cc8e19abf7622
Build 3: 8bc47ea55d5d13a6359f0d39b2461712
^^^ DIFFERS from build 2:
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build2/_astro: SvelteWidget0.CHZtD1E3.js
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build3/_astro: SvelteWidget0.DNGJBpKz.js
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build2/_astro: SvelteWidget1.C_-Zw1cq.js
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build3/_astro: SvelteWidget1.Ch6lmidG.js
(4 total differences)
Build 4: 8bc47ea55d5d13a6359f0d39b2461712
Build 5: 8bc47ea55d5d13a6359f0d39b2461712
Build 6: 8bc47ea55d5d13a6359f0d39b2461712
Build 7: 8bc47ea55d5d13a6359f0d39b2461712
Build 8: 7c17b92b2df44911065cc8e19abf7622
^^^ DIFFERS from build 7:
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build8/_astro: SvelteWidget0.CHZtD1E3.js
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build7/_astro: SvelteWidget0.DNGJBpKz.js
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build8/_astro: SvelteWidget1.C_-Zw1cq.js
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build7/_astro: SvelteWidget1.Ch6lmidG.js
(4 total differences)
Build 9: 8bc47ea55d5d13a6359f0d39b2461712
^^^ DIFFERS from build 8:
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build8/_astro: SvelteWidget0.CHZtD1E3.js
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build9/_astro: SvelteWidget0.DNGJBpKz.js
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build8/_astro: SvelteWidget1.C_-Zw1cq.js
Only in /var/folders/00/y54gq_b567l2cd0qtqqqlysm0000gn/T/tmp.MlsGPfeaxn/build9/_astro: SvelteWidget1.Ch6lmidG.js
(4 total differences)
Build 10: 8bc47ea55d5d13a6359f0d39b2461712
RESULT: Non-deterministic! 3 of 9 consecutive comparisons differed.
Cause
In static-build.ts#L374-L376, client build entry points are passed to Rollup via Array.from(internals.clientInput). clientInput is a Set whose iteration order depends on the order components were discovered during prerendering. That discovery order is non-deterministic because this.getModuleIds() in the plugin-analyzer reflects async module resolution timing (Rollup resolves dependencies in parallel via Promise.all).
When Rollup receives entry points in different order, chunk assignment and hash collision resolution produce different output filenames.
Fix
Sort the array before passing it to Rollup:
See #16348
What's the expected result?
Deterministic build output.
Link to Minimal Reproducible Example
https://github.com/issueset/astro_build_order_issue.git
Participation
- I am willing to submit a pull request for this issue.
Activity
astrobot-houston commentedon Apr 16, 2026
I was able to reproduce this issue. The root cause is in
packages/astro/src/core/build/static-build.ts, where client build entry points are passed to Rollup viaArray.from(internals.clientInput)without sorting. TheclientInputSet's iteration order depends on insertion order from theplugin-analyzer, which usesthis.getModuleIds()— an API whose iteration order is non-deterministic due to parallel async module resolution. When Rollup receives entry points in different orders, chunk assignment and content-hash computation produce different output filenames.I was able to fix this issue. The fix adds
.sort()to theArray.from(internals.clientInput)call at line 374 ofstatic-build.ts, ensuring Rollup always receives entry points in a stable lexicographic order regardless of module discovery timing. View Suggested FixP4: important. This affects any project using multiple client-side framework components (e.g. React + Vue + Svelte with hydration directives) — every deploy can invalidate CDN caches even when source code hasn't changed. While it doesn't cause runtime errors, it violates the expected behavior that identical source produces identical output, and it significantly impacts caching and deployment pipelines for production sites.
Full Triage Report
No
report.mdwas generated by prior triage steps. The following analysis was performed directly from the source code and issue description.Root Cause
In
packages/astro/src/core/build/plugins/plugin-analyzer.ts:23, thegenerateBundlehook iterates overthis.getModuleIds(). The order of IDs returned by this Rollup/Vite API depends on the order modules were resolved, which is non-deterministic because Rollup resolves dependencies in parallel.As the analyzer discovers hydrated components, client-only components, and scripts, it inserts them into Maps/Sets on
BuildInternals(discoveredHydratedComponents,discoveredClientOnlyComponents,discoveredScripts). These are later collected bygetClientInput()(static-build.ts:610-630) into a singleSet<string>.At
static-build.ts:374, this Set was converted to an array viaArray.from(internals.clientInput)and passed directly as Rollup'sinput. SinceSetpreserves insertion order, and insertion order is non-deterministic, Rollup received entry points in varying order across builds, producing different chunk names/hashes.Fix
A one-line change adding
.sort()to theArray.from()call:builder.environments.client.config.build.rollupOptions.input = Array.from( internals.clientInput, - ); + ).sort();This ensures Rollup always receives entry points in a stable lexicographic order, producing deterministic output filenames.
Verification
The fix is on branch
flue/fix-16347(commita17a59f4ed). The change is minimal and isolated to the client build input ordering — it does not affect SSR, prerender, or any other build phase.This report was made by an LLM. Mistakes happen, check important info.
leifmarcus commentedon Apr 16, 2026
We had the same issue and found a solution for this. Here is how we changed our config
ocavue commentedon Apr 16, 2026
@leifmarcus Thanks for letting me know. I guess
maxParallelFileOps: 1will slow down the build, andminifyInternalExports: falsewill increase the file size.I wonder if you still need these two workarounds after my patch is released. If you can still reproduce the non-deterministic issue, perhaps there is another place that needs
.sort().pdig-tobiasbreit commentedon Apr 16, 2026
@ocavue is your change/suggestion already merged?
ocavue commentedon Apr 16, 2026
Not yet. See #16348