Skip to content

feat: experimental per-key isolation for the Next.js adapters - #1485

Draft
franky47 wants to merge 4 commits into
ref/single-storefrom
exp/next-key-isolation
Draft

feat: experimental per-key isolation for the Next.js adapters#1485
franky47 wants to merge 4 commits into
ref/single-storefrom
exp/next-key-isolation

Conversation

@franky47

@franky47 franky47 commented Jul 8, 2026

Copy link
Copy Markdown
Member

Next.js' useSearchParams (app) and useRouter (pages) re-render every call site on any search param change, so a page with many keys pays a full re-render for a single-key write. This has kept the shared key-isolation e2e spec marked N/A on Next.js.

Behind an experimental_keyIsolation flag, each adapter instance runs a single Bridge that consumes those contexts and republishes committed search params into a per-key store hooks subscribe to, so writing one key only re-renders its watchers. Publishing at commit time preserves the existing pathname-gate semantics, and the pending-updates overlay covers both the optimistic path and shallow: false round-trips without useOptimistic. Unflagged routes stay on the current path untouched, so pinned render counts hold.

Opt-in and additive: nothing changes for existing consumers unless they set the flag.

Tasks

  • Add docs

Blocked by #1482 (merge first then rebase).

franky47 added 3 commits July 8, 2026 22:50
A fresh context value on every provider render invalidates all consumers
under React 19's lazy context propagation, even through a nested provider of
the same context that should shadow them. Memoizing also removes redundant
re-render invalidations on unrelated provider re-renders for every adapter.
Next.js' useSearchParams (app) and useRouter (pages) re-render every call
site on any search param change. Behind experimental_keyIsolation, a single
Bridge per adapter instance consumes those contexts and publishes committed
search params into a per-key store that hooks subscribe to, so writing a key
only re-renders its watchers. Publishing at commit time only keeps the
pathname-gate semantics (#1293/#1273), and the pending-updates overlay covers
both the optimistic path and shallow: false round-trips without useOptimistic.
On the pages router, isolation additionally requires a render-stable flagged
subtree, as Next re-renders the page tree top-down on every route state change.
Previously N/A on Next.js (the context re-renders made the spec unpassable);
the flagged adapters make it applicable. Nested flagged providers keep every
existing route on the unflagged path, preserving the pinned render counts.
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nuqs Ready Ready Preview Aug 7, 2026 10:58pm

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f0f77f19-af28-4988-8a60-0e87e0b99d86

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 8, 2026

Copy link
Copy Markdown
pnpm add https://pkg.pr.new/nuqs@1485

commit: f380577

@franky47 franky47 added AI slop PR generated by AI, needs some cleanup before merging adapters/next/app Uses the Next.js app router adapters/next/pages Uses the Next.js pages router labels Jul 8, 2026
…ge-next-pr-1485

# Conflicts:
#	packages/nuqs/src/adapters/lib/key-isolation.test.ts
#	packages/nuqs/src/adapters/next/impl.pages.ts
#	packages/nuqs/tests/snapshots/adapters/next/app.snapshot.d.ts
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Bundle size

Base PR Δ
✅ Client 5.94 kB 5.95 kB ⬆️ +10 B
✅ Client (minimal tree-shaken) 4.37 kB 4.37 kB
✅ Server 3.66 kB 3.66 kB

Brotli-compressed. Limits are set in the size-limit config in packages/nuqs/package.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adapters/next/app Uses the Next.js app router adapters/next/pages Uses the Next.js pages router AI slop PR generated by AI, needs some cleanup before merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant