sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
17.81k stars 1.78k forks source link

immutable chunks output is different every build for chunks depending on `$app/stores` #12126

Closed jacobpake closed 1 month ago

jacobpake commented 1 month ago

Describe the bug

Immutable chunks with references to $app/stores get a different hash on every build.

My component

<script>
  import { page } from "$app/stores";
</script>

{$page.url.pathname}

Produces the following outputs on immediately subsequent builds with no code changes:

.svelte-kit/output/client/_app/immutable/chunks/MyComponent.CrIxeNgb.js
.svelte-kit/output/client/_app/immutable/chunks/MyComponent.BDsT9bSS.js

MyComponent-{hash}.js imports page from stores-{hash}.js which imports from entry-{hash}.js.

entry-{hash}.js is different on every build because of the version number.

If this is not by design, is there any way to separate the version number from these stores (and other entry.js exports which do not rely on the version number)?

If this is by design, are there any suggestions to avoid this?

My desired outcome is that the output Javascript filename is the same on subsequent builds without code changes.

Reproduction

Minimal reproduction

I have created a new skeleton SvelteKit project, added MyComponent (below) and imported it from two separate pages in routes so that it is included as a chunk.

<script>
  import { page } from "$app/stores";
</script>

{$page.url.pathname}

Logs

No response

System Info

Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v20.10.0/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
    bun: 1.1.2 - ~/.nvm/versions/node/v20.10.0/bin/bun
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.2.0 
    @sveltejs/kit: ^2.0.0 => 2.5.6 
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.1.0 
    svelte: ^4.2.7 => 4.2.14 
    vite: ^5.0.3 => 5.2.8

Severity

annoyance

Additional Information

No response

jacobpake commented 1 month ago

I have changed the kit.version.name to the current commit hash as suggested here and that fixes the issue for me

gregg-cbs commented 1 day ago

I need this too. I have added a javascript error handler that logs errors to our slack. You cannot believe the amount of errors we are getting from facebook and tiktok trying to preload the site but the files it knows of have changed and its failing to preload css and js because the file names are constantly changing.

The fact that all file hashes change without changes even happening in the files is terrible behaviour.