next-cache-components-optimizer

Drives Next.js routes to instant navigation using test-driven Cache Components optimization.

Updated Aug 5, 2024
One-click install
npx skills add https://github.com/SethyRung/movie-next --skill next-cache-components-optimizer-sethyrung
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: next-cache-components-optimizer
Source: https://github.com/SethyRung/movie-next/tree/main/.agents/skills/next-cache-components-optimizer
Command: npx skills add https://github.com/SethyRung/movie-next --skill next-cache-components-optimizer-sethyrung

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @next/playwright, @playwright/test, next, and includes references (resource) components.

What problem does it solve? Next.js routes often block navigation on top-level awaits, uncached data reads, or misplaced Suspense boundaries, leaving users staring at blank screens. This Skill sets up a repeatable, test-driven loop that proves a route's static shell commits instantly and ships a regression guard so it stays that way. ## Core Features & Use Cases - Test-driven optimization loop: Encodes the goal as a failing @next/playwright instant() e2e test (RED), works it to green by pushing Suspense boundaries down to the data they guard, and ships the test as a regression guard. - Fix pattern library: Provides before/after recipes for common blockers including top-level awaits, cookies()/headers() reads, uncached fetches, searchParams, dynamic metadata, and non-deterministic values. - Robustness gates: Includes a RED-verification checklist, differential testing (revert fix → RED, re-apply → GREEN), and parity checks so the refactor changes only whether the route is instant. - Use Case: A dashboard route waits on a charts query before painting anything. The Skill drives a real <Link> click under the instant() lock, confirms the shell is missing, hoists the layout UI into the static shell, defers the charts read behind a Suspense boundary with the existing skeleton, and verifies the shell now commits instantly at desktop and mobile widths. ## Quick Start Ask the agent to make a specific route's navigation instant using the next-cache-components-optimizer skill, for example: make navigating to /movies instant and ship the instant() e2e guard for it.

Frequently Asked Questions about next-cache-components-optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make a Next.js route navigation instant with Cache Components?

Encode the goal as a failing @next/playwright instant() test, then push each Suspense boundary down to the single data read it guards while hoisting static layout UI into the shell. The route is done when the locked test passes green on a production build and a revert of the fix turns it red again.

How to fix a top-level await blocking the Next.js static shell?

Make the page or layout synchronous and move the await into a Suspense-wrapped child component that receives the params or data promise as a prop. Only that leaf streams; the stable ancestors prerender into the static shell.

Does this optimization work with Next.js versions before 16.3?

No. The workflow requires Next.js 16.3 or later with cacheComponents: true in next.config, because without Cache Components there is no static shell to optimize. Upgrade first, then run the optimizer once the app builds under Cache Components.

Why does my instant() test pass but the route still feels slow?

A green instant() test can be vacuous if the build lacks experimental.exposeTestingApiInProductionBuild, since the lock silently no-ops. It can also pass with an empty fallback shell, so verify the testing API is exposed and assert deferred content is gated under the lock.

Can I measure instant navigation on next dev?

No. next dev does not prefetch and its lock is unreliable for blocking routes, so a dev instant() result is not a valid verdict. Always measure on a production build such as next build && next start, a staging container, or a preview deploy.

What if a route depends entirely on URL params or searchParams?

When URL data cannot be pushed down, there may be no meaningful shared static shell to grow, so do not force one. Per-link prefetching with <Link prefetch={true}> under Partial Prefetching is the alternative, but it sits outside this optimizer loop.