Skip to content

Commit ca93d78

Browse files
fix: ignore sortersChanged for non-existent columns (#9734)
Following up on the AI reproduction, `Grid.sortersChanged` no longer throws when a sorter references a column that was removed on the server between the client emitting the event and the server handling it. The stale sorter is now skipped and any remaining valid sorters are still applied. Fixes #1201 --- 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Sergey Vinogradov <5039436+vursen@users.noreply.github.com>
1 parent bf59b13 commit ca93d78

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

  • vaadin-grid-flow-parent/vaadin-grid-flow/src

vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4028,8 +4028,10 @@ private void sortersChanged(ArrayNode sorters) {
40284028
JsonNode sorter = sorters.get(i);
40294029
Column<T> column = idToColumnMap.get(sorter.get("path").asString());
40304030
if (column == null) {
4031-
throw new IllegalArgumentException(
4032-
"Received a sorters changed call from the client for a non-existent column");
4031+
// The column may have been removed on the server between the
4032+
// client emitting the event and the server handling it. Skip
4033+
// the stale sorter.
4034+
continue;
40334035
}
40344036
if (sorter.has("direction") && sorter.get("direction")
40354037
.getNodeType() == JsonNodeType.STRING) {

vaadin-grid-flow-parent/vaadin-grid-flow/src/test/java/com/vaadin/flow/component/grid/GridSortingTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,32 @@ void changing_sorters() {
247247
testSortListener.events.get(1).getSortOrder());
248248
}
249249

250+
@Test
251+
void sortersChanged_forRemovedColumn_sorterIgnored() {
252+
// A sortersChanged call can reference a column that was removed on the
253+
// server between the client emitting the event and the server handling
254+
// it. Such stale sorters should be ignored, not throw.
255+
ArrayNode sortersArray = JacksonUtils.createArrayNode();
256+
sortersArray.add(createSortObject(getColumnId(nameColumn), "asc"));
257+
sortersArray.add(createSortObject("non-existent-column", "desc"));
258+
callSortersChanged(sortersArray);
259+
260+
assertSortOrdersEquals(GridSortOrder.asc(nameColumn).build(),
261+
testSortListener.events.get(0).getSortOrder());
262+
}
263+
264+
@Test
265+
void sortersChanged_onlyRemovedColumn_sortCleared() {
266+
setTestSorting();
267+
268+
ArrayNode sortersArray = JacksonUtils.createArrayNode();
269+
sortersArray.add(createSortObject("non-existent-column", "asc"));
270+
callSortersChanged(sortersArray);
271+
272+
assertSortOrdersEquals(List.of(),
273+
testSortListener.events.get(1).getSortOrder());
274+
}
275+
250276
@Test
251277
void template_renderer_non_comparable_property() {
252278
Column<Person> column = grid.addColumn(LitRenderer.<Person> of("")

0 commit comments

Comments
 (0)