Skip to content

Grid: component cells retry setTimeout forever when their node never arrives (hidden component column on 25.2; hidden grid also on 25.3) #10145

Closed

Description

@mkopyczok

Description

A Grid column created with addComponentColumn can be hidden with setVisible(false) in the same server round trip that sends new rows, for example together with setItems. When that happens, every new cell of that column starts an endless setTimeout loop in the browser.

With the example below (10 rows), on 25.2.8:

  • The page is idle, yet setTimeout runs about 2 440 times per second. Every call comes from FlowComponentDirective.updateContent in flow-component-directive.js.
  • The node lookups keep failing. Vaadin.Flow.clients[appId].getByNodeId(nodeid) returns null for 10 node ids, one per new row. Flow never sends components that sit under a hidden column, so these lookups can never succeed.
  • The loop does not stop on its own. The rate is unchanged 5 seconds later, and nothing in the directive would stop it.
    • No connected element carries __nodeRetryTimeout, so the retrying cells are detached from the document.
    • The directive re-arms its timer after every failed lookup. It stops only when the node resolves or when Lit calls disconnected(), and neither happens for these cells.
  • Showing the column again stops the loop, because the components then arrive.
  • Two separate round trips do not trigger it: hiding the column first and replacing the items afterwards gives no loop.

In a production application with three hidden component columns, we measured about 23 000 calls per second. That kept a CPU core busy for as long as the tab stayed open.

Why it happens on 25.2

  1. The cell content is detached at once, but the rows are rebuilt later. _hiddenChanged in vaadin-grid-column removes the column's cell _content elements from the DOM immediately. _renderColumnTree, which drops hidden columns from the rows, only runs on the next animation frame.
  2. The rows are rendered before that frame. In the same response, the connector's set() calls __updateVisibleRows() synchronously. __updateRow then calls the renderer of every cell in the row, including the cells of the hidden column, whose content is already detached.
  3. The lookup can never succeed. The row data still carries the component's nodeid, because 25.2 generates data for hidden columns. Flow, however, never binds a component under a hidden column. The directive therefore keeps retrying on a detached element.

25.3 avoids this through #6798 ("do not generate data for hidden columns", which fixes #6737):

  • On 25.3.0-beta1 and 25.3.0-rc1, the rows sent after hiding the column have no lr_…_nodeid field, so the directive has nothing to look up.
  • Grid.Column has the new compositeDataGenerator only from 25.3 on.
  • refactor!: do not generate data for hidden columns #6798 was merged as a breaking refactor, and we found no 25.2 backport.

The unbounded retry in flow-component-directive.js is still unchanged on main.

Our workaround is a Grid subclass with two changes for its component columns:

  • the data generator skips generating components while the column element is hidden;
  • a setVisible override calls getDataCommunicator().reset() when the visibility changes.

Expected outcome

  • On 25.2, a hidden component column does not leave cells pointing at components the server never sends. Either refactor!: do not generate data for hidden columns #6798 or a narrower fix could achieve this, for example one that skips only renderer data for hidden columns.
  • Independently, the directive stops retrying after a bounded number of attempts, instead of running forever. Any other nodeid that never resolves would loop the same way. Stopping only once the cell is detached is not enough: in the second trigger (see the comments), the retrying cells stay connected.

Minimal reproducible example

@Route("")
public class HiddenComponentColumnView extends VerticalLayout {

  private final Grid<String> grid = new Grid<>();
  private int itemGeneration;

  public HiddenComponentColumnView() {
    grid.addColumn(item -> item).setHeader("Text");
    Grid.Column<String> componentColumn =
        grid.addComponentColumn(item -> new Span("component of " + item)).setHeader("Component");
    grid.setItems(nextItems());

    add(
        grid,
        new Button(
            "Hide the column and replace the items",
            click -> {
              componentColumn.setVisible(false);
              grid.setItems(nextItems());
            }),
        new Button("Show the column", click -> componentColumn.setVisible(true)),
        new Button("Hide the column only", click -> componentColumn.setVisible(false)),
        new Button("Replace the items only", click -> grid.setItems(nextItems())));
  }

  private List<String> nextItems() {
    itemGeneration++;
    return IntStream.rangeClosed(1, 10).mapToObj(row -> "item " + itemGeneration + "." + row).toList();
  }
}

Counting snippet for the DevTools console:

(() => {
  const originalSetTimeout = window.setTimeout;
  let calls = 0;
  window.setTimeout = function (...args) {
    calls++;
    return originalSetTimeout.apply(this, args);
  };
  originalSetTimeout(() => {
    window.setTimeout = originalSetTimeout;
    console.log(`setTimeout calls in 1 s: ${calls}`);
  }, 1000);
})();

Steps to reproduce

  1. Open the view and run the snippet in the DevTools console. It prints 0.
  2. Click Hide the column and replace the items.
  3. Run the snippet again. It prints about 2440, and a run a few seconds later prints the same.
  4. Click Show the column. The snippet prints 0 again.
  5. For comparison, reload the page, click Hide the column only, and then click Replace the items only. The snippet prints 0.

Environment

Vaadin version(s): 25.2.8 (Flow client 25.2.9, vaadin-grid 25.2.11) and 25.2.7 are affected. Because of #6798, the trigger above does not reproduce on 25.3.0-beta1 and 25.3.0-rc1. The second trigger in the comments does reproduce on 25.3.0-rc1.
Spring Boot 4.1.1, Java 21, development mode
OS: Ubuntu 24.04

Browsers

Chrome

Activity

  1. mkopyczok commented on Sep 17, 2026

    @mkopyczok
    Author

    Runnable project with the view above: mkopyczok/vaadin-hidden-component-column-repro

    Run mvn spring-boot:run and open http://localhost:8092/. Its README lists the numbers measured per Vaadin version.

  2. mkopyczok commented on Sep 17, 2026

    @mkopyczok
    Author

    Follow-up: the loops outlive the view, and they add up.

    Navigating to another route with UI.navigate, without a page reload, does not stop them, because nothing renders the detached cells again. Measured on 25.2.8 with the example above plus a second route that has no grid:

    Step setTimeout calls per second
    Grid view, idle 0
    Hide the column and replace the items 2 460
    Navigate to a view without any grid 2 430
    Same view, 10 s later 2 450
    Navigate back (a new grid view instance) 2 450
    Show the column in the new grid 2 450
    Reload the page 0

    Each trigger adds new loops to the ones already running. We repeated "hide and replace, navigate away, navigate back" three times, and the rate went 2 450 → 4 880 → 7 350 calls per second. Only a page reload or closing the tab stops them, so a user who keeps the tab open collects more loops with every trigger.

    The second route used for this:

    @Route("other")
    public class OtherView extends VerticalLayout {
    
      public OtherView() {
        add(new Button("Back to the grid view",
            click -> UI.getCurrent().navigate(HiddenComponentColumnView.class)));
      }
    }

    In HiddenComponentColumnView, add new Button("Go to another view", click -> UI.getCurrent().navigate(OtherView.class)).

  3. mkopyczok commented on Sep 17, 2026

    @mkopyczok
    Author

    A second trigger, which 25.3.0-rc1 does not fix.

    The endless retry also starts when three things happen in one round trip:

    • the grid, or any of its parents, is hidden with setVisible(false);
    • its rows are replaced (setItems, or getDataProvider().refreshAll());
    • a column is hidden.

    The hidden column does not have to be a component column; a plain text column is enough. The cells that loop belong to the grid's other component columns, which stay visible. Hiding the only component column gives 0.

    Unlike the case in the description, this still loops on 25.3.0-rc1, so #6798 does not cover it.

    @Route("")
    public class StaleRowsView extends VerticalLayout {
    
      public StaleRowsView() {
        Grid<String> grid = new Grid<>();
        Grid.Column<String> textColumn = grid.addColumn(item -> "text of " + item).setHeader("Text");
        grid.addComponentColumn(item -> new Span("component of " + item)).setHeader("Component");
        grid.setItems(IntStream.rangeClosed(1, 10).mapToObj(row -> "item " + row).toList());
    
        add(grid, new Button("Hide the grid, clear the items, hide the text column", click -> {
          grid.setVisible(false);
          grid.setItems(List.of());
          textColumn.setVisible(false);
        }));
      }
    }

    Measured with the counting snippet from the description, after the click:

    Vaadin setTimeout calls per second Node ids getByNodeId cannot find
    25.2.8 about 2 450 10
    25.3.0-rc1 (Flow 25.3.0-rc2) about 2 450 10
    • Any two of the three steps alone give 0 calls per second.
    • Showing the grid again stops the loop only when it comes back with new, non-empty items. Showing it with an empty item list does not stop it.

    A runnable version, with these control cases and the workaround below, is the /stale-rows view in mkopyczok/vaadin-hidden-component-column-repro.

    What seems to happen:

    1. The client keeps the old rows. Flow holds back the JavaScript calls of invisible components, so the grid's connector calls ($connector.updateSize and the others) do not reach the client.
    2. Those rows' components are gone. setItems destroys them, and the same response detaches their nodes.
    3. The column change still reaches the client. A visible=false change is sent even under the invisible grid; a visible=true change is not.
    4. The stale rows are rendered again. Hiding the column runs _hiddenChanged → (next animation frame) _renderColumnTree → __updateRow, and every component cell of those rows looks up a node that no longer exists. Those cells stay connected to the document and keep retrying, and nothing renders them again until the grid is shown with new rows.

    Where we hit it. A message list shows an empty-state placeholder with grid.setVisible(false), and switches between a "From" and a "To" column per folder. Going from a non-empty folder into an empty folder with the other layout looped at ~2 900–11 000 calls per second.

    Our workaround. We hide the grid with CSS (display: none via a class) instead of setVisible(false), and keep its parents visible. The grid stays active, so its row update arrives in the same response, and every path above then measures 0.

    This makes the bounded retry in flow-component-directive.js, asked for in the description, more relevant: any nodeid that stops resolving leaves a loop running, not only one in a hidden column. Here the retrying cells stay connected (all 10 carry __nodeRetryTimeout), so stopping once the cell is detached would not end these loops; only a bounded retry would.

  4. changed the title [-]Grid (25.2): hiding a component column in the same round trip as new items makes its cells retry `setTimeout` forever[/-] [+]Grid: component cells retry `setTimeout` forever when their node never arrives (hidden component column on 25.2; hidden grid also on 25.3)[/+] on Sep 17, 2026
  5. yuriy-fix commented on Sep 18, 2026

    @yuriy-fix
    Contributor

    Dear @mkopyczok, thank you for detailed report! The issue would require further investigation on our side.

  6. self-assigned this
    on Sep 22, 2026
  7. vaadin-bot commented on Sep 28, 2026

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 25.2.9.

  8. vaadin-bot commented on Sep 29, 2026

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 25.4.0-alpha1.

  9. vaadin-bot commented on Oct 5, 2026

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 25.3.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions