Re: [whatwg/url] URLSearchParams inconsistent behavior with multiple same-name parameters leads to data loss on backend (Issue #889)

Voral left a comment (whatwg/url#889)

Of course, I understand that I can manually work around this issue by writing:

```js
const params = new URLSearchParams();
params.append('category[]', 'books');
params.append('category[]', 'movies');
```

This will indeed produce the format that PHP expects: `category[]=books&category[]=movies`

However, this feels more like a workaround than a clean solution. It requires:
- Manually modifying parameter names with `[]` brackets
- Remembering which parameters should be treated as arrays
- Creating inconsistency in the API (some parameters with `[]`, some without)

What I was hoping for is a more elegant, native way to handle this common use case. The current approach forces developers to leak backend-specific implementation details (PHP's array syntax) into their frontend JavaScript code.

A cleaner API would allow us to work logically with multi-value parameters while letting the serialization layer handle the compatibility aspects automatically.

The manual `[]` approach works, but it undermines the promise of URLSearchParams as a convenient, standards-based abstraction for working with query parameters and form data.

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

Message ID: <whatwg/url/issues/889/3462048889@github.com>

Received on Wednesday, 29 October 2025 15:00:44 UTC