Skip to content

feat: Next.js Pages Router support#393

Open
andreas-karlsson wants to merge 3 commits intomainfrom
pages-router-support
Open

feat: Next.js Pages Router support#393
andreas-karlsson wants to merge 3 commits intomainfrom
pages-router-support

Conversation

@andreas-karlsson
Copy link
Copy Markdown
Contributor

Summary

Adds three subexports under ./pages-router/* for the Next.js Pages Router, parallel to the existing react-server/react-client pair for App Router:

  • pages-router/serverwithConfidence(config, gssp?) HOC that resolves the flag bundle in getServerSideProps (no exposure) and merges it into pageProps. Plus a low-level resolveConfidence helper.
  • pages-router/client<ConfidencePagesProvider> for _app.tsx. The existing useFlag / useFlagDetails from react-client work unchanged.
  • pages-router/apiapplyHandler({ providerName? }?) factory for the /api/confidence/apply POST route the client uses to log exposure.

The resolve token is sealed with AES-256-GCM (key from CONFIDENCE_TOKEN_KEY env var) before reaching the client, since Pages Router has no encrypted-closure equivalent to App Router server actions. The apply route opens it server-side.

README-REACT.md gets a new "Next.js Pages Router" section. The App Router quick-start was also moved to instrumentation.ts since that's router-agnostic and avoids the build-time side-effect issue with top-level-await setup files.

Test plan

  • yarn typecheck clean
  • yarn test — 7 token tests + 6 apply-handler tests pass
  • yarn build emits dist/pages-router/{server,client,api}.{js,d.ts}
  • Existing react-server / react-client builds unchanged
  • Verified end-to-end against a Pages Router demo app (server-side resolve → client hook reads → apply route fires exposure)

🤖 Generated with Claude Code

Comment thread openfeature-provider/js/src/pages-router/server.ts Outdated
Comment thread openfeature-provider/js/src/pages-router/server.ts
Comment thread openfeature-provider/js/src/pages-router/constants.ts Outdated
Comment thread openfeature-provider/js/src/pages-router/client.tsx Outdated
Comment thread openfeature-provider/js/src/pages-router/api.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants