Skip to content

Serve /community from the CDN instead of a function per visit - #208

Merged
valebearzotti merged 1 commit into
mainfrom
git-chad/vercel-shader-usage-review
Nov 6, 2026
Merged

valebearzotti merged 1 commit into
mainfrom
git-chad/vercel-shader-usage-review

Conversation

@git-chad

@git-chad git-chad commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Vercel usage for Shader Lab jumped last month: /tools/shader-lab/community had 43K invocations and 16h of active CPU while visitors rose 659%.

The page read searchParams for the ?effect= filter, so with cacheComponents the scene grid was a dynamic hole. The edge served the shell (toolbar, hero, skeleton), and every visit ran a function to render the same 48 scenes, filter or not. getPublicScenes was already "use cache", so the database was mostly spared, but compute grew with every visit. The page has read searchParams since #118; the cost became visible when traffic spiked.

Change

  • The page no longer reads searchParams. The unfiltered "popular" grid prerenders into the static HTML. Publishing and deleting already invalidate COMMUNITY_FEED_TAG.
  • useCommunityEffects reads ?effect= on the client with useSyncExternalStore. Chips update the URL with pushState (prefetch={false}, modifier-clicks still open a tab), and filtered pages come from /api/community/scenes, which already sends s-maxage=60, stale-while-revalidate=300.
  • PublicSceneGrid accepts initialScenes: null and shows a skeleton while a filtered view loads.
  • The middleware matcher is :path+ instead of :path*, so it no longer runs on the index, where it only returned next().

Verified on a production build (next build + next start, Playwright)

  • The route builds as ○ Static (revalidate 15m) instead of ◐ Partial Prerender. The HTML includes the grid and filter (262 KB, was a 36 KB shell).
  • /community and /community?effect=…, HTML and RSC, return x-nextjs-cache: HIT with s-maxage=900.
  • A chip click makes one API fetch, revisits and back/forward make none, and a multi-effect deep link renders filtered after hydration. No hydration errors.

Tradeoffs

  • A shared filtered link shows the unfiltered grid until hydration.
  • Like counts and popular order in the grid can be up to ~15 min stale; publishes and deletes are immediate.
  • Filtered views are client-rendered. The canonical is /community, and per-effect SEO pages stay at /community/effects/[effect].

After deploy, Observability should show /tools/shader-lab/community invocations near zero.

🤖 Generated with Claude Code

The page read searchParams for the effect filter, which made the scene
grid a dynamic hole: every visit ran a Vercel Function to render the same
48 scenes. The grid now prerenders unfiltered into the static page, and
the filter reads the URL on the client and fetches the CDN-cached
/api/community/scenes endpoint. The route builds as Static instead of
Partial Prerender, and the middleware no longer runs on the index.
@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
shader-lab Ready Ready Preview Nov 6, 2026 1:49pm UTC

@valebearzotti
valebearzotti merged commit 60bfa6e into main Nov 6, 2026
4 of 5 checks passed

This branch was successfully deployed

1 active deployment
Preview — 7116993c Deployed Nov 6, 2026 by vercel[bot]
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