next-cache-components-optimizer

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

Updated Aug 26, 2026
One-click install
npx skills add https://github.com/MohamadJoumaa/Direct --skill next-cache-components-optimizer-mohamadjoumaa
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: next-cache-components-optimizer
Source: https://github.com/MohamadJoumaa/Direct/tree/main/.cursor/skills/next-cache-components-optimizer
Command: npx skills add https://github.com/MohamadJoumaa/Direct --skill next-cache-components-optimizer-mohamadjoumaa

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 dynamic data reads, so users wait for the entire page before anything paints. This Skill sets up a repeatable, test-driven loop that moves dynamic reads behind Suspense boundaries so the static shell commits immediately, and ships a regression test that keeps the route instant. ## Core Features & Use Cases - Test-driven optimization loop: Encodes the goal as a failing @next/playwright instant() e2e test (RED), fixes the route, and verifies GREEN on a production build, with a differential check proving the test measures the right property. - Fix pattern library: Provides before/after recipes for every blocker type — top-level awaits, cookies()/headers(), uncached fetches, searchParams, generateMetadata, non-deterministic values, auth gates, and parallel routes. - Rig discovery: Guides one-time setup of a committed instant-nav.rig.md describing how the project builds, exposes the testing API, authenticates the test user, and runs the e2e loop. - Use Case: A dashboard route waits on a charts query before painting anything. The Skill writes a failing instant() test, pushes the data read behind a Suspense boundary reusing the existing skeleton, and verifies the layout now commits instantly on both hard and soft navigations. ## Quick Start Ask the agent to make a specific Next.js route's navigation instant using the next-cache-components-optimizer skill, naming the route to optimize.

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?

Write a failing @next/playwright instant() test that asserts the route's static shell commits under the lock, then push each dynamic read behind a Suspense boundary scoped to the data it guards. Verify the test goes green on a production build and ship it as a regression guard.

How to fix a Next.js route whose static shell is not prerendered?

Run next build with --debug-prerender to find the blocking read, then apply the matching pattern: move top-level awaits into Suspense children, cache stable data with 'use cache', and defer auth gates into a Suspense-wrapped component that renders children unconditionally.

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

No. The workflow requires Next.js 16.3 or later with cacheComponents: true in next.config, because earlier versions have no static shell to optimize. Upgrade first with npx @next/codemod upgrade, then enable Cache Components.

Why does my instant() test pass but the route is still 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 assert deferred content is gated under the lock and give every boundary a real loading skeleton.

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 via 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. Instead use per-link prefetching with Partial Prefetching adopted, a Link prefetch={true}, and the URL-dependent content behind 'use cache' keyed by the resolved params.