Interactive demo project showing how to use @basestack/flags-react in a Next.js App Router app with OpenNext deployment to Cloudflare Workers.
- Server-side flag preloading with
fetchFlagsin the root layout. - Client-side flag consumption with
useFlag. - Feature preview modal (
openPreviewModal) and feedback modal (openFeedbackModal). - Runtime checks through:
- a Server Action (
runHeaderPolicyAction) - a Route Handler (
/api/route-handler-demo)
- a Server Action (
- Cloudflare-ready build, preview, upload, and deploy scripts via OpenNext.
- Next.js 16 (App Router)
- React 19
- Tailwind CSS 4
@basestack/flags-react- OpenNext Cloudflare (
@opennextjs/cloudflare) - Vitest + Testing Library
- Biome (lint/format)
- Node.js
>= 20 - Bun (the repo uses
bun.lockandpackageManager: bun@1.3.12) - A Basestack project/environment with valid API credentials
- Cloudflare account + Wrangler auth for preview/deploy workflows
Create a local env file (for example .env.local) with:
NEXT_PUBLIC_BASE_URL=""
NEXT_PUBLIC_PROJECT_KEY=""
NEXT_PUBLIC_ENVIRONMENT_KEY=""These are required by src/libs/feature-flags/config.ts.
bun installbun run devApp runs at http://localhost:3000.
stats_grid- controls the stats cards section.initiative_overview- controls expanded initiative list and feedback action.preview_notes- controls the preview notes panel.header- used by the server action policy check.
- Server Action:
src/app/actions/runtime-demo-actions.ts - Route Handler:
GET /api/route-handler-demo
The route returns current flag status and metadata for stats_grid.
bun run dev- start local Next.js dev serverbun run build- Next.js production buildbun run start- serve production build locallybun run test- run Vitest with coveragebun run test:watch- run Vitest in watch modebun run lint- Biome lintbun run lint:fix- Biome lint with fixesbun run format- Biome formatbun run check- Biome check with writesbun run cf-typegen- regeneratecloudflare-env.d.tsbun run preview- OpenNext Cloudflare local previewbun run upload- OpenNext Cloudflare uploadbun run deploy- OpenNext Cloudflare deploy
Preview the Worker runtime locally:
bun run previewDeploy to Cloudflare:
bun run deployThe worker configuration is in wrangler.jsonc and OpenNext config is in open-next.config.ts.
Run the full test suite:
bun run testComponent and runtime behavior are covered in:
src/components/home/__tests__src/app/actions/__tests__src/app/api/route-handler-demo/__tests__