Repository navigation
fix: keep order of query parameters - #27174
Conversation
QueryParameters copied its parameters into hash maps, so the query string, and the browser address written on navigation, listed them in hash order. Keep the order of the query string or of the map they were created from, also for excluding, including and merging. Fixes #27172
Type of change
How to test
|
Memory footprintCompared with the base commit 32e7f0a.
Empty UI: Heap retained per UI by class
UI with 200 component rows: Heap retained per UI by class
UI with 200 form rows added in the latest round trip: Heap retained per UI by class
UI with 200 form rows: Heap retained per UI by class
Scenarios
Measured by |
vaadin-review-bot
left a comment
There was a problem hiding this comment.
Reviewed the changes — left 1 comment.
| Finding | |
|---|---|
| Unordered input maps now produce a query string order that changes between JVM runs. |
| /** | ||
| * Creates query parameters from parameter map. | ||
| * <p> | ||
| * The parameters keep the iteration order of the given map, so use an |
There was a problem hiding this comment.
The old HashMap copy gave an arbitrary but stable order for a given set of names. The order is now whatever the input map iterates in, and Map.of(...) with two or more entries iterates in an order randomized per JVM.
So QueryParameters.simple(Map.of("page", "1", "sort", "name")) renders a different href after each restart. That group isn't in the PR's risk list, which only names apps passing an ordered map or parsing a string.
Nothing here or in flow-components breaks, but it is worth saying in the risk notes. The ordering hint added to the constructor would also help on full and simple, which are the usual map entry points and say nothing about order.
QueryParameters.java:53 · correctness
There was a problem hiding this comment.
Good point. full and simple now carry the same ordering note as the constructor, and all three say that maps without a defined order, such as Map.of, may give a different order in each JVM run. The PR description lists this as a risk. I kept the behaviour itself: sorting or hashing unordered input would bring back the reordering this PR removes for ordered maps, and there is no way to tell the two kinds of map apart.
|
|
Documentation Bot: No documentation needed for this change. This is a Nothing was opened in vaadin/docs. If you disagree, the change has to be documented by hand there.
|
This PR cherry-picks changes from the original PR #27174 to branch 25.4. --- > Fixes #27172 > > **behavior deviation** · flow-server · apps that navigate with query parameters or render links from them > > Query parameters came out in hash order instead of the order they were given in. So the browser address written on navigation, and links built from `QueryParameters`, could list parameters differently from the address the user pasted. They now keep the order of the query string, or of the map they were created from. Applications had no workaround. > > **Risks:** > -⚠️ Behaviour change: the order of parameters in the query string changes for apps that pass an ordered map or parse a string. The order was never documented as stable, and the old order was arbitrary. All values of a repeated name are still written together, at the position where the name first appears (`b=1&a=2&b=3` becomes `b=1&b=3&a=2`). > -⚠️ Maps without a defined order, such as `Map.of(...)` passed to `simple` or `full`, now give their own iteration order, which can differ between JVM runs. Before, the `HashMap` copy gave an arbitrary but stable order. The Javadoc of the map factories now recommends an ordered map such as `LinkedHashMap`. > - ✅ No API change, no change to `equals`/`hashCode` (map equality ignores order), no security, memory, serialization, threading or performance impact. > > **Context.** The browser's `URLSearchParams` keeps the order, so Flow was the only step that reordered. A plain `HashMap` copy was used in each factory and derive method. > > - Changed every internal copy in `QueryParameters` (constructor, `full`, `simple`, `fromString`, `excluding`, `including`, `merging`, `mergingAll`) to keep insertion order > - `merging`/`mergingAll` keep a replaced name in place and add new names at the end > - Updated the Javadoc of the constructor, `full`, `simple`, `getQueryString()`, `merging` and `mergingAll` to describe the order > - Added tests for the order when creating and when deriving parameters, including a repeated name split by another one > > Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>



Fixes #27172
behavior deviation · flow-server · apps that navigate with query parameters or render links from them
Query parameters came out in hash order instead of the order they were given in. So the browser address written on navigation, and links built from
QueryParameters, could list parameters differently from the address the user pasted. They now keep the order of the query string, or of the map they were created from. Applications had no workaround.Risks:
b=1&a=2&b=3becomesb=1&b=3&a=2).Map.of(...)passed tosimpleorfull, now give their own iteration order, which can differ between JVM runs. Before, theHashMapcopy gave an arbitrary but stable order. The Javadoc of the map factories now recommends an ordered map such asLinkedHashMap.equals/hashCode(map equality ignores order), no security, memory, serialization, threading or performance impact.Context. The browser's
URLSearchParamskeeps the order, so Flow was the only step that reordered. A plainHashMapcopy was used in each factory and derive method.QueryParameters(constructor,full,simple,fromString,excluding,including,merging,mergingAll) to keep insertion ordermerging/mergingAllkeep a replaced name in place and add new names at the endfull,simple,getQueryString(),mergingandmergingAllto describe the order