streaming-cache
Skill4 starsChanged 4 months agoMITView on GitHub
Load when designing data architecture or rendering strategy for a Next.js 16 app. This skill teaches how to architect with caching and streaming — the compositional patterns, not the API surface. For cache API reference (use cache, cacheLife, cacheTag): load next-cache-components (SK-030). For the full architecture overview: load web-l100 (SK-083) for Render Tiers and the streaming pipeline. Deep patterns: references/compositional-cache.md The key Next.js 16 insight: a cached component can accept children and other ReactNode props. The cached shell renders once,…
In this repository162 other files it gives its agents.
- agents/AGENTS.mdAGENTS.md
- skills/compound-engineering/AGENTS.mdAGENTS.md
- skills/trailofbits-security/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- examples/CLAUDE.mdCLAUDE.md
- skills/compound-engineering/CLAUDE.mdCLAUDE.md
- skills/trailofbits-security/CLAUDE.mdCLAUDE.md
- app-store-reviewSkill
- advanced-javascriptSkill
- ai-native-uiSkill
- anime-jsSkill
- app-l100Skill
- barba-jsSkill
- brand-guidelinesSkill
- cinematic-web-engineSkill
- codebase-knowledge-graphSkill
- crossplatform-monorepoSkill
- css-first-uiSkill
- design-auditSkill
- design-critiqueSkill
- dev-cycleSkill
- device-hardware-bridgeSkill
- discovery-docSkill
- docxSkill
- edge-intelligenceSkill
- graph-aware-reviewSkill
- linkedin-posterSkill
- local-first-architectureSkill
- modern-build-pipelineSkill
- motion-nativeSkill
- nano-bananaSkill
- playwrightSkill
- pptxSkill
- project-initSkill
- remotionSkill
- sensory-nativeSkill
- spline-3dSkill
- tanstack-ecosystemSkill
- design-taste-frontendSkill
- tauri-desktopSkill
- threejsSkill
- transition-nativeSkill
- ui-design-stackSkill
- visual-nativeSkill
- web-l100Skill
- web-platform-apisSkill
- xlsxSkill
- better-authSkill
- claude-real-videoSkill
- clone-websiteSkill
- css-keyframe-animationsSkill
- design-checkSkill
- design-dnaSkill
- design-polishSkill
- drizzle-neonSkill
- fastlaneSkill
- angular-architectSkill
- api-designerSkill
- architecture-designerSkill
- atlassian-mcpSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 144
When user navigates to Settings, the component is already rendered — instant transition.
- Distinctive: line 241
When cache boundaries are nested, the most conservative (shortest) lifetime wins:
- Distinctive: line 285
Rule: Never nest a short-lived cache inside a long-lived cache.
- Distinctive: line 295
If user interacts with a not-yet-hydrated component, React prioritizes hydrating that component
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!--
id: SK-085
name: streaming-cache
description: Streaming & Cache Architecture — Next.js 16 compositional cache slots, React 19.2 Activity + ViewTransition, streaming SSR, cache lifetime bubbling, selective hydration. Load for data architecture and rendering strategy.
keywords: streaming, cache, ppr, activity, view-transition, cache-slots, compositional, selective-hydration, suspense, cache-lifetime, use-cache-remote, react-19
version: 1.0.0
-->Streaming & Cache Architecture
When to Use This Skill
Load when designing data architecture or rendering strategy for a Next.js 16 app. This skill teaches how to architect with caching and streaming — the compositional patterns, not the API surface.
For cache API reference (use cache, cacheLife, cacheTag): load next-cache-components (SK-030).
For the full architecture overview: load web-l100 (SK-083) for Render Tiers and the streaming pipeline.
Compositional Cache Slots
Deep patterns: references/compositional-cache.md
The key Next.js 16 insight: a cached component can accept children and other ReactNode props. The cached shell renders once, but dynamic children stream independently.
// Cached layout shell — renders once, CDN-cached
async function DashboardShell({ children }: { children: React.ReactNode }) {
'use cache'
cacheLife('days')
const nav = await db.navigation.findMany();
return (
<div className="dashboard">
<Sidebar items={nav} />
<main>{children}</main> {/* Dynamic children stream through the cached shell */}
</div>
);
}
// Page composes cached shell with dynamic content
export default function DashboardPage() {
return (
<DashboardShell>
{/* T1: Cached stats */}
<StatsPanel />
{/* T2: Dynamic user content — streams independently */}
<Suspense fallback={<ActivitySkeleton />}>
<UserActivity />
</Suspense>
</DashboardShell>
);
}The shell cache is not polluted by dynamic children — each Suspense boundary resolves independently.
Pattern: Shared Layout, Per-User Content
async function ProductPage({ id }: { id: string }) {
return (
<CachedProductLayout id={id}>
{/* User-specific: cannot be cached globally */}
<Suspense fallback={<PriceSkeleton />}>
<PersonalizedPrice productId={id} />
</Suspense>
<Suspense fallback={<ReviewsSkeleton />}>
<UserReviews productId={id} />
</Suspense>
</CachedProductLayout>
);
}
async function CachedProductLayout({ id, children }: { id: string; children: React.ReactNode }) {
'use cache'
cacheLife('hours')
cacheTag(`product-${id}`)
const product = await db.products.findUnique({ where: { id } });
return (
<article>
<h1>{product.name}</h1>
<ProductImages images={product.images} />
<p>{product.description}</p>
{children}
</article>
);
}use cache: remote
For serverless deployments where in-memory cache doesn't persist across invocations:
async function getPopularProducts() {
'use cache: remote' // Uses platform cache (Redis, KV, Vercel Data Cache)
cacheLife('hours')
cacheTag('popular-products')
return db.products.findMany({
orderBy: { sales: 'desc' },
take: 20,
});
}When to use:
use cache(default) — single-server or persistent process (good for dev, Node.js long-running)use cache: remote— serverless, edge, multi-region (Vercel, Cloudflare, AWS Lambda)use cache: private— per-user cache, allows cookies/headers access
React <Activity>
Deep patterns: references/activity-component.md
<Activity> keeps component trees in memory without rendering them to the DOM. React 19.2+.
Pre-render Anticipated Routes
import { Activity } from 'react';
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
return (
<>
{children}
{/* Pre-render settings page in background */}
<Activity mode="hidden">
<SettingsPage />
</Activity>
</>
);
}When user navigates to Settings, the component is already rendered — instant transition.
Keep Tabs Alive
function TabPanel({ tabs, activeTab }: { tabs: Tab[]; activeTab: string }) {
return (
<div>
{tabs.map(tab => (
<Activity key={tab.id} mode={tab.id === activeTab ? 'visible' : 'hidden'}>
<TabContent tab={tab} />
</Activity>
))}
</div>
);
}Switching tabs is instant — state, scroll position, and input values are preserved. No unmount/remount cycle.
Background Data Prefetch
<Activity mode="hidden">
{/* This Suspense boundary fetches data in the background */}
<Suspense fallback={null}>
<ExpensiveDataComponent />
</Suspense>
</Activity>Data fetches at lower priority, doesn't block visible content.
React <ViewTransition>
Deep patterns: references/view-transition-component.md
First-class React component for View Transitions. React 19.2+, Next.js 16+.
import { ViewTransition } from 'react';
function ProductCard({ product }: { product: Product }) {
return (
<ViewTransition name={`product-${product.id}`}>
<Link href={`/products/${product.id}`}>
<img src={product.image} alt={product.name} />
<h3>{product.name}</h3>
</Link>
</ViewTransition>
);
}
// On the detail page, same ViewTransition name = shared element transition
function ProductDetail({ product }: { product: Product }) {
return (
<ViewTransition name={`product-${product.id}`}>
<img src={product.image} alt={product.name} className="hero-image" />
</ViewTransition>
);
}Enable in Next.js 16
// next.config.ts
const nextConfig: NextConfig = {
viewTransition: true,
};Next.js auto-triggers view transitions on route changes.
CSS Customization
::view-transition-old(*) {
animation-duration: 200ms;
}
::view-transition-new(*) {
animation-duration: 300ms;
}
/* Specific named transition */
::view-transition-group(product-hero) {
animation-duration: 400ms;
animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}Cache Lifetime Bubbling
When cache boundaries are nested, the most conservative (shortest) lifetime wins:
async function PageLayout() {
'use cache'
cacheLife('days') // Layout wants to cache for days
return (
<div>
<Header />
<StockTicker /> {/* But this caches for seconds */}
<Footer />
</div>
);
}
async function StockTicker() {
'use cache'
cacheLife('seconds') // This pulls the outer cache down to seconds
const prices = await fetchStockPrices();
return <div>{/* ... */}</div>;
}The fix: Move volatile components to Suspense boundaries instead of nesting caches:
async function PageLayout() {
'use cache'
cacheLife('days') // Layout stays cached for days
return (
<div>
<Header />
<Suspense fallback={<TickerSkeleton />}>
<StockTicker /> {/* Dynamic — doesn't affect layout cache */}
</Suspense>
<Footer />
</div>
);
}Rule: Never nest a short-lived cache inside a long-lived cache. Use Suspense to isolate volatile data.
Selective Hydration
React 19 streams HTML and hydrates <Suspense> boundaries independently:
- Static shell arrives instantly (PPR)
- Each Suspense boundary hydrates when its data arrives
- If user interacts with a not-yet-hydrated component, React prioritizes hydrating that component
- Hidden
<Activity>components hydrate at lowest priority
Architecture Implication
Wrap each independent data source in its own Suspense boundary:
export default function Dashboard() {
return (
<>
<StaticHeader /> {/* T0 — no Suspense needed */}
<Suspense fallback={<StatsSkeleton />}>
<Stats /> {/* T1 or T2 — independent data source */}
</Suspense>
<Suspense fallback={<ChartSkeleton />}>
<Charts /> {/* T2 — different data, different timing */}
</Suspense>
<Suspense fallback={<FeedSkeleton />}>
<ActivityFeed /> {/* T2 — slowest data, streams last */}
</Suspense>
</>
);
}Each section appears as soon as its data is ready. The user sees a progressively complete page, not a loading spinner.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

