ce-nextjs-patterns

Automate Next.js server components, actions, and token management for Commerce Engine storefronts.

Updated Feb 12, 2026
One-click install
npx skills add https://github.com/commercengine/skills --skill ce-nextjs-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ce-nextjs-patterns
Source: https://github.com/commercengine/skills/tree/main/skills/nextjs-patterns
Command: npx skills add https://github.com/commercengine/skills --skill ce-nextjs-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Provides a cohesive set of Next.js integration patterns for Commerce Engine to streamline SSR, Server Actions, SSG/ISR, and secure token management in storefronts.

Core Features & Use Cases

  • Server Components & Cookies: context-aware storefront usage with cookies() on the server for authenticated data.
  • Server Actions for Mutations: place auth and cart mutations in Server Actions to safely write cookies and update state.
  • SSG/ISR Patterns: build-time data fetching and token caching to speed up static pages.
  • Root Layout Initialization: use storefront({ isRootLayout: true }) in the root layout to bootstrap anonymous sessions and maintain continuity.
  • Client-Server Token Sync: tokens read from browser cookies and refreshed automatically across contexts.

Quick Start

Create a Next.js app, install the Commerce Engine storefront SDK, and apply the provided patterns in your root layout and pages.

Frequently Asked Questions about ce-nextjs-patterns

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

FAQPage Schema
How do I manage authentication tokens in Next.js server components?

Authentication tokens in Next.js server components are managed using cookies-based storage, allowing context-aware storefront usage on the server for authenticated data retrieval and automatic client-server token synchronization.

How do I bootstrap anonymous sessions in a Next.js root layout?

Bootstrap anonymous sessions in a Next.js root layout by initializing the storefront context with the isRootLayout flag set to true, ensuring session continuity and automatic token refresh across server and client components.

Can I use Server Actions for cart mutations in a Next.js storefront?

Yes, Server Actions handle cart and authentication mutations in a Next.js storefront by safely writing cookies and updating state on the server without exposing sensitive token management logic to the client.

What's the best way to cache tokens for SSG and ISR pages in Next.js?

Cache tokens for SSG and ISR pages in Next.js by applying build-time data fetching patterns with token caching, which speeds up static page generation while maintaining secure storefront context adaptation.

Does this Commerce Engine integration support both SSR and SSG patterns?

Yes, the Commerce Engine integration supports both SSR and SSG patterns, providing cohesive data fetching mechanisms that adapt the storefront context across server components, static generation, and incremental static regeneration.

Why do I need the isRootLayout flag for storefront initialization?

The isRootLayout flag is required for storefront initialization to properly bootstrap anonymous sessions and maintain token continuity across server-side rendering, client components, and server actions in your Next.js application.