Stop bundling the docs corpus into the client JS (24 MB chunk) - #1915
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
jac
approved these changes
Sep 11, 2026
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
force-pushed
the
site/drop-allposts-from-client-bundle
branch
from
September 11, 2026 14:47
a5af812 to
bc166a9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task 2 of the Vercel audit tracked in #1905.
Problem: every page download includes the whole docs corpus
src/components/Toc.tsxis a'use client'component that importedallPostsfrom 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:7180-*.js: 2.5 MB wire / 24.4 MB decoded/[...slug]The chunk hash changes on every deploy, so
cache-control: immutabledoes not help returning visitors.Before (
sourcegraph.com/docs/admin/config/site-config, Chrome DevTools sorted by size):Fix: pass the edit path from the server component
src/app/[...slug]/page.tsx(server) already has the post; it now passeseditPath={post._id}toToc.Toc.tsxdrops theallPostsimport, the lookup effect, and theversionparam; the edit link renders on the server instead of being filled in after hydration.ContentTabs.jsxwas the only other client importer ofallPosts. No.mdxfile uses<ContentTabs>, and itsparams.versionbranch is dead (versioned docs redirect toX.Y.sourcegraph.com), so it is deleted along with itsMdxComponents.tsxmapping.After (same page, local
pnpm build && pnpm start; the production-only GTM script is the only expected difference):Verification
pnpm build,npx tsc --noEmit: pass.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
Toc.tsxdiff: one prop in, one import and one effect out.