Skip to content

Conversation

@vursen
Copy link
Contributor

@vursen vursen commented Jan 8, 2026

Description

The PR fixes a regression that was introduced in #22328. Removing items from the cache turned out to cause issues with the collapse(T item) method, which became unable to find such "unloaded" items and clean up their sub-caches if they were expanded.

While it's technically possible to refactor the collapse(T item) method so that it traverses the tree of sub-caches instead of relying on item contexts, reverting to not clearing the cache seems like the better option. It simplifies the implementation and restores the behavior to what it was in Vaadin 24, where items were removed from the key mapper but remained in the hierarchy mapper.

Note, as part of the fix, a new objects() method was added to KeyMapper to allow HierarchicalDataCommunicator to get all items that have keys and clean up those that are no longer in the viewport. Since KeyMapper always contains fewer items than the Cache, this API helps reduce the number of iterations needed during cleanup.

Fixes vaadin/flow-components#8427.

Type of change

  • Bugfix

@vursen vursen force-pushed the do-not-remove-out-of-viewport-items-from-cache branch from 397f9c7 to c42587b Compare January 8, 2026 12:14
@github-actions
Copy link

github-actions bot commented Jan 8, 2026

Test Results

1 307 files  ±0  1 307 suites  ±0   1h 14m 36s ⏱️ +45s
9 270 tests ±0  9 202 ✅ ±0  68 💤 ±0  0 ❌ ±0 
9 726 runs  ±0  9 650 ✅ ±0  76 💤 ±0  0 ❌ ±0 

Results for commit 02d3c71. ± Comparison against base commit 3d0f854.

This pull request removes 3 and adds 3 tests. Note that renamed tests count towards both.
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorDataGenerationTest ‑ collapseItems_destroyDataCalledBeforeItemRemovedFromKeyMapper
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorViewportTest ‑ setViewportRange_expandItemOutsideRange_adjustRangeToIncludeItem_flatSizeUpdated
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorViewportTest ‑ setViewportRange_toggleItemOutsideRange_flatSizeNotUpdated
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorViewportTest ‑ setViewportRange_expandItemOutsideViewport_moveItemIntoViewport_flatSizeUpdated
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorViewportTest ‑ setViewportRange_expandItem_moveItemOutOfViewport_collapseItem_flatSizeUpdated
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorViewportTest ‑ setViewportRange_toggleItemOutsideViewport_flatSizeNotUpdated

♻️ This comment has been updated with latest results.

@vursen vursen marked this pull request as ready for review January 8, 2026 12:32
@github-actions github-actions bot added +0.0.1 and removed +1.0.0 labels Jan 8, 2026
@vursen vursen requested a review from tltv January 8, 2026 12:39
@vursen vursen changed the title fix: do not remove out-of-viewport items from cache fix: Do not remove out-of-viewport items from cache Jan 8, 2026
@vursen vursen changed the title fix: Do not remove out-of-viewport items from cache fix: Avoid removing out-of-viewport items from cache Jan 8, 2026
@vursen vursen added the target/25.0 Cherry-pick to 25.0 branch label Jan 8, 2026
@sonarqubecloud
Copy link

@vaadin-bot vaadin-bot added +1.0.0 and removed +0.0.1 labels Jan 12, 2026
@tltv tltv merged commit 13427a0 into main Jan 12, 2026
31 checks passed
@tltv tltv deleted the do-not-remove-out-of-viewport-items-from-cache branch January 12, 2026 13:20
vaadin-bot pushed a commit that referenced this pull request Jan 12, 2026
Fixes a regression that was introduced in #22328. Removing items from the cache turned out to cause issues with the collapse(T item) method, which became unable to find such "unloaded" items and clean up their sub-caches if they were expanded.

Simplifies the implementation and restores the behavior to what it was in Vaadin 24, where items were removed from the key mapper but remained in the hierarchy mapper.

Note, as part of the fix, a new objects() method was added to KeyMapper to allow HierarchicalDataCommunicator to get all items that have keys and clean up those that are no longer in the viewport. Since KeyMapper always contains fewer items than the Cache, this API helps reduce the number of iterations needed during cleanup.

Fixes: vaadin/flow-components#8427
vaadin-bot added a commit that referenced this pull request Jan 12, 2026
Fixes a regression that was introduced in #22328. Removing items from the cache turned out to cause issues with the collapse(T item) method, which became unable to find such "unloaded" items and clean up their sub-caches if they were expanded.

Simplifies the implementation and restores the behavior to what it was in Vaadin 24, where items were removed from the key mapper but remained in the hierarchy mapper.

Note, as part of the fix, a new objects() method was added to KeyMapper to allow HierarchicalDataCommunicator to get all items that have keys and clean up those that are no longer in the viewport. Since KeyMapper always contains fewer items than the Cache, this API helps reduce the number of iterations needed during cleanup.

Fixes: vaadin/flow-components#8427

Co-authored-by: Sergey Vinogradov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collapsing items in TreeGrid does not work correctly when the items are not currently in the viewport

4 participants