mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #424] [MERGED] fix: return ReadonlyURLSearchParams from useSearchParams #562
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#562
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/424
Author: @JaredStowell
Created: 3/10/2026
Status: ✅ Merged
Merged: 3/10/2026
Merged by: @james-elicx
Base:
main← Head:jstowell/fix-readonly-search-params📝 Commits (2)
493ba1eUpdate navigation search params4eb5652Fix server readonly cache scope📊 Changes
8 files changed (+335 additions, -27 deletions)
View changed files
📝
packages/vinext/src/shims/navigation.ts(+30 -19)📝
packages/vinext/src/shims/next-shims.d.ts(+7 -3)➕
packages/vinext/src/shims/readonly-url-search-params.ts(+29 -0)📝
tests/e2e/app-router/nextjs-compat/hooks.spec.ts(+32 -0)➕
tests/fixtures/app-basic/app/nextjs-compat/hooks-search-readonly/page.tsx(+85 -0)📝
tests/fixtures/app-basic/next-shims.d.ts(+7 -1)📝
tests/nextjs-compat/hooks.test.ts(+29 -0)📝
tests/shims.test.ts(+116 -4)📄 Description
Summary
Fix
next/navigationcompatibility souseSearchParams()returns a realReadonlyURLSearchParamswrapper instead of a mutableURLSearchParams.This matches Next.js runtime behavior more closely:
ReadonlyURLSearchParamsclassappend,delete,set, andsortuseSearchParams()on both SSR and client pathsuseSyncExternalStoreChanges
packages/vinext/src/shims/readonly-url-search-params.tspackages/vinext/src/shims/navigation.tsto cache and return readonly wrapperspackages/vinext/src/shims/next-shims.d.tsto expose the runtime class and readonly return typetests/fixtures/app-basic/next-shims.d.tstests/fixtures/app-basic/app/nextjs-compat/hooks-search-readonly/page.tsxinstanceof ReadonlyURLSearchParamsand mutation blockingNext.js parity
Ported from:
test/e2e/app-dir/hooks/hooks.test.tstest/e2e/app-dir/hooks/app/hooks/use-search-params/instanceof/page.jsReference implementation:
packages/next/src/client/components/readonly-url-search-params.tspackages/next/src/client/components/navigation.tsVerification
pnpm run fmtpnpm run buildpnpm test tests/shims.test.ts tests/nextjs-compat/hooks.test.tsPLAYWRIGHT_PROJECT=app-router pnpm run test:e2e tests/e2e/app-router/nextjs-compat/hooks.spec.tspnpm run typecheckpnpm run lintpnpm testNotes
This is a behavior change for any app that was incorrectly mutating the object returned by
useSearchParams(), but that previous behavior was not Next.js-compatible🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.