implement-ssr-prefetch-and-query-client-boundaries

Prefetch and hydrate server-side query data in Next.js SSR.

2|Updated Dec 2, 2024
One-click install
npx skills add https://github.com/TechsioCZ/new-engine --skill implement-ssr-prefetch-and-query-client-boundaries
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: implement-ssr-prefetch-and-query-client-boundaries
Source: https://github.com/TechsioCZ/new-engine/tree/main/libs/storefront-data/skills/implement-ssr-prefetch-and-query-client-boundaries
Command: npx skills add https://github.com/TechsioCZ/new-engine --skill implement-ssr-prefetch-and-query-client-boundaries

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The skill enables reliable SSR data handling in Next.js apps, providing a way to prefetch and share query data between server and client using a request-scoped server query client.

Core Features & Use Cases

  • SSR prefetching: fetch data on the server with a server query client and hydrate it on the client to avoid hydration issues.
  • Boundary ownership: establish request-scoped ownership over the query client to prevent cross-request contamination.
  • Compatibility with storefront-data: works with getServerQueryClient, HydrationBoundary, dehydrate, and preset query options like getListQueryOptions/getDetailQueryOptions.
  • Use Case: in a Next.js app with server components, prefetch a product list and hydrate it for client components.

Quick Start

Install and configure the storefront-data library in your Next.js app, then use the server query client to prefetch data and hydrate the cache on the client.

Frequently Asked Questions about implement-ssr-prefetch-and-query-client-boundaries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prefetch server-side query data for Next.js server components?

Prefetch server-side query data in Next.js by using a server query client to fetch data on the server, then dehydrate and pass it through a HydrationBoundary to client components. This shares fetched data safely between server and client.

Why does my Next.js app have hydration issues with server component data?

Hydration issues occur when server and client query data do not match. Establishing request-scoped query client ownership and using HydrationBoundary prevents cross-request contamination and ensures the client cache matches the server-rendered output.

How do I prevent cross-request query client contamination in Next.js SSR?

Prevent cross-request contamination in Next.js SSR by using a request-scoped server query client. This isolates query cache ownership per request, ensuring data from one request does not leak into another during server-side rendering.

Can I use getServerQueryClient and dehydrate with storefront-data in Next.js?

Yes, storefront-data works with getServerQueryClient and dehydrate in Next.js. You coordinate these with preset query options like getListQueryOptions or getDetailQueryOptions to prefetch and bind data for hydration.

What is the best way to hydrate a prefetched product list for client components in Next.js?

The best way to hydrate a prefetched product list is to fetch it using a server query client, dehydrate the cache, and wrap your client components in a HydrationBoundary to pass the server state down without refetching.