Skip to content

fix(themes): move chunk rules to Rolldown codeSplitting groups so shared-home holds only home code - #100

Open
HusnainMaroof wants to merge 1 commit into
SallaApp:masterfrom
HusnainMaroof:bugfix/THEM-0000-rolldown-chunk-groups
Open

HusnainMaroof wants to merge 1 commit into
SallaApp:masterfrom
HusnainMaroof:bugfix/THEM-0000-rolldown-chunk-groups

Conversation

@HusnainMaroof

@HusnainMaroof HusnainMaroof commented Nov 1, 2026 •

Copy link
Copy Markdown

Problem

Part of #96. Thanks @fadyehabamer for the measurements.

vite.config.ts asks for three shared chunks, but only shared-home is created. At 523 kB raw / 160 kB gzip it is the largest client chunk, and every page loads it.

Two causes:

  1. Rolldown runs manualChunks as a single group with includeDependenciesRecursively: true. When HomeComponentRenderer / ProductsSlider go into shared-home, every module they import goes with them: the theme's product components, i18next, ky, sonner, TanStack Query, Swiper and the engine. Reordering the ifs does not help. Removing only the shared-home rule makes shared-product appear.
  2. The shared-common matchers never match. @salla.sa/twilight-theme-engine ships prebuilt flat files (dist/Breadcrumb-7QGTM5S5.js, dist/chunk-*.js), so no module id contains /components/common/.

Fix

vite.config.ts only. The same intent moves to build.rolldownOptions.output.codeSplitting.groups, which supports priorities. This is the build's own hint.

  • preload-helper, vendor-react, vendor-router and vendor-hooks keep their current matchers
  • New vendor-core (i18next, ky, sonner, TanStack Query/Virtual) and vendor-swiper
  • New vendor-salla: only the engine modules every page loads. The engine's lazy screens keep their own route chunks
  • shared-common, shared-product and shared-home now each hold what their names say
  • resolveDependencies is unchanged

Results

Client build, gzip -9, same script on both builds:

master a913dfa this PR
shared-home 160.4 kB 8.5 kB
Largest chunk 523 kB raw 265 kB raw, and the 500 kB warning is gone
shared-product / shared-common not emitted 8.1 kB / 13.8 kB
Total client JS 425.4 kB 415.6 kB
JS per page at startup 344.5 kB 338.1 kB

Caching also improves: a theme-only change now invalidates small theme chunks instead of the 160 kB shared-home, and library chunks change only when a dependency is upgraded.

Size budget (#63)

I ran scripts/check-bundle.mjs with size-budget.json from feature/quality-gates-twig-parity-audit against both builds:

  • master already exceeds the shared-home budget by 12.6 kB
  • This PR is 23.7 kB under the total JS budget and 139 kB under the shared-home budget
  • The five new chunks need budget entries (pnpm size:update). Their code moved there from other chunks; nothing was added
  • vendor-react is 0.3 kB over its 5% margin, because React's own dependencies are now captured with it. Turning capture off for that group breaks the SSR build (preserveEntrySignatures: 'strict')

Not fixed here

Every page still loads the home blocks and Swiper, because app/router.tsx imports them statically. They are now small separate chunks rather than part of one 160 kB chunk. Making them lazy from the theme alone saved only about 4 kB more in my tests. The bigger win (up to 60 kB on cart, blog and account pages) needs engine changes:

  • the engine package has no sideEffects field, so barrels pull in ProductPage / CartPage
  • @salla.sa/twilight-theme-engine/skeleton (every route's pendingComponent) imports about 60 engine chunks
  • route modules statically import the engine route objects for loader / head
  • the route generator rewrites route files marked // @auto-generated on each build

Checks

  • pnpm build passes (client and SSR), with no circular-chunk or execution-order warnings
  • pnpm test: 606/606 pass
  • pnpm typecheck passes
  • Not tested against a live store in a browser (the demo store returns 422 "store not found")

Questions

  1. Should this target master or feature/quality-gates-twig-parity-audit? That branch has the size budget and also changes vite.config.ts
  2. Should I add the size-budget.json update to this PR?

…red-home holds only home code

Rolldown runs output.manualChunks as one group with
includeDependenciesRecursively on, so shared-home captured the product
components, the shared libraries, Swiper and the engine, and
shared-product / shared-common were never emitted. The shared-common
matchers also never matched the engine's prebuilt flat files.

Move the rules to build.rolldownOptions.output.codeSplitting.groups
with priorities: vendor-core, vendor-swiper and vendor-salla for
libraries, and shared-common / shared-product / shared-home for theme
code. shared-home drops from 160.4 kB to 8.5 kB gzip and total client
JS from 425.4 kB to 415.6 kB.

Part of SallaApp#96

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sallainternalbot
sallainternalbot Bot marked this pull request as draft November 1, 2026 12:49
@HusnainMaroof
HusnainMaroof marked this pull request as ready for review November 1, 2026 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant