Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

nextjs-static-shells

FreeNo executable scriptsNot checked

Static-first Next.js 16 architecture patterns: cached shells with dynamic slots, provider islands, 'use cache' boundaries, and link preloading strategy. Use…

joelhooksby joelhooks★ 69 GitHub stars

About this skill

Static-First Next.js 16 Patterns

Build a static shell first, then cut small dynamic holes where personalization or request-specific behavior is required.

  • Static shell = deterministic, cacheable, fast first paint
  • Dynamic holes = isolated request/user behavior streamed with Suspense
  • Client interactivity = provider islands, not global client sprawl

Route Architecture: Entry + Static + Slots

Pattern

  1. Entry component (server, request-aware)
    • Reads params/search/auth/session/cookies
    • Validates access, resolves IDs, prepares dynamic props
  2. Static renderer (server, 'use cache')
    • Renders deterministic layout/content
    • Accepts dynamic UI as slot props (ReactNode)
  3. Dynamic slots
    • Injected from entry component
    • Suspense-wrapped where rendered in static shell

Why This Works

  • Static shell stays cacheable
  • Dynamic behavior is explicit and narrow
  • Streaming keeps UI responsive
  • No accidental full-route dynamic bailout
import { Suspense, type ReactNode } from 'react';

type PageProps = { params: Promise<{ slug: string }> };

/** Request-aware server entry. */
export default async function PageEntry({ params }: PageProps) {
  const { slug } = await params;

  const staticData = await getStaticData(slug); // deterministic
  const userData = await getUserData(); // request-dependent

  const dynamicPanel = <PersonalizedPanel userData={userData} />;

  return <PageStatic data={staticData} panel={dynamicPanel} />;
}

type PageStaticProps = {
  data: StaticData;
  panel?: ReactNode;
};

/** Cached static shell. Keep request-volatile reads out. */
async function PageStatic({ data, panel }: PageStaticProps) {
  'use cache';

  return (
    <main>
      <Hero data={data.hero} />
      <Content data={data.content} />
      <Suspense fallback={<PanelSkeleton />}>{panel}</Suspense>
    </main>
  );
}

Cache Components Setup & Mechanics

Enable

// next.config.ts
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  cacheComponents: true,
}

export default nextConfig

Replaces the old experimental.ppr flag.

Three Content Types

Type Characteristic Example
Static Synchronous, pure computation <header><h1>Our Blog</h1></header>
Cached ('use cache') Async but deterministic for given inputs db.posts.findMany() with cacheLife('hours')
Dynamic (Suspense) Runtime/request-specific, must be fresh cookies(), user session, notifications

'use cache' Scope Levels

// File level — entire module cached
'use cache'
export default async function Page() { /* ... */ }

// Component level
export async function CachedComponent() {
  'use cache'
  const data = await fetchData()
  return <div>{data}</div>
}

// Function level
export async function getData() {
  'use cache'
  return db.query('SELECT * FROM posts')
}

Cache Profiles with cacheLife()

import { cacheLife } from 'next/cache'

async function getData() {
  'use cache'
  cacheLife('hours')  // Built-in: 'default' | 'minutes' | 'hours' | 'days' | 'weeks' | 'max'
  return fetch('/api/data')
}

// Or inline config:
async function getDataCustom() {
  'use cache'
  cacheLife({
    stale: 3600,      // 1h — serve stale while revalidating
    revalidate: 7200, // 2h — background revalidation interval
    expire: 86400,    // 1d — hard expiration
  })
  return fetch('/api/data')
}

Built-in profile shortcuts: 'use cache' alone → 5m stale / 15m revalidate. 'use cache: remote' → platform KV. 'use cache: private' → allows runtime APIs (compliance escape hatch).

Cache Invalidation

import { cacheTag } from 'next/cache'

async function getProduct(id: string) {
  'use cache'
  cacheTag('products', `product-${id}`)
  return db.products.findUnique({ where: { id } })
}

updateTag() — immediate, same-request invalidation:

'use server'
import { updateTag } from 'next/cache'

export async function updateProduct(id: string, data: FormData) {
  await db.products.update({ where: { id }, data })
  updateTag(`product-${id}`)  // caller sees fresh data
}

revalidateTag() — background stale-while-revalidate:

'use server'
import { revalidateTag } from 'next/cache'

export async function createPost(data: FormData) {
  await db.posts.create({ data })
  revalidateTag('posts')  // next request sees fresh data
}

Cache Key Generation (Automatic)

Keys derived from: build ID + function location hash + serializable arguments + closure variables. No manual keyParts like unstable_cache.

async function Component({ userId }: { userId: string }) {
  const getData = async (filter: string) => {
    'use cache'
    // cache key = userId (closure) + filter (argument)
    return fetch(`/api/users/${userId}?filter=${filter}`)
  }
  return getData('active')
}

What Cannot Live Inside `'use cache

Full SKILL.md on GitHub

Install nextjs-static-shells in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

Bundled files

agents/openai.yamlassets/small-logo.svg

FAQ

What does the nextjs-static-shells skill do?

Static-first Next.js 16 architecture patterns: cached shells with dynamic slots, provider islands, 'use cache' boundaries, and link preloading strategy. Use when building or refactoring Next.js routes to maximize static rendering, implementing 'use cache' with dynamic personalization, splitting entry vs static renderers, scoping client providers, or tuning prefetch behavior. Triggers on 'static shell', 'use cache pattern', 'dynamic slots', 'provider island', 'prefetch strategy', 'static first', 'cache boundary', 'route goes dynamic unexpectedly', or any Next.js architecture work involving mixed static/dynamic rendering.

How do I install the nextjs-static-shells skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the nextjs-static-shells skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare nextjs-static-shells with