Skip to content

fix: make conditional editing work with lazy columns#11405

Merged
sissbruecker merged 5 commits into
mainfrom
fix/lazy-column-conditional-cell-editing
Mar 25, 2026
Merged

fix: make conditional editing work with lazy columns#11405
sissbruecker merged 5 commits into
mainfrom
fix/lazy-column-conditional-cell-editing

Conversation

@sissbruecker
Copy link
Copy Markdown
Contributor

Description

The conditional editing logic needs to access the row from a cell element and currently uses cell.parentElement. When using lazy column rendering, cells are created eagerly when rendering rows but are not added to the row yet, so accessing parentElement does not return the row reference.

This changes the logic to use the __parentRow property, which is set when creating the cell.

Fixes vaadin/flow-components#8976

Type of change

  • Bugfix

Comment thread packages/grid-pro/src/vaadin-grid-pro-inline-editing-mixin.js
@sissbruecker sissbruecker requested a review from tomivirkki March 24, 2026 09:47
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's an error that happens in Firefox and Safari when you scroll away from the column while the editor is active, so that the column is detached, and then scroll back to the same column and try to open the editor on the same cell again. That seems to happen because _stopEdit is never called when the element is detached whereas in Chrome it does:

grid-edit-firefox.mp4

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.

Looks like those browsers don't fire focusout when the focused element is removed from the DOM. Added an override for __updateColumnsBodyContentHidden to detect when the edited cell is removed from the DOM.

The added tests only covers Safari, as Playwright Firefox does fire focusout in that case 🤦‍♂️

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, I recall facing this same limitation in another issue (maybe also related to grid-pro 🤔). I can't see the issue anymore.

});
});

describe('lazy column rendering', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In line 542 of the vaadin-grid-pro-inline-editing-mixin file, it checks that cell.parentNode === row. It should use cell.__parentRow === row for consistency with the rest of the PR. Without this, item identity changes are not detected when the edited cell is lazy-detached.

This test fails without the suggested change.

      it('should stop editing when item identity changes for a detached edited cell', async () => {
        let cell = getCellByColumnPath('col1');
        cell.focus();
        await sendKeys({ press: 'Enter' });
        expect(getCellEditor(cell)).to.be.ok;

        // Scroll far right so col1 cell gets detached from the DOM
        await scrollHorizontally(400);

        // Change the item identity for the edited row
        grid.items = [
          { col0: 'x0', col1: 'x1', col2: 'x2', col3: 'x3', col4: 'x4', col5: 'x5', col6: 'x6', col7: 'x7' },
          { col0: 'b0', col1: 'b1', col2: 'b2', col3: 'b3', col4: 'b4', col5: 'b5', col6: 'b6', col7: 'b7' },
        ];
        flushGrid(grid);

        // The edit should be stopped because the item identity changed
        expect(getCellEditor(cell)).to.not.be.ok;
      });

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.

Updated it to use __parentRow to be safe. The test from the other issue should cover this already (editor is removed when cell is removed).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Works now

@sonarqubecloud
Copy link
Copy Markdown

});

// Focus button mode that is active on MacOS causes issues with Tab key navigation in Firefox when run with Playwright
(isFirefox && isMac ? it.skip : it)('should navigate through editable cells with Tab', async () => {
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.

Had to skip this one on FF / Mac, looks like there is an unrelated issue with the focus button mode in keyboard navigation mixin that can also be observed in some scenarios when testing manually on main.

Copy link
Copy Markdown
Contributor

@DiegoCardoso DiegoCardoso left a comment

Choose a reason for hiding this comment

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

LGTM

});
});

describe('lazy column rendering', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Works now

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, I recall facing this same limitation in another issue (maybe also related to grid-pro 🤔). I can't see the issue anymore.

@sissbruecker sissbruecker merged commit e173de5 into main Mar 25, 2026
10 checks passed
@sissbruecker sissbruecker deleted the fix/lazy-column-conditional-cell-editing branch March 25, 2026 09:31
vaadin-bot pushed a commit that referenced this pull request Mar 25, 2026
* fix: make conditional editing work with lazy columns

* fix tests

* handle cell editor navigation when using lazy column rendering

* make getEventContext work with lazily rendered cells

* stop editing when edited cell is scrolled out of view
@vaadin-bot
Copy link
Copy Markdown
Collaborator

Hi @sissbruecker and @sissbruecker, when i performed cherry-pick to this commit to 24.10, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick e173de5
error: could not apply e173de5... fix: make conditional editing work with lazy columns (#11405)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

vaadin-bot pushed a commit that referenced this pull request Mar 25, 2026
* fix: make conditional editing work with lazy columns

* fix tests

* handle cell editor navigation when using lazy column rendering

* make getEventContext work with lazily rendered cells

* stop editing when edited cell is scrolled out of view
@vaadin-bot
Copy link
Copy Markdown
Collaborator

Hi @sissbruecker and @sissbruecker, when i performed cherry-pick to this commit to 24.9, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick e173de5
error: could not apply e173de5... fix: make conditional editing work with lazy columns (#11405)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

sissbruecker added a commit that referenced this pull request Mar 25, 2026
* fix: make conditional editing work with lazy columns

* fix tests

* handle cell editor navigation when using lazy column rendering

* make getEventContext work with lazily rendered cells

* stop editing when edited cell is scrolled out of view

Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
sissbruecker added a commit that referenced this pull request Mar 25, 2026
….0) (#11411)

* fix: make conditional editing work with lazy columns (#11405)

* fix: make conditional editing work with lazy columns

* fix tests

* handle cell editor navigation when using lazy column rendering

* make getEventContext work with lazily rendered cells

* stop editing when edited cell is scrolled out of view

* replace scrollToColumn with individual calls

---------

Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GridPro Lazy Column Rendering Bug with AbstractBackEndDataProvider

4 participants