feature-flags-nextjs
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "feature-flags-nextjs" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-bc7dcb5f1c669c906cafe7b23e31aebd7642cff10310af88b72dcd963ea66982. Verify the upstream source and version against https://skills.sh/posthog/skills/feature-flags-nextjs before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skills.sh
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
PostHog feature flags integration for Next.js applications, for managing and controlling feature flags within a Next.js project.
Introduction source: third_party · posthog · 1.0.0 Reference
SkillPi interpretation
- Tasks
- PostHog feature flags for Next.js applications
- Testing
- Not tested
Browse files
Frontmatter
name: feature-flags-nextjs
description: PostHog feature flags for Next.js applications
metadata:
author: PostHog
version: 1.9.4PostHog feature flags for Next.js
This skill helps you add PostHog feature flags to Next.js applications.
Reference files
references/react.md- React feature flags installation - docsreferences/next-js.md- Next.js - docsreferences/adding-feature-flag-code.md- Adding feature flag code - docsreferences/best-practices.md- Feature flag best practices - docs
Consult the documentation for API details and framework-specific patterns.
Key principles
- Environment variables: Always use environment variables for PostHog keys. Never hardcode them.
- Minimal changes: Add feature flag code alongside existing logic. Don't replace or restructure existing code.
- Boolean flags first: Default to boolean flag checks unless the user specifically asks for multivariate flags.
- Server-side when possible: Prefer server-side flag evaluation to avoid UI flicker.
PostHog MCP tools
Check if a PostHog MCP server is connected. If available, look for tools related to feature flag management (creating, listing, updating, deleting flags). Use these tools to manage flags directly in PostHog rather than requiring the user to do it manually in the dashboard.
Framework guidelines
- For Next.js 15.3+, initialize PostHog in instrumentation-client.ts for the simplest setup
- The PostHog React hooks (useFeatureFlagEnabled, useFeatureFlagPayload) work WITHOUT PostHogProvider if posthog-js is already initialized (e.g., via instrumentation-client.ts)
- In client components, import and use hooks directly - the React context defaults to the posthog-js singleton
- Do NOT wrap components in PostHogProvider just for feature flags - it's unnecessary if posthog-js is initialized globally
- Server Components and Route Handlers cannot use React hooks - use posthog-node SDK instead
- Create a server-side PostHog client with posthog-node, call getAllFlags() or getFeatureFlag(), then await posthog.shutdown()
- Pass flag values from server to client components as props to avoid hydration mismatches
- For flags that affect initial render, evaluate server-side and pass as props to prevent UI flicker
- Client-side hooks may return undefined initially while flags load - handle this loading state
- For feature flags, use useFeatureFlagEnabled() or useFeatureFlagPayload() hooks - they handle loading states and external sync automatically
- Add analytics capture in event handlers where user actions occur, NOT in useEffect reacting to state changes
- Do NOT use useEffect for data transformation - calculate derived values during render instead
- Do NOT use useEffect to respond to user events - put that logic in the event handler itself
- Do NOT use useEffect to chain state updates - calculate all related updates together in the event handler
- Do NOT use useEffect to notify parent components - call the parent callback alongside setState in the event handler
- To reset component state when a prop changes, pass the prop as the component's key instead of using useEffect
- useEffect is ONLY for synchronizing with external systems (non-React widgets, browser APIs, network subscriptions)
Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 Next.js 集成 PostHog 功能标志的完整工程化方案
- 涵盖服务端/客户端差异化处理、环境变量管理等关键实践
Highlights
- 触发描述清晰明确,frontmatter 完整
Areas to improve
-
缺少 When to Use 和端到端示例章节 Reported severity: Minor
文档结构完整但缺少使用场景说明和完整示例
Recommendation: 补充 When to Use 章节和端到端集成示例
Highlights
- 关键原则和框架指南清晰,结构良好
Areas to improve
-
PostHog MCP 工具来源和参数说明不明确 Reported severity: Minor
提及工具检查但未提供具体调用方式和参数细节
Recommendation: 补充 PostHog MCP 工具的具体使用方法和参数说明
Highlights
- 包含环境变量管理、服务端优先等可靠性最佳实践
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.