feature-flags-nextjs

Manage and evaluate PostHog feature flags in Next.js apps.

58|5|Updated Jan 19, 2026
One-click install
npx skills add https://github.com/PostHog/skills --skill feature-flags-nextjs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: feature-flags-nextjs
Source: https://github.com/PostHog/skills/tree/main/skills/posthog/feature-flags/skills/nextjs
Command: npx skills add https://github.com/PostHog/skills --skill feature-flags-nextjs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Enable Next.js applications to reliably manage and evaluate PostHog feature flags across client and server environments.

Core Features & Use Cases

  • Server-side flag evaluation and bootstrapping for Next.js pages and app router.
  • Guidance for initializing PostHog in Next.js (instrumentation-client.ts/js) and preventing UI flicker through pre-render flag values.
  • Framework-specific guidance for Next.js 15.3+ server components using posthog-node and server-side flag propagation to the client.

Quick Start

Install PostHog, configure environment, and ensure flag evaluation happens before rendering to avoid flicker.

Frequently Asked Questions about feature-flags-nextjs

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

FAQPage Schema
How do I evaluate PostHog feature flags server-side in Next.js to prevent UI flicker?

Evaluate PostHog feature flags server-side in Next.js by fetching flag values before the initial render. This ensures pre-render flag values are applied, preventing UI flicker during client hydration.

Can I use PostHog feature flags with both the Next.js app router and pages router?

Yes, PostHog feature flags work with both the Next.js app router and pages router. The implementation covers client-side and server-side flag evaluation, bootstrapping, and server-to-client flag propagation for both routing methods.

How do I initialize PostHog in Next.js 15.3+ server components?

Initialize PostHog in Next.js 15.3+ by configuring the client in instrumentation-client.ts/js. Use posthog-node for server-side flag fetching in server components and propagate those flags to the client.

What is bootstrapping in the context of Next.js feature flags?

Bootstrapping feature flags in Next.js means passing server-fetched flag values directly to the client during initial render. This allows immediate flag evaluation before the client-side PostHog instance fully loads.

How do I propagate server-side feature flag values to the client in Next.js?

Propagate server-side feature flag values to the Next.js client by evaluating them on the server using posthog-node and passing the resulting flag state down. This ensures the client renders with the correct flags immediately.

Do I need posthog-node to fetch feature flags in Next.js server components?

Yes, use posthog-node to fetch feature flags in Next.js server components. It enables server-side flag evaluation, allowing you to pass pre-render flag values to the client and avoid UI flicker.