Re: [whatwg/url] Proposal: URL.setSearchParams() (Issue #828)

I think a `searchParams` setter makes the most sense but I also don't see this as a critical issue to address and would likely prefer not to change this.

> The one question I see is what should happen if URLSearchParams already has an associated URL. We'd have to decide between throwing or changing the URL association (and updating both the old and new URL). I don't think we want to end up in a situation where a single URLSearchParams can be associated with multiple URLs.

I think there are a few options here.

1. The setter could be defined to essentially clone/copy the given `URLSearchParams` as opposed to storing it by reference. It could be a bit odd in some cases in that the following would hold true `url.searchParams = newSearchParams; url.searchParams !== newSearchParams` but it would address the URL link issue.

2. Throw if the `URLSearchParams` has a link to a URL such that users would need to do something like `url.searchParams = new URLSearchParams(otherUrl.searchParams)`

3. Make it possible to detach a `URLSearchParams` from it's `URL`, e.g. `url.searchParams = otherUrl.searchParams.detach()` ... which would effectively null out the search params on the `otherUrl` and break that link.

Of these, number 2 would be my preference.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/url/issues/828#issuecomment-2127324738
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/url/issues/828/2127324738@github.com>

Received on Thursday, 23 May 2024 14:47:09 UTC