Skip to content

fix: keep order of query parameters - #27174

Merged
Artur- merged 5 commits into
mainfrom
fix/query-parameters-keep-order
Nov 28, 2026
Merged

Artur- merged 5 commits into
mainfrom
fix/query-parameters-keep-order

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

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

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
@totally-not-ai

Copy link
Copy Markdown
Contributor Author

Type of change

  • Bugfix

How to test

  1. Call QueryParameters.fromString("boot=1&ruled=1&disc=1&open=x").getQueryString()
  2. Expect boot=1&ruled=1&disc=1&open=x (before: ruled=1&disc=1&boot=1&open=x)

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Memory footprint

Compared with the base commit 32e7f0a.

Scenario Metric Base Head Change
Empty UI Heap retained per UI 6,456 B 6,488 B $\color{red}\textbf{+32 B}$ (+0.5%)
Empty UI Serialized session with one UI 21,482 B 21,484 B +2 B (ignored)
UI with 200 component rows Heap retained per UI 693,232 B 693,264 B $\color{red}\textbf{+32 B}$ (+0.0%)
UI with 200 component rows Serialized session with one UI 438,899 B 438,901 B +2 B (ignored)
UI with 200 form rows added in the latest round trip Heap retained per UI 1,634,904 B 1,634,944 B $\color{red}\textbf{+40 B}$ (+0.0%)
UI with 200 form rows added in the latest round trip Serialized session with one UI 1,368,748 B 1,368,750 B +2 B (ignored)
UI with 200 form rows Heap retained per UI 1,589,952 B 1,589,984 B $\color{red}\textbf{+32 B}$ (+0.0%)
UI with 200 form rows Serialized session with one UI 1,323,777 B 1,323,779 B +2 B (ignored)
Empty UI: Heap retained per UI by class
Class Instances Bytes
java.util.LinkedHashMap +2 +128
java.util.HashMap −2 −96
UI with 200 component rows: Heap retained per UI by class
Class Instances Bytes
java.util.LinkedHashMap +2 +128
java.util.HashMap −2 −96
UI with 200 form rows added in the latest round trip: Heap retained per UI by class
Class Instances Bytes
java.util.LinkedHashMap +2 +128
java.util.HashMap −2 −96
[B 0 +8
UI with 200 form rows: Heap retained per UI by class
Class Instances Bytes
java.util.LinkedHashMap +2 +128
java.util.HashMap −2 −96
Scenarios
  • Empty UI (empty-ui): A UI with no components, which is the cost of every UI.
  • UI with 200 component rows (ui-with-200-component-rows): A UI with 200 rows, each a div with a class name and a style, holding a span, an input with a value change listener and a button with a click listener.
  • UI with 200 form rows added in the latest round trip (ui-with-200-form-rows-added-in-latest-round-trip): The UI with 200 form rows, with the rows added in the latest round trip, as when navigating to a view, so that the response kept for resending holds all of them.
  • UI with 200 form rows (ui-with-200-form-rows): A UI with 200 rows, each a layout with a theme and several styles, holding a text field and a combo box bound to a bean with a binder and a button with a click listener. The fields are web components with several properties and a synchronized value, and the combo box has client callable methods, as Vaadin components that load data do.

Measured by UIMemoryFootprintTest. Differences under 10 B are ignored.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

 1 701 files  ±0   1 791 suites  ±0   2h 9m 5s ⏱️ - 5m 2s
13 715 tests +2  13 643 ✅ +2  72 💤 ±0  0 ❌ ±0 
14 393 runs  +2  14 321 ✅ +2  72 💤 ±0  0 ❌ ±0 

Results for commit 477d5f1. ± Comparison against base commit 32e7f0a.

♻️ This comment has been updated with latest results.

@mshabarov
mshabarov marked this pull request as ready for review November 24, 2026 08:57
@mshabarov mshabarov added the Intent Approved Labeled open PR means 1. Problem confirmed, 2. Solution confirmed. label Nov 24, 2026

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Unordered input maps now produce a query string order that changes between JVM runs.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sonarqubecloud

Copy link
Copy Markdown

@Artur-
Artur- enabled auto-merge November 26, 2026 07:31
@Artur-
Artur- added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit fc87f81 Nov 28, 2026
143 of 148 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Documentation Bot: No documentation needed for this change.

This is a BEHAVIOR_CHANGE: QueryParameters now preserves the order parameters were given in (query string order, or map iteration order) instead of an arbitrary HashMap-based order. The order was never documented as stable, no existing documentation page claims any ordering guarantee, and no example in vaadin/docs passes an unordered map (e.g. Map.of(...)) to simple()/full() where the new behavior would contradict it. The only addition this change would support is a caveat-style note recommending an ordered map for predictable output, which isn't enough on its own to justify a documentation pull request.

Nothing was opened in vaadin/docs. If you disagree, the change has to be documented by hand there.

Generated by Documentation Bot for #27174 · agent · 71.8 AIC · ⊞ 11.7K · ◷

vaadin-bot added a commit that referenced this pull request Nov 28, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked-25.4 Intent Approved Labeled open PR means 1. Problem confirmed, 2. Solution confirmed. target/25.4 +0.0.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hackathon 25.4: QueryParameters could keep the order the parameters were given in

4 participants