with one click
feature-flags
Implement feature flags for gradual rollouts and A/B testing.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Implement feature flags for gradual rollouts and A/B testing.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Migrate from Next.js 15 to Next.js 16 and handle breaking changes
Configure Content Security Policy and security headers for the portfolio
Deploy Next.js to Cloudflare Workers using OpenNext adapter
Manage the canary token honeypot system for detecting security scanning
Write, debug, and optimize GROQ queries for Sanity CMS in this portfolio
Advanced TypeScript patterns and type safety as used in this portfolio
| name | feature-flags |
| description | Implement feature flags for gradual rollouts and A/B testing. |
Implement feature flags for controlled feature rollouts, A/B testing, and environment-based configuration.
// lib/features.ts
export const FEATURE_FLAGS = {
NEW_DASHBOARD: {
enabled: true,
percentage: 50, // 50% of users
allowedUsers: ['admin@example.com'],
},
BETA_FEATURES: {
enabled: process.env.NODE_ENV === 'development',
percentage: 100,
},
} as const;
export function isFeatureEnabled(
flag: keyof typeof FEATURE_FLAGS,
userId?: string
): boolean {
const config = FEATURE_FLAGS[flag];
if (!config.enabled) return false;
if (config.allowedUsers?.includes(userId || '')) return true;
if (config.percentage === 100) return true;
// Deterministic percentage based on userId
if (userId) {
const hash = hashString(userId);
return (hash % 100) < config.percentage;
}
return false;
}
// components/FeatureGate.tsx
interface FeatureGateProps {
feature: keyof typeof FEATURE_FLAGS;
children: React.ReactNode;
fallback?: React.ReactNode;
}
export function FeatureGate({ feature, children, fallback }: FeatureGateProps) {
const enabled = isFeatureEnabled(feature);
if (!enabled && fallback) {
return <>{fallback}</>;
}
return enabled ? <>{children}</> : null;
}
// Usage
<FeatureGate feature="NEW_DASHBOARD" fallback={<OldDashboard />}>
<NewDashboard />
</FeatureGate>