Skip to content

Conversation

@vursen
Copy link
Contributor

@vursen vursen commented Aug 12, 2025

Description

Note

This PR is a reopen of #21966 after its unintentional merge and revert.

Warning

DO NOT MERGE until the related flow-components PR is approved.

The PR refactors HierarchicalDataCommunicator so that hierarchy management (expanded items, hierarchical cache) is centralized on the server side instead of being shared between client and server. This makes the client a simple consumer of flattened data lists, which significantly reduces the client-side complexity and opens the door for introducing flat data providers to support fetching flattened data directly from the data source.

Key changes

  1. HierarchyMapper and HierarchicalCommunicationController have been replaced with the new concept, Cache. This new class provides a system for storing data in a hierarchical structure while enabling access in a flattened format for client-side consumption.
  2. setRequestedRange and setParentRequestedRange have been replaced with a single setViewportRange which spans all hierarchy levels.

Caveats

  1. setViewportRange does not currently remove items from Cache and KeyMapper when they move out of the viewport. However, the previous version also only removed items from KeyMapper while keeping them in HierarchyMapper, so item instances actually continued to remain in memory. I feel this could be optimized separately if needed.
  2. setViewportRange currently always sends the full viewport to the client even when some items are already present on the client-side. I plan to address this separately, see #21989
  3. refresh(T item) currently also sends the full viewport on every item refresh. I plan to address this separately, see #21989

Test coverage

  1. The PR aims at providing test coverage for all core functionality and public APIs. Individual tests for internal APIs such as Cache will be added separately.
  2. The refactoring successfully passes all TreeGrid ITs, see #7676

Depends on

Fixes #21876, #21877

Type of change

  • Refactor

@github-actions
Copy link

github-actions bot commented Aug 12, 2025

Test Results

1 245 files  + 4  1 245 suites  +4   1h 11m 19s ⏱️ - 1m 50s
8 622 tests +44  8 555 ✅ +44  67 💤 ±0  0 ❌ ±0 
8 942 runs  +14  8 865 ✅ +13  77 💤 +1  0 ❌ ±0 

Results for commit bdd8a15. ± Comparison against base commit eda19b9.

This pull request removes 16 and adds 60 tests. Note that renamed tests count towards both.
com.vaadin.flow.data.provider.hierarchy.HierarchicalCommunicatorDataTest ‑ expandItem_requestNonOverlappingRange_expandedItemPersistsInKeyMapper
com.vaadin.flow.data.provider.hierarchy.HierarchicalCommunicatorDataTest ‑ expandItem_tooMuchItemsRequested_maxItemsAllowedRequested
com.vaadin.flow.data.provider.hierarchy.HierarchicalCommunicatorDataTest ‑ expandRoot_filterOutAllChildren_clearCalled
com.vaadin.flow.data.provider.hierarchy.HierarchicalCommunicatorDataTest ‑ expandRoot_streamIsClosed
com.vaadin.flow.data.provider.hierarchy.HierarchicalCommunicatorDataTest ‑ sameKeyDifferentInstance_latestInstanceUsed
com.vaadin.flow.data.provider.hierarchy.HierarchicalCommunicatorDataTest ‑ uniqueKeyProviderIsNotSet_keysGeneratedByKeyMapper
com.vaadin.flow.data.provider.hierarchy.HierarchicalCommunicatorDataTest ‑ uniqueKeyProviderIsSet_keysGeneratedByProvider
com.vaadin.flow.data.provider.hierarchy.HierarchicalCommunicatorTest ‑ folderRemove
com.vaadin.flow.data.provider.hierarchy.HierarchicalCommunicatorTest ‑ folderRemoveRefreshAll
com.vaadin.flow.data.provider.hierarchy.HierarchicalCommunicatorTest ‑ leafRemove
…
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorBasicTest ‑ collapseCollectionOfItems_returnsEffectivelyCollapsedItems
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorBasicTest ‑ collapseItems_collapsedChildrenRemovedFromKeyMapper
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorBasicTest ‑ collapseItems_dataGeneratorDestroyDataCalledForCollapsedChildren
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorBasicTest ‑ expandCollectionOfItems_returnsEffectivelyExpandedItems
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorBasicTest ‑ flush_arrayUpdaterInitializedOnce
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorBasicTest ‑ flush_emptyRangeSent
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorBasicTest ‑ getDepth_doesNotReturnDepthForNonExistingItems
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorBasicTest ‑ getDepth_returnsDepthForCachedItemsAfterTheyAreLoaded
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorBasicTest ‑ hasChildren_returnsValueBasedOnDataProvider
com.vaadin.flow.data.provider.hierarchy.HierarchicalDataCommunicatorBasicTest ‑ setBackendSorting_sortingApplied
…

♻️ This comment has been updated with latest results.

@vaadin-bot vaadin-bot added +1.0.0 and removed +0.0.1 labels Aug 12, 2025
@vursen vursen mentioned this pull request Aug 12, 2025
1 task
@vursen vursen requested a review from mshabarov August 13, 2025 10:16
@mshabarov
Copy link
Contributor

To be merged after 25.0.0-alpha4 release of platform.

@vursen vursen changed the title refactor!: centralize hierarchy management server-side refactor!: Centralize hierarchy management server-side Aug 19, 2025
@sonarqubecloud
Copy link

@mshabarov mshabarov merged commit 7a0e62f into main Aug 22, 2025
26 of 27 checks passed
@mshabarov mshabarov deleted the refactor/flattening-data-in-tree-grid branch August 22, 2025 10:58
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 25.0.0-alpha8.

Copilot AI pushed a commit that referenced this pull request Oct 1, 2025
The PR refactors HierarchicalDataCommunicator so that hierarchy management (expanded items, hierarchical cache) is centralized on the server side instead of being shared between client and server. This makes the client a simple consumer of flattened data lists, which significantly reduces the client-side complexity and opens the door for introducing flat data providers to support fetching flattened data directly from the data source.

Key changes
HierarchyMapper and HierarchicalCommunicationController have been replaced with the new concept, Cache. This new class provides a system for storing data in a hierarchical structure while enabling access in a flattened format for client-side consumption.
setRequestedRange and setParentRequestedRange have been replaced with a single setViewportRange which spans all hierarchy levels.
Caveats
setViewportRange does not currently remove items from Cache and KeyMapper when they move out of the viewport. However, the previous version also only removed items from KeyMapper while keeping them in HierarchyMapper, so item instances actually continued to remain in memory. I feel this could be optimized separately if needed.
setViewportRange currently always sends the full viewport to the client even when some items are already present on the client-side. I plan to address this separately, see #21989
refresh(T item) currently also sends the full viewport on every item refresh. I plan to address this separately, see #21989
Test coverage
The PR aims at providing test coverage for all core functionality and public APIs. Individual tests for internal APIs such as Cache will be added separately.
The refactoring successfully passes all TreeGrid ITs, see #7676
Depends on

refactor: remove deprecated HierarchicalDataCommunicator APIs #21965
Fixes #21876, #21877
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.

Replace HierarchicalDataCommunicator with new implementation

4 participants