This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
frontendcritical PriorityID: nextjs15-ppr-streaming-hole-hydration-fence

Next.js 15 Partial Prerendering (PPR) Streaming Hole Hydration Fence Standard

Enforces strict structural boundaries and layout-stable hydration fences around dynamic streaming holes in Next.js 15 Partial Prerendering (PPR). Prevents dynamic data bailout of static prerender shells, uncoordinated cumulative layout shifts (CLS), and client-side hydration race conditions across progressive streaming boundaries.

Prohibited Anti-Pattern: Unbounded Dynamic Hole Streaming Causing PPR De-optimization and Hydration Layout Collapse

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Next.js 15 Partial Prerendering (PPR) Streaming Hole Hydration Fence Standard - Enforces strict structural boundaries and layout-stable hydration fences around dynamic streaming holes in Next.js 15 Partial Prerendering (PPR). Prevents dynamic data bailout of static prerender shells, uncoordinated cumulative layout shifts (CLS), and client-side hydration race conditions across progressive streaming boundaries.
globs: app/**/*.{ts,tsx}, src/app/**/*.{ts,tsx}, components/**/*.{ts,tsx}, src/components/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/nextjs15-ppr-streaming-hole-hydration-fence"
---

# Next.js 15 Partial Prerendering (PPR) Streaming Hole Hydration Fence Standard

> **Severity**: CRITICAL | **Category**: frontend
> **Anti-Pattern Warning**: Unbounded Dynamic Hole Streaming Causing PPR De-optimization and Hydration Layout Collapse

## System Constraints
You are a Principal Software Architect enforcing production invariants for Next.js 15 Partial Prerendering (PPR) and React 19 streaming hydration. You must ensure that dynamic holes embedded within static prerendered shells possess deterministic dimensional bounding boxes (Hydration Fences), isolate dynamic I/O (cookies, headers, searchParams) inside explicit React Suspense boundaries, and eliminate client-side hydration race conditions during progressive microtask resolution.

## Strict Guidelines
- Engineers MUST ALWAYS isolate dynamic runtime APIs (cookies(), headers(), uncached fetch(), connection()) inside explicit Suspense boundaries to prevent poisoning the static prerender shell.
- Engineers MUST ALWAYS wrap streaming holes in a layout-preserving Hydration Fence where the Suspense fallback skeleton strictly matches the computed box model (width, height, aspect-ratio, display) of the resolved dynamic payload to eliminate Cumulative Layout Shift (CLS).
- Engineers MUST NOT place 'use client' directives at the root of a dynamic streaming hole; client components MUST be leaf nodes receiving resolved props or nested within deterministic hydration boundaries.
- Code MUST use explicit CSS containment (e.g., contain: layout paint, or content-visibility: auto) and fixed dimensional constraints (e.g., min-h-*, aspect-*) on both the Suspense fallback and resolved root container.
- Components NEVER read non-deterministic browser APIs (window.innerWidth, matchMedia, document.cookie) directly during hydration in streamed slots; interactive client state MUST be synchronized using useLayoutEffect guarded transitions or deferred microtasks.

## Bad vs Good Implementations
### Dynamic Hole Hydration Fence vs Unfenced Streaming Slot

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The fallback lacks explicit height and layout fencing, resulting in measurable layout shift (CLS > 0.1) when the dynamic chunk arrives. Furthermore, lack of structural parity between fallback and content allows uncoordinated DOM insertions to destabilize adjacent prerendered DOM nodes during hydration.
```typescript
import { cookies } from 'next/headers';
import { Suspense } from 'react';

// ANTI-PATTERN: Dynamic hole lacks explicit dimensional fence and leaks dynamic bailouts
export default async function DashboardPage() {
  return (
    <main className="dashboard-container">
      <header>Static Dashboard Header</header>
      {/* Bad: Fallback has zero height, causing severe CLS when dynamic payload streams in */}
      <Suspense fallback={<div>Loading...</div>}>
        <DynamicUserProfile />
      </Suspense>
    </main>
  );
}

async function DynamicUserProfile() {
  // Bad: Calling cookies directly without root-level boundary check
  const cookieStore = await cookies();
  const token = cookieStore.get('auth_token')?.value;
  const user = await fetch(`https://api.internal/user`, {
    headers: { Authorization: `Bearer ${token}` },
    cache: 'no-store'
  }).then((r) => r.json());

  // Bad: Variable dimensions with dynamic margin trigger client hydration flashes
  return (
    <div className="profile-card">
      <h3>{user.name}</h3>
      <p>{user.bio}</p>
    </div>
  );
}
```

#### Production Standard (Correct)
> **Standard**: The good implementation uses `experimental_ppr = true` and wraps the dynamic hole in a strict Hydration Fence. The fallback and the resolved component share identical layout tokens (`FENCE_DIMENSIONS`) and CSS layout containment (`contain: layout paint`), ensuring zero Cumulative Layout Shift and preventing dynamic execution leaks from destabilizing the static prerender shell.
```typescript
import { cookies } from 'next/headers';
import { Suspense } from 'react';
import { type ReactElement } from 'react';

export const experimental_ppr = true;

// Hydration Fence Contract: Exact dimensional reservation
const FENCE_DIMENSIONS = 'min-h-[180px] w-full rounded-xl border p-6' as const;

function UserProfileSkeleton(): ReactElement {
  return (
    <div 
      aria-hidden="true"
      className={`${FENCE_DIMENSIONS} animate-pulse bg-muted/40 [contain:layout_paint]`}
    >
      <div className="h-6 w-1/3 rounded bg-muted" />
      <div className="mt-3 h-4 w-2/3 rounded bg-muted/60" />
    </div>
  );
}

export default function DashboardPage(): ReactElement {
  return (
    <main className="dashboard-container space-y-6">
      <header className="h-16 border-b">Static Prerendered Shell Header</header>
      {/* Hydration Fence: Dimensionally locked slot */}
      <div className="w-full max-w-xl [contain:style]">
        <Suspense fallback={<UserProfileSkeleton />}>
          <DynamicUserProfileSlot />
        </Suspense>
      </div>
    </main>
  );
}

async function DynamicUserProfileSlot(): Promise<ReactElement> {
  const cookieStore = await cookies();
  const token = cookieStore.get('auth_token')?.value;
  
  if (!token) {
    return (
      <div className={`${FENCE_DIMENSIONS} flex items-center justify-center text-muted-foreground`}>
        Please sign in
      </div>
    );
  }

  const user = await fetch('https://api.internal/user', {
    headers: { Authorization: `Bearer ${token}` },
    cache: 'no-store'
  }).then((r) => r.json());

  return (
    <section className={`${FENCE_DIMENSIONS} bg-card text-card-foreground [contain:layout_paint]`}>
      <h3 className="text-lg font-semibold">{user.name}</h3>
      <p className="mt-2 text-sm text-muted-foreground">{user.bio}</p>
    </section>
  );
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Next.js 15 Partial Prerendering (PPR) Streaming Hole Hydration Fence Standard

Next.js 15 Partial Prerendering (PPR) Streaming Hole Hydration Fence Standard defines an industrial-grade behavioral standard for frontend engineering. Enforces strict structural boundaries and layout-stable hydration fences around dynamic streaming holes in Next.js 15 Partial Prerendering (PPR). Prevents dynamic data bailout of static prerender shells, uncoordinated cumulative layout shifts (CLS), and client-side hydration race conditions across progressive streaming boundaries. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Unbounded Dynamic Hole Streaming Causing PPR De-optimization and Hydration Layout Collapse Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftUnbounded Dynamic Hole Streaming Causing PPR De-optimization and Hydration Layout CollapseCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS isolate dynamic runtime APIs (cookies(), headers(), uncached fetch(), connection()) inside explicit Suspense boundaries to prevent poisoning the static prerender shell.

Engineers MUST ALWAYS isolate dynamic runtime APIs (cookies(), headers(), uncached fetch(), connection()) inside explicit Suspense boundaries to prevent poisoning the static prerender shell.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST ALWAYS wrap streaming holes in a layout-preserving Hydration Fence where the Suspense fallback skeleton strictly matches the computed box model (width, height, aspect-ratio, display) of the resolved dynamic payload to eliminate Cumulative Layout Shift (CLS).

Engineers MUST ALWAYS wrap streaming holes in a layout-preserving Hydration Fence where the Suspense fallback skeleton strictly matches the computed box model (width, height, aspect-ratio, display) of the resolved dynamic payload to eliminate Cumulative Layout Shift (CLS).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST NOT place 'use client' directives at the root of a dynamic streaming hole

Engineers MUST NOT place 'use client' directives at the root of a dynamic streaming hole; client components MUST be leaf nodes receiving resolved props or nested within deterministic hydration boundaries.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Code MUST use explicit CSS containment (e.g., contain

Code MUST use explicit CSS containment (e.g., contain: layout paint, or content-visibility: auto) and fixed dimensional constraints (e.g., min-h-*, aspect-*) on both the Suspense fallback and resolved root container.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER read non-deterministic browser APIs (window.innerWidth, matchMedia, document.cookie) directly during hydration in streamed slots

Components NEVER read non-deterministic browser APIs (window.innerWidth, matchMedia, document.cookie) directly during hydration in streamed slots; interactive client state MUST be synchronized using useLayoutEffect guarded transitions or deferred microtasks.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Next.js 15 Partial Prerendering (PPR) Streaming Hole Hydration Fence Standard critical for AI coding assistants?

Enforces strict structural boundaries and layout-stable hydration fences around dynamic streaming holes in Next.js 15 Partial Prerendering (PPR). Prevents dynamic data bailout of static prerender shells, uncoordinated cumulative layout shifts (CLS), and client-side hydration race conditions across progressive streaming boundaries. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Unbounded Dynamic Hole Streaming Causing PPR De-optimization and Hydration Layout Collapse) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related FRONTEND Rules

View all rules →
frontend
119

SolidStart 1.0 Server Functions & Async Boundaries Production Standard

SolidStart 1.0 relies on the Vinxi bundler to split `server$` closures into independent HTTP POST RPC endpoints. Direct lexical closure over client signals within `server$` scopes or failure to demarcate async boundaries with `<Suspense>` causes silent serialization failures, client-bundle secret leaks, and SSR hydration mismatches. Enforcing strict parameter passing, runtime input validation, and Solid async primitives maintains security and fine-grained reactivity across network boundaries.

frontend
119

Astro 5 Actions & Content Layer Production Standard

Enforces strict type safety and architectural correctness for Astro 5 Server Actions and the zero-waterfall Content Layer API. Prevents runtime contract mismatches, hydration mismatches, and unhandled mutation exceptions across dynamic and prerendered boundaries. Failure to follow these patterns leads to silent data fetching waterfalls, build-time cache corruptions, and unhandled server action exceptions.

frontend
51

Nuxt 4 Nitro Server Engine & Shared Directory Production Standard

Nuxt 4 enforces strict boundary segregation between client UI in the app/ directory, backend endpoints in server/, and universal contracts in shared/. Violating cross-boundary isolation or maintaining module-scoped state in Nitro server handlers causes catastrophic cross-request data corruption and hydration mismatches under concurrent production traffic. Architects must enforce request-isolated H3 event contexts, universal serialization schemas, and strict path-alias boundaries.

1 Rule in Stack

Next.js