Client bundle lists collections in load-completion order, so identical builds get different chunk hashes
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 89/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- bun, node.js, nuxt, typescript, vite
- Ambito
- build-system, performance
Direzione di ricerca
Leggi src/core/bundle.ts nella sezione relativa a resolveBundleIcons e test/bundle.test.ts; l’issue include una riproduzione e propone un ordinamento deterministico. Inizia eseguendo lo scenario di test fornito e controllando l’ordine attuale delle collection. Il lavoro è completato quando le collection vengono risolte in un ordine stabile per punti di codice e il test di regressione passa.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Environment
@nuxt/icon2.6.3 (the same code is onmainat 28c9943)nuxt4.6.4,vite8.3.8,@iconify/utils3.1.7- Linux x64, Bun 1.4.4 (
bun --bun nuxt build) and Node 22.23.4
Reproduction
nuxt.config.ts, with @iconify-json/lucide, @iconify-json/ph, @iconify-json/cib and @iconify-json/simple-icons installed:
export default defineNuxtConfig({
modules: ['@nuxt/icon'],
icon: {
clientBundle: {
icons: [
'lucide:arrow-down', 'lucide:x', 'lucide:check',
'ph:gear', 'ph:house', 'ph:user',
'cib:ideal', 'cib:bancontact',
'simple-icons:github', 'simple-icons:americanexpress',
],
},
},
compatibilityDate: '2026-11-01',
})
The order is easiest to see with the exported resolver. order.mjs in the project root:
import { resolveBundleIcons } from '@nuxt/icon/utils'
const { collections } = await resolveBundleIcons({
icons: [
'lucide:arrow-down', 'lucide:x', 'lucide:check',
'ph:gear', 'ph:house', 'ph:user',
'cib:ideal', 'cib:bancontact',
'simple-icons:github', 'simple-icons:americanexpress',
],
})
console.log(collections.map(c => c.prefix).join(','))
Each run needs its own process, because the collection loader caches within one:
seq 64 | xargs -P 8 -I{} bun order.mjs | sort | uniq -c
44 lucide,cib,ph,simple-icons
18 lucide,cib,simple-icons,ph
1 cib,lucide,simple-icons,ph
1 cib,lucide,ph,simple-icons
node order.mjs gives three orders as well (61 / 2 / 1 out of 64), less often.
Effect on builds
The resolved collections are serialized as they are into nuxt-icon-client-bundle.mjs. When their order changes, the chunk that holds the client bundle changes, though its only difference is the order of the collections inside JSON.parse(...). Every chunk that imports it then gets a new hash as well.
I built three identical copies of the app above at the same time, as on a busy CI runner, round after round with bun --bun nuxt build:
| Builds | Collection orders | Distinct sets of _nuxt/*.js names |
|
|---|---|---|---|
| 2.6.3 | 36 | 3 | 3 |
| 2.6.3 with the fix below | 36 | 1 | 1 |
The two most common orders differ in 8 of this app's 13 chunk names. Six sequential builds on an idle machine all matched, which makes the problem easy to miss.
In a larger app (115 chunks), two builds whose only difference was a stylesheet that no script references renamed 51 chunks. The only root of those renames was the chunk holding the client bundle. Returning visitors download those chunks again after each deploy, even though their code is unchanged.
Expected
Identical inputs produce identical chunk names.
Cause
resolveBundleIcons loads collections inside Promise.all. addIcon adds a collection to the collections map when its first icon resolves, so the map holds the collections in the order their files finished loading:
- https://github.com/nuxt/icon/blob/28c9943893a4f5609b2ec79afe22768170df9fae/src/core/bundle.ts#L115-L123
- https://github.com/nuxt/icon/blob/28c9943893a4f5609b2ec79afe22768170df9fae/src/core/bundle.ts#L145-L170
#446 (for #445) sorted the icons inside each collection, but the collections are still returned in insertion order:
With scan: true, the order in which the loads start varies too, because scanned files are read in parallel. Both the module's client bundle (src/context.ts) and the standalone Vite plugin (src/vite.ts) use this function.
Suggested fix
return {
- collections: [...collections.values()],
+ collections: [...collections.values()].sort((a, b) => a.prefix < b.prefix ? -1 : a.prefix > b.prefix ? 1 : 0),
count,
The test below, for test/bundle.test.ts, fails today: custom collections resolve immediately, so without the sort they come back in request order (['zeta', 'alpha']).
it('returns collections in a stable order', async () => {
const collection = (prefix: string) => ({
prefix,
icons: { foo: { body: '<path d="M0 0h24v24H0z"/>' } },
width: 24,
height: 24,
})
const result = await resolveBundleIcons({
icons: ['zeta:foo', 'alpha:foo'],
customCollections: [collection('zeta'), collection('alpha')],
resolvePaths: [root],
})
expect(result.collections.map(c => c.prefix)).toEqual(['alpha', 'zeta'])
})
The comparison is by code point on purpose. Under Node, localeCompare() follows the build machine's locale: LANG=et_EE.UTF-8 sorts zondicons before tabler, and LANG=da_DK.UTF-8 sorts names starting with aa last. The icon-name sort from #446 uses localeCompare(), so it can also differ between machines.
- Lingua principale
- TypeScript
- Stelle
- 1.2k
- Fork
- 103
- Merge medio
- 3g 6h
- PR unite (30g)
- 33
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nuxt/icon
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
nuxt/icon#492 · 1 commento · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 30/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
bug priority: low role: BE stage: now
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
ahmadrosid/nakama#2594 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
milind-soni/OpenMausBot#6495 ·
I maintainer di solito rispondono entro 1 giorno
-
Navigating the session tree adds the branch's prompts to Up-arrow history againForse già presa @acmerfight l’ha presa oggi. Apertauntriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
earendil-works/pi#12279 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
approved documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 89/100
vitest-dev/vitest#12015 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno