Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builds are non-deterministic #11911

Closed
7 tasks done
Rich-Harris opened this issue Feb 2, 2023 · 8 comments · Fixed by #12497
Closed
7 tasks done

Builds are non-deterministic #11911

Rich-Harris opened this issue Feb 2, 2023 · 8 comments · Fixed by #12497
Labels
p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Comments

@Rich-Harris
Copy link
Contributor

Describe the bug

Running vite build twice can, in some circumstances, result in different chunking. Unfortunately the only repro I have uses SvelteKit (it comes from sveltejs/kit#8291) — I haven't been able to simplify it further.

Reproduction

https://github.com/Rich-Harris/vite-non-deterministic-build-repro

Steps to reproduce

git clone git@github.com:Rich-Harris/vite-non-deterministic-build-repro.git
cd vite-non-deterministic-build-repro
pnpm i
pnpm test
pnpm test
pnpm test
pnpm test

System Info

System:
    OS: macOS 12.6.3
    CPU: (10) arm64 Apple M1 Max
    Memory: 5.13 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.0/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.0/bin/npm
  Browsers:
    Chrome: 109.0.5414.119
    Chrome Canary: 112.0.5574.0
    Firefox: 109.0.1
    Safari: 15.6.1
  npmPackages:
    vite: ^4.0.3 => 4.0.4

Used Package Manager

pnpm

Logs

No response

Validations

@sun0day
Copy link
Member

sun0day commented Feb 8, 2023

The ./src/lib/ComponentA.svelte?svelte&type=style&lang.css and ./src/lib/ComponentB.svelte?svelte&type=style&lang.css virtual modules will generate the same css as below via @sveltejs/vite-plugin-svelte.

main.svelte-66r8fo{max-width:1024px;margin:0 auto;background:red}h1.svelte-66r8fo{font-size:2rem}

Is this as expected?

@Rich-Harris
Copy link
Contributor Author

Yep, that's expected

@sun0day
Copy link
Member

sun0day commented Feb 9, 2023

Two same css chunks will generate the same source code hash. Rollup has a Map to cache chunk hash.

The problem happens due to the css-post plugin's async renderChunk, can't guarantee the chunks emit order.

I see two options:

  • css-post plugin add some extra no-side-effect code to the chunk to make chunks' hash diff
  • ask Rollup to expose an API to detect whether a chunk source code hash exists

@bluwy @sapphi-red

@sapphi-red
Copy link
Member

If I understand your comment correctly, this could happen without Vite.

I think it would be great if we can provide a reproduction (or a simplified repo that demonstrates the problem) and create a issue in rollup.

@sun0day
Copy link
Member

sun0day commented Feb 18, 2023

If I understand your comment correctly, this could happen without Vite.

I think it would be great if we can provide a reproduction (or a simplified repo that demonstrates the problem) and create a issue in rollup.

A simplified repo is here: https://stackblitz.com/edit/vitejs-vite-acbane?file=src%2Fdom2%2Findex.ts,src%2Fdom1%2Findex.ts,src%2Findex.ts,vite.config.ts,src%2Fdom1%2Fdom1.css,build.js,package.json,src%2Fdom2%2Fdom2.css,_gitignore&terminal=dev

repro step:

  • clone it to your local
  • npm run build serveral times, and you will see the the CSS asset name would be dom1.css or dom2.css randomly

@sapphi-red
Copy link
Member

@sun0day Thanks! I created a issue to rollup to discuss whether this can be fixed in rollup.
rollup/rollup#4909

@sapphi-red
Copy link
Member

Reopening as the PR was partially reverted in rollup.

My thoughts: rollup/rollup#4919 (comment)

@sapphi-red sapphi-red reopened this Mar 27, 2023
@bluwy
Copy link
Member

bluwy commented Apr 7, 2023

Fixed in #12558

@bluwy bluwy closed this as completed Apr 7, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants