diff --git a/.changeset/deterministic-client-build.md b/.changeset/deterministic-client-build.md new file mode 100644 index 000000000000..8ab67911befe --- /dev/null +++ b/.changeset/deterministic-client-build.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a bug where emitted assets during a client build would contain always fresh, new hashes in their name. Now the build should be more stable. diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index a95321d2322e..97112de36244 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -371,9 +371,12 @@ async function buildEnvironments(opts: StaticBuildOptions, internals: BuildInter // So using the noop plugin here which will give us an input that just gets thrown away. internals.clientInput.add(NOOP_MODULE_ID); } - builder.environments.client.config.build.rollupOptions.input = Array.from( - internals.clientInput, - ); + // Sort the client input to ensure deterministic Rollup entry point ordering. + // `internals.clientInput` is a Set whose iteration order depends on async module resolution + // timing during prerendering. Without sorting, consecutive builds of the same + // source code can produce different output filenames, breaking CDN caching. + const sortedClientInput = Array.from(internals.clientInput).sort(); + builder.environments.client.config.build.rollupOptions.input = sortedClientInput; settings.timer.start('Client build'); await builder.build(builder.environments.client); settings.timer.end('Client build');