Skip to content

Non-deterministic build output: identical source produces different JS filenames #16347

@ocavue

Description

@ocavue

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 output
Running 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions