redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

Sort Query String Order

Open SeanFitzpatrick0 opened this issue 3 years ago • 2 comments

RTK Query uses URLSearchParams to serialise the query parameters.

URLSearchParams does not serialise these parameters in any specific order. This makes it difficult to sign the request using sigV4 as the order that the parameters that are used for the signature may not be the same as the order RTK Query will serialise them in.

This can be resolved by sorting the URLSearchParams before serialising them (see here).

i.e. The change would be to just add .sort here.

SeanFitzpatrick0 avatar Jul 29 '22 22:07 SeanFitzpatrick0

params is an object there, how would you call .sort on that?

To be honest, this is not a very common requirement and as I guess that a simple .sort will not do it, but this will require some more code I'd recommend that you use the paramsSerializer instead - we would otherwise be adding quite some code that only a very small part of the userbase would have use for - but shipping it to everyone.

phryneas avatar Jul 30 '22 07:07 phryneas

I am referring to sorting this (new URLSearchParams(stripUndefined(params))).

I can definitely unblock myself with using paramsSerializer , but IMO I think it would be nice for this package to offer a consistent order that users can expect to have their query params by default.

Feel free to close if you don't think this can offer value. Just a small paper cut issue that I think can offer a slightly better experience.

Thanks for looking into this.

SeanFitzpatrick0 avatar Aug 01 '22 12:08 SeanFitzpatrick0