Unverified Commit 847c14ea authored by Ben Brook's avatar Ben Brook Committed by GitHub

Add `size` property to `ReadonlySearchParams` (#53144)

Closes #49774 (and my dupe https://github.com/vercel/next.js/issues/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 (https://github.com/microsoft/TypeScript/issues/54466). The [URL Standard](https://url.spec.whatwg.org/#dom-urlsearchparams-size) added the size property to URLSearchParams (https://github.com/whatwg/url/pull/734) and this now has wide [browser support](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/size).

parent 11dfdf8d
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()
})
})
......@@ -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
......@@ -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]()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment