How to scroll an element into view in a TreeGrid?

I have a “Problems View” where items with issues are listed, and want to be able to navigate to corresponding item presented in a TreeGrid. Setting the selection works fine, but it is not reliably scrolled into view. Noted that https://vaadin.com/docs/latest/components/tree-grid#best-practices says just that: “scrollToIndex() isn’t reliable” … so warned, but if I still want to achive this … any tips?

Tested with code below in the selection listener, and indeed … it does work not reliable :slightly_smiling_face:

    Optional<Object> selectionOpt = event.getFirstSelectedItem();
    if (!selectionOpt.isEmpty()) {
      Integer index = treeGrid.getDataCommunicator().getIndex( selectionOpt.get());
      if (index != null) {
        treeGrid.scrollToIndex(index);
      } 
    }

There will be improved scroll to method in Vaadin 24.1 for TreeGrid which gives better control on this.