Skip to content

Commit

Permalink
Add size property to ReadonlySearchParams (#53144)
Browse files Browse the repository at this point in the history
Closes #49774 (and my dupe #53141), where there's a type error when attempting to construct URLSearchParams from ReadonlyURLSearchParams, [as recommended in the Next docs here](https://nextjs.org/docs/app/api-reference/functions/use-search-params#updating-searchparams) and breaks `next build` on Node v18.16.0+, including on Vercel.


This is blocked by TS publishing the new `dom` types (microsoft/TypeScript#54466). The [URL Standard](https://url.spec.whatwg.org/#dom-urlsearchparams-size) added the size property to URLSearchParams (whatwg/url#734) and this now has wide [browser support](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/size).
  • Loading branch information
bencmbrook authored Aug 17, 2023
1 parent 11dfdf8 commit 847c14e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/next/src/client/components/navigation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ReadonlyURLSearchParams } from './navigation'

describe('next/navigation', () => {
it('should be able to construct URLSearchParams from ReadonlyURLSearchParams', () => {
const searchParams = new URLSearchParams('?foo=test&bar=test')
const readonlySearchParams = new ReadonlyURLSearchParams(searchParams)
expect(() => new URLSearchParams(readonlySearchParams)).not.toThrow()
})
})
2 changes: 2 additions & 0 deletions packages/next/src/client/components/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class ReadonlyURLSearchParams {
keys: URLSearchParams['keys']
values: URLSearchParams['values']
toString: URLSearchParams['toString']
size: any | URLSearchParams['size']

constructor(urlSearchParams: URLSearchParams) {
this[INTERNAL_URLSEARCHPARAMS_INSTANCE] = urlSearchParams
Expand All @@ -45,6 +46,7 @@ export class ReadonlyURLSearchParams {
this.keys = urlSearchParams.keys.bind(urlSearchParams)
this.values = urlSearchParams.values.bind(urlSearchParams)
this.toString = urlSearchParams.toString.bind(urlSearchParams)
this.size = urlSearchParams.size
}
[Symbol.iterator]() {
return this[INTERNAL_URLSEARCHPARAMS_INSTANCE][Symbol.iterator]()
Expand Down

0 comments on commit 847c14e

Please sign in to comment.