ferroxlabs/wayland/nextjs-data-patterns

Claude Code and agent skill by ferroxlabs/wayland

Trust tier 1
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Guides expert-level next.js data patterns implementation: typescript and frameworks decision frameworks, production-ready patterns, and concrete templates for nextjs data patterns workflows. Use when the user asks about next.js data patterns, nextjs data patterns configuration, or typescript best practices for next.js projects. Do NOT use when the user needs a different web development capability -- check sibling skills in the web development subcategory.

Install

npx vskill@latest install ferroxlabs/wayland/nextjs-data-patterns

SKILL.md

The same SKILL.md was published earlier as ferroxlabs/wayland/nextjs-data-patterns.

Next.js Data Patterns

When to Use

Use this skill when:

  • The user asks how to fetch data in a Next.js App Router project and needs to choose between Server Components, Route Handlers, or client-side fetching
  • The user is deciding between generateStaticParams, Incremental Static Regeneration (ISR), or fully dynamic rendering for a specific route
  • The user needs to implement caching strategies with fetch cache options, unstable_cache, or React cache deduplication in Next.js 13+
  • The user wants to integrate a database (PostgreSQL, MongoDB, Prisma, Drizzle) directly in Server Components and needs patterns for connection pooling, query structuring, and error handling
  • The user is building a data-heavy feature -- search, dashboards, paginated lists, real-time feeds -- and needs the correct rendering and fetching architecture for performance
  • The user asks about Server Actions, form mutations, and optimistic UI patterns in the App Router
  • The user needs to handle authenticated data fetching, per-user caching, and session-aware queries in Next.js
  • The user is migrating a Pages Router (getServerSideProps, getStaticProps) application to the App Router and needs equivalent patterns

Do NOT use this skill when:

  • The user is asking about general React state management (Zustand, Jotai, Redux) with no Next.js-specific data fetching question -- use a React state management skill
  • The user needs CSS, layout, or UI component advice in Next.js -- use a Next.js UI/styling skill
  • The user is building a pure API backend with no rendering layer -- use a Node.js/Express API skill
  • The user is asking about deployment, CI/CD, or infrastructure for Next.js -- use a deployment skill
  • The user is working in the Pages Router exclusively with no intent to migrate -- patterns differ significantly and this skill targets the App Router model primarily
  • The user is asking about Next.js authentication flows beyond data fetching concerns -- use an auth skill
  • The user needs real-time WebSocket or Server-Sent Events architecture -- use a real-time communication skill

Process

1. Identify the Rendering Context and Freshness Requirements

Before selecting any data pattern, establish the rendering model for the route:

  • Determine staleness tolerance: Data that changes once per day (blog posts, product catalogs) can tolerate ISR with revalidate: 3600. Data that changes per-request (cart contents, user dashboards) must be fully dynamic. Data that never changes (documentation, policy pages) should be statically generated.
  • Map routes to rendering strategies: Static (force-static) → ISR with revalidation interval → Dynamic (force-dynamic) with per-request fetching. Choose the least dynamic option that satisfies freshness requirements.
  • Identify authentication requirements: Authenticated routes must always be dynamic or use per-user cache keys. Never cache authenticated responses without user-scoping -- this causes data leakage across users.
  • Check for streaming requirements: If the route has a slow data dependency (external API, complex DB query), plan to use Suspense boundaries to stream fast content immediately and defer slow content.
  • Classify data by source: First-party database (use Server Component direct query), third-party REST API (use fetch with cache control), third-party SDK without fetch (use unstable_cache wrapper), client-only data (browser APIs, user interactions -- use client components with SWR or TanStack Query).
2. Choose the Data Fetching Layer

Select the correct layer based on context classification from Step 1:

  • Server Components + direct DB queries: Use this for the majority of data needs in App Router. Import your Prisma client or Drizzle db instance directly. There is no API round-trip overhead. Example: const posts = await db.post.findMany({ where: { published: true } }) inside an async Server Component.
  • Route Handlers (`app/api/route.ts`): Use exclusively when you need an actual HTTP endpoint -- consumed by third-party webhooks, mobile clients, or client-side fetch calls from Client Components. Do not call your own Route Handlers from Server Components; that is a wasted HTTP round-trip.
  • Server Actions (`'use server'`): Use for mutations -- form submissions, creating records, deleting items. Server Actions can be called from both Client Components and Server Components. They run on the server, eliminating the need for dedicated mutation Route Handlers for most use cases.
  • Client-side fetching with TanStack Query or SWR: Use when data must update after initial render without a full page reload -- live search results, polling dashboards, user-triggered data loads. Always pair with a Route Handler that returns JSON.
  • React `cache()` for deduplication: Wrap expensive DB queries with cache() from React when the same query might be called in multiple Server Components within one render tree. The result is memoized for the duration of that request.
3. Design the Cache Strategy

Cache decisions determine performance and cost. Apply these rules precisely:

  • `fetch` with Next.js cache options: fetch(url, { cache: 'force-cache' }) caches indefinitely (static). fetch(url, { next: { revalidate: 60 } }) caches for 60 seconds (ISR). fetch(url, { cache: 'no-store' }) opts out of caching entirely (dynamic). Default behavior in App Router is force-cache for GET requests.
  • `unstable_cache` for non-fetch data sources: Wrap any async function that fetches from a database or SDK that does not use the native fetch API. Provide explicit cache keys and revalidation: unstable_cache(async () => db.query(...), ['cache-key'], { revalidate: 300, tags: ['posts'] }).
  • On-demand revalidation with cache tags: Tag fetches with { next: { tags: ['product-123'] } }. Call revalidateTag('product-123') from a Server Action or Route Handler when the underlying data changes. This is the correct pattern for CMS-backed sites and e-commerce product pages.
  • Per-user cache isolation: Always include the user ID or session token as part of the cache key when caching user-specific data. Never use a shared cache key for personalized content.
  • Cache busting with `revalidatePath`: Call revalidatePath('/dashboard') after mutations to purge the route-level cache. Use this after Server Actions that modify data displayed on specific routes.
4. Structure Server Component Data Fetching

Apply these patterns for clean, maintainable Server Component data code:

  • Colocate queries with the component that renders the data. A <ProductCard> Server Component should fetch its own product data rather than receiving it drilled from a parent. This makes components independently cacheable and easier to reason about.
  • Parallelize independent queries with `Promise.all`. When a page component needs user data AND product data AND analytics data, fetch them in parallel: const [user, products, analytics] = await Promise.all([getUser(), getProducts(), getAnalytics()]). Never await sequentially unless one query depends on another's result.
  • Use `Suspense` for sequential dependencies. When query B depends on query A's result, place query B in a child component wrapped in <Suspense fallback={<Skeleton />}>. The parent resolves A, passes the result as a prop, and the child streams in when B resolves.
  • Separate data access into a dedicated layer. Create a lib/data/ or lib/queries/ directory. Export typed async functions like getProductById(id: string): Promise<Product | null>. Server Components import from this layer, never constructing raw queries inline.
  • Type all data access functions with TypeScript. Define Zod schemas for external API responses. Define TypeScript types (or use Prisma-generated types) for database results. Validate external data at the boundary -- never trust raw API responses.
5. Implement Server Actions for Mutations

Structure Server Actions for reliability and correctness:

  • Always mark the file or function with `'use server'`. Place shared actions in app/actions/ or lib/actions/. Mark the entire file 'use server' at the top rather than individual functions when the file contains only server-side code.
  • Validate all input with Zod before touching the database. Never trust form data. Parse with a Zod schema first: const parsed = ProductSchema.safeParse(formData). Return early with an error object if validation fails.
  • Return typed result objects, not thrown errors. Return { success: true, data: product } or { success: false, error: 'Validation failed', fieldErrors: parsed.error.flatten() }. This allows Client Components to handle errors without try/catch.
  • Call `revalidatePath` or `revalidateTag` after successful mutations. Revalidation ensures the UI reflects the new state without a manual refresh.
  • Use `redirect()` from `next/navigation` inside Server Actions to navigate after successful form submission -- for example, after creating a new product, redirect to /products/${newProduct.id}.
  • Handle optimistic updates on the Client Component side using useOptimistic. The Server Action handles the real mutation; useOptimistic provides immediate UI feedback before the action resolves.
6. Handle Error States and Loading UI

Production data patterns require explicit error and loading handling:

  • Use `error.tsx` boundary files for route-level error handling. Place an error.tsx in each route segment that needs isolated error recovery. The error.tsx component receives error and reset props -- always expose the reset function to allow retry.
  • Use `loading.tsx` files for route-level suspense fallbacks. loading.tsx automatically wraps the page in a <Suspense> boundary. Use skeleton components, not spinners, for better perceived performance.
  • Distinguish between not-found and error states. Call notFound() from next/navigation when a resource does not exist (404). Let real errors bubble to error.tsx. Never return null for missing data without signaling 404.
  • Wrap third-party API calls in try/catch within data access functions. Log errors server-side and return a typed error result rather than propagating the raw exception to the component.
  • Set timeouts on external fetches. Use AbortController with a timeout to prevent slow external APIs from hanging the entire render: const controller = new AbortController(); setTimeout(() => controller.abort(), 5000); fetch(url, { signal: controller.signal }).
7. Optimize for Performance and Bundle Size

Apply these techniques to keep data patterns fast at scale:

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
608
Repository forks
113
7-day trend score
37

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/ferroxlabs/wayland/nextjs-data-patterns/badge)](https://verified-skill.com/skills/ferroxlabs/wayland/nextjs-data-patterns)

Something wrong with this skill or its page? Tell us.