Skip to content

fix(elements): Ensure ForOF out of bound row gets deleted before moving to opposite side.#17199

Open
skrustev wants to merge 1 commit intomasterfrom
skrastev/fix-for-of-elements
Open

fix(elements): Ensure ForOF out of bound row gets deleted before moving to opposite side.#17199
skrustev wants to merge 1 commit intomasterfrom
skrastev/fix-for-of-elements

Conversation

@skrustev
Copy link
Copy Markdown
Member

@skrustev skrustev commented Apr 16, 2026

Closes #17179

Additional information (check all that apply):

  • Bug fix
  • New functionality
  • Documentation
  • Demos
  • CI/CD

Checklist:

  • All relevant tags have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them

Guide to reproducing it consistently:

  1. Expand the first row of the Elements HGrid
  2. Scroll down slowly ensuring rows get added/removed from the view one by one. This ensures a Child Row get replaced by a regular row.
  3. Same for scrolling up but expanding bottom row
hgrid_elements_scroll_correct

--

Performance shouldn't be affected since the update of context now happens before moving the node instead of after. Quick test for HGrid with all rows expanded. The first test is longer due to scrolling to unknown expanded rows:

Old:
Long Tasks:16, Average Long Task Time: 1177.3125
Long Tasks:31, Average Long Task Time: 544.0645161290323
Long Tasks:24, Average Long Task Time: 559.375

With fix:
Long Tasks:16, Average Long Task Time: 1161.4375
Long Tasks:33, Average Long Task Time: 556.6363636363636
Long Tasks:21, Average Long Task Time: 527.0952380952381

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a virtualization edge-case in IgxForOfDirective that can lead to incorrect DOM/view recycling when scrolling (notably reproducible in the “Elements” scenario described in #17179), resulting in incorrect scrollbar sizing/empty space.

Changes:

  • Add null-safety for recycled embedded views when shifting/popping from the internal view cache.
  • Force a view refresh (detectChanges()) after updating template context and before reinserting the recycled view into the ViewContainerRef.

@skrustev skrustev changed the title fix(elements): Ensure ForOF out of bound row gets deleted before moving to bottom. fix(elements): Ensure ForOF out of bound row gets deleted before moving to opposite side. Apr 16, 2026

// Because in Elements the whole parent div (containing data-index) gets removed (possibly due to being disconnected). In Angular it just gets moved.
// This ensures to update it with the new context and remove it first from DOM because of detach action before inserting it manually.
view.detectChanges();
Copy link
Copy Markdown
Member Author

@skrustev skrustev Apr 17, 2026

Choose a reason for hiding this comment

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

Note: In order to minimize this change since it is problematic so far only in Elements, this can be an option that can be enabled for the ForOf and be enabled only for the HGrid on Elements.

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.

IMO from a performance perspective this is fine, since this is only for small scrolls where a single view is moved and re-rendered. So an additional check should not cause a performance degradation.

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.

Adding Paginator/Toolbar to Row Island of a Hierarchical Grid breaks vertical scrollbar when expanding children

5 participants