Skip to content

tanstack: vendor-router chunk swallows the whole app (manualChunks captures the client entry; global sync sections; preview code in prod bundle) #662

Open

Description

@aline-pereira

Problem

On a TanStack site built with @decocms/tanstack 7.77.2 (deco-sites/oficina-tanstack), every page ships one client chunk called vendor-router of 2.32 MB raw / 758 KB gzip, while main-*.js is 237 bytes. Only ~98 KB of it is router code; the rest is the whole app.

Attribution via source maps (1,735 sources):

Source bytes %
src/components 1,098,258 47.3 %
src/sdk 195,839 8.4 %
src/sections 164,655 7.1 %
motion-dom + framer-motion 137,220 5.9 %
@decocms/blocks 105,116 4.5 % (preview/decoMark.ts 29 KB, cms/schema.ts 15 KB, cms/resolve.ts 10 KB)
@tanstack/router-core + react-router + start-client-core 98,440 4.2 %
src/previews 49,774 2.1 %

Causes

  1. src/vite/plugin.js manualChunks (~l.875-903) sends @tanstack/react-start-client, @tanstack/start-client-core and the @tanstack/start catch-all to vendor-router. That includes the client entry (StartClient), and Rollup treats a manual chunk as a pseudo-entry: every module reachable only through it (router → routeTree → cmsRoute → .deco/sections.gen.ts → every sync = true section and its components) is assigned to the same chunk.
  2. sync = true sections are registered globally in .deco/sections.gen.ts (import * as _syncN), so a section used on a single page (e.g. My Account, 288 KB of components) lands on every page.
  3. Admin/preview-only code reaches the production client bundle: @decocms/blocks/src/preview/decoMark.ts, cms/schema.ts, cms/resolve.ts, and the site's previews/* (export { Preview } from each section).

Measured on the site: removing sync from 23 single-page sections drops the chunk by 54 KB gzip (−7 %) on every page; the structural fix belongs in the plugin.

Proposal

  • manualChunks should not capture the client entry/start-client-core; keep vendor-router to router packages only.
  • Register sync sections per page/route (or let the generator emit per-page chunks) instead of one global eager import.
  • Strip preview/admin modules (decoMark, schema, Preview exports) from production client builds.

Found while validating deco-sites/oficina-tanstack#479 (QA-165).

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions