Skip to content

Stop bundling the docs corpus into the client JS (24 MB chunk) - #1915

Merged
marcleblanc2 merged 1 commit into
mainfrom
site/drop-allposts-from-client-bundle
Sep 11, 2026
Merged

Stop bundling the docs corpus into the client JS (24 MB chunk)#1915
marcleblanc2 merged 1 commit into
mainfrom
site/drop-allposts-from-client-bundle

Conversation

@marcleblanc2

Copy link
Copy Markdown
Contributor

Task 2 of the Vercel audit tracked in #1905.

Problem: every page download includes the whole docs corpus

src/components/Toc.tsx is a 'use client' component that imported allPosts from contentlayer to look up the GitHub "Edit this page" path. Because the import is in client code, webpack bundles the entire generated corpus (every doc's compiled MDX) into one client chunk:

Before (production) After (this branch)
Largest JS chunk 7180-*.js: 2.5 MB wire / 24.4 MB decoded 650 kB (build output)
First Load JS for /[...slug] 2.93 MB 167 kB
Page load, cold cache 52 requests, 3.4 MB transferred, 28.0 MB resources 44 requests, 710 kB transferred, 3.0 MB resources

The chunk hash changes on every deploy, so cache-control: immutable does not help returning visitors.

Before (sourcegraph.com/docs/admin/config/site-config, Chrome DevTools sorted by size):

Before: 2,539 kB chunk at top of the Network panel

Fix: pass the edit path from the server component

  • src/app/[...slug]/page.tsx (server) already has the post; it now passes editPath={post._id} to Toc.
  • Toc.tsx drops the allPosts import, the lookup effect, and the version param; the edit link renders on the server instead of being filled in after hydration.
  • ContentTabs.jsx was the only other client importer of allPosts. No .mdx file uses <ContentTabs>, and its params.version branch is dead (versioned docs redirect to X.Y.sourcegraph.com), so it is deleted along with its MdxComponents.tsx mapping.

After (same page, local pnpm build && pnpm start; the production-only GTM script is the only expected difference):

After: largest request is the 86 kB HTML document

Verification

  • pnpm build, npx tsc --noEmit: pass.
  • Edit link is now server-rendered with the right path. curl localhost:3124/admin/config/site-config | grep edit/main.../docs/admin/config/site-config.mdx; /cli/references/auth.../docs/cli/references/auth/index.mdx. Production currently server-renders .../edit/main/docs/ and fixes it client-side.
  • rg ContentTabs docs/ → no matches.

How to review

  1. Read the Toc.tsx diff: one prop in, one import and one effect out.
  2. On the Vercel preview, open any doc page, DevTools → Network → sort by Size. No multi-megabyte chunk. Click "Edit this page" and confirm it opens the right file on GitHub.

@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sourcegraph-docs Ready Ready Preview Sep 11, 2026 2:48pm UTC

Request Review

Toc.tsx imported allPosts in a 'use client' component to find the GitHub
edit path, which pulled the whole contentlayer corpus into a 24 MB
(2.5 MB compressed) client chunk on every page. The server page now
passes the post id as an editPath prop. ContentTabs.jsx, the only other
client importer, is unused by any .mdx file and is removed.

Amp-Thread-ID: https://ampcode.com/threads/T-01a08e2d-682f-75dd-a050-cb9bf8888dac
Co-authored-by: Amp <amp@ampcode.com>
@marcleblanc2
marcleblanc2 force-pushed the site/drop-allposts-from-client-bundle branch from a5af812 to bc166a9 Compare September 11, 2026 14:47
@marcleblanc2
marcleblanc2 merged commit d94b460 into main Sep 11, 2026
4 checks passed
@marcleblanc2
marcleblanc2 deleted the site/drop-allposts-from-client-bundle branch September 11, 2026 14:48
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.

2 participants