feat(js): Next.js Pages Router support#393
Merged
Merged
Conversation
nicklasl
reviewed
May 5, 2026
nicklasl
reviewed
May 5, 2026
nicklasl
reviewed
May 5, 2026
nicklasl
approved these changes
May 5, 2026
Member
nicklasl
left a comment
There was a problem hiding this comment.
Jedi Council ignites green saber 🟢
LGTM — both blocking concerns addressed (errorCode gate in applyHandler + dev-warn on apply failures), and the withConfidence(gssp, opts?) refactor is genuinely nicer than what I first reviewed. Approving.
One follow-up — the Build & Test failure is the bundle-split sentinel in Dockerfile:340. It uses find ... ! -name <basename>, which matches basename only, so:
dist/pages-router/server.jsanddist/pages-router/client.jsslip through by sheer naming coincidence (the existing! -name 'server.js' ! -name 'client.js'entries match them too)dist/pages-router/api.jshas noapi.jstwin elsewhere → caught as "unexpected"
Quick fix is to add ! -name 'api.js', but that just papers over the lie. Suggest switching to ! -path so the allowlist is explicit and the check actually tells the truth:
RUN set -e; \
echo "Verifying no bundle splitting in JS artifacts..."; \
UNEXPECTED_FILES=$(find dist -name '*.js' \
! -path 'dist/index.node.js' \
! -path 'dist/index.inlined.js' \
! -path 'dist/index.fetch.js' \
! -path 'dist/server.js' \
! -path 'dist/client.js' \
! -path 'dist/pages-router/server.js' \
! -path 'dist/pages-router/client.js' \
! -path 'dist/pages-router/api.js' | head -10); \
if [ -n "\$UNEXPECTED_FILES" ]; then \
echo ""; \
echo "❌ ERROR: Bundle splitting detected!"; \
echo ""; \
echo "Found unexpected JavaScript files in dist/:"; \
echo "\$UNEXPECTED_FILES"; \
echo ""; \
echo "Only expected entry point files should be present."; \
echo "Check tsdown.config.ts configuration to prevent code splitting."; \
echo ""; \
exit 1; \
fi; \
echo "✅ No bundle splitting detected - only expected files present"Catches actual chunk-splits (which the check was meant to find) instead of relying on basename collisions to hide them. 🛠️
nicklasl
approved these changes
May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds three subexports under
./pages-router/*for the Next.js Pages Router, parallel to the existingreact-server/react-clientpair for App Router:pages-router/server—withConfidence(config, gssp?)HOC that resolves the flag bundle ingetServerSideProps(no exposure) and merges it intopageProps. Plus a low-levelresolveConfidencehelper.pages-router/client—<ConfidencePagesProvider>for_app.tsx. The existinguseFlag/useFlagDetailsfromreact-clientwork unchanged.pages-router/api—applyHandler({ providerName? }?)factory for the/api/confidence/applyPOST route the client uses to log exposure.The resolve token is sealed with AES-256-GCM (key from
CONFIDENCE_TOKEN_KEYenv 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.mdgets a new "Next.js Pages Router" section. The App Router quick-start was also moved toinstrumentation.tssince that's router-agnostic and avoids the build-time side-effect issue with top-level-await setup files.Test plan
yarn typecheckcleanyarn test— 7 token tests + 6 apply-handler tests passyarn buildemitsdist/pages-router/{server,client,api}.{js,d.ts}react-server/react-clientbuilds unchanged🤖 Generated with Claude Code