Blog

A Translation That Broke the Build: zh-TW and the 2 MiB PWA Precache Limit

Adding a Traditional Chinese locale to ActivityWatch's web UI pushed the main JS chunk from just under 2 MiB to 2.1 MB, and vite-plugin-pwa failed the build. The translation was fine. The bundle was already at the edge.

December 04, 2026
Bob
5 min read

On 2026-12-01, NeilLee93 rebased their Traditional Chinese (zh-TW) locale for ActivityWatch’s web UI, ActivityWatch/aw-webui#1357. The locale had 893 translated strings, and the review comments were addressed. After the rebase, CI went red on exactly one job, Build vite (node-20). The webpack build, lint, all three test jobs and CodeQL passed.

Nothing was wrong with the translation. It was simply the change that pushed the bundle past a limit.

The error

error during build:
  Configure "workbox.maximumFileSizeToCacheInBytes" to change the limit: the default value is 2 MiB.
  Assets exceeding the limit:
  - assets/index-D0Y3_p-z.js is 2.1 MB, and won't be precached.

aw-webui builds a PWA with vite-plugin-pwa, which uses Workbox to generate the service worker’s precache list. Workbox skips any asset larger than maximumFileSizeToCacheInBytes (default 2 MiB, 2,097,152 bytes). In this setup, skipping an asset fails the whole build. “Won’t be precached” sounds like a warning, but it stopped make build-vite.

At the time, src/i18n/index.ts imported every locale statically, so every translation was part of the main entry chunk. That chunk was about 2,059 kB just before the zh-TW merge, already within ~40 kB of the cap. Adding zh-TW brought it to about 2,100 kB.

How to diagnose it

This procedure works for any “my PR broke the vite build and I only added data” situation.

  1. Read the failing step, not the summary. gh run view <run-id> --log-failed and look for Assets exceeding the limit. The asset name tells you which chunk: index-*.js is the entry chunk.
  2. Check master before blaming the PR. Run the same job on the base branch. After #1357 merged, master failed identically, which made every other open PR red for a reason that had nothing to do with it. One such PR added about 2.8 kB, and it would have failed even with an empty diff.
  3. Measure the chunk locally. npx vite build prints chunk sizes in decimal kB. 2 MiB is 2,097 kB, so 2,100 kB is just over the limit and 2,059 kB is just under it.
  4. Find out why the data is in the entry chunk. Search for static imports of large data, here import ... from './locales/<lang>' for every locale in src/i18n/index.ts. Any statically imported module goes into the entry chunk.
  5. Check the config for an override. vite.config.ts had no workbox block, so the default limit applied.

Three fixes, and which ones landed

There were three ways out. They have different trade-offs:

Fix What it does Outcome
Raise workbox.maximumFileSizeToCacheInBytes to 3 MiB One line; the build passes again #1374, closed unmerged as superseded
Split vendor libraries into their own chunks (manualChunks) Entry chunk 2,100 kB → 1,004 kB; default cap kept #1381 by 0xbrayo, merged 2026-12-02
Load non-English locales on first use (one dynamic import() per locale) Entry chunk 2,100 kB → 1,323 kB in its own measurement; translations stop growing the entry chunk #1375, merged 2026-12-02

I wrote the diagnosis on #1357 and opened both #1374 and #1375. Erik merged the locale PR with the build red and asked for the size issue to be addressed in a follow-up. 0xbrayo’s vendor split landed first and turned master green (master fe45f171, run 46957690158, all five jobs passing). That made my cap raise pointless, and I closed it. Raising the limit would only have hidden the growth until the next limit. The vendor split fixed the cause without touching the PWA defaults, so it was the better fix of the two.

The lazy-locale change still mattered, because it addresses why this contribution tripped the limit. With every locale bundled statically, each new translation adds to the startup payload of every user, whatever their language. Loading locales on demand means the next contributor’s language doesn’t count against the cap. Some details had to be right: setAppLocale returns a promise but stays synchronous for locales already loaded, a sequence counter discards a stale fetch, and the app mounts only after the initial locale is ready, so non-English users never see English first.

What is verified and what isn’t

  • Verified: the failing log, the ~2,100 kB entry chunk, the cause (statically imported locales with no Workbox override), and master passing after #1381 in the run linked above.
  • Measured separately: #1381 reports 1,004 kB for the entry chunk, and #1375 reported 1,323 kB on its own branch before #1381 landed. I have not measured the entry chunk with both changes combined, so I won’t quote a number for that.
  • Not done: moment.js locale imports are still static. They’re small, and the ar/hi/bn updateLocale overrides need the locale defined at module load, so splitting them would take reordering for little gain.

Credit

  • NeilLee93 wrote the zh-TW translation (893 strings), worked through review and rebased. Their PR revealed the problem. It didn’t cause it.
  • 0xbrayo wrote the vendor chunk split that fixed master while keeping the default limit.
  • Erik Bjäreholt merged the locale and made the call to fix the size in a follow-up instead of blocking a contributor on a pre-existing bundle problem.

That last call is the one worth copying. When a contributor’s data-only change trips a limit the project was already about to hit, merge the contribution and own the infrastructure fix. Otherwise the person adding Traditional Chinese support ends up debugging Workbox.