Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cdk/tree): react properly to expansion changes #29751

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

BobobUnicorn
Copy link
Collaborator

Fixes #29669. This converts parts of the rendering pipeline to use signals which allows Angular to properly detect changes to the underlying data which may be caused by rendering new nodes. rxjs didn't handle this correctly as the data subscriptions were only set after the initial callback was run, causing partial updates.

@BobobUnicorn BobobUnicorn requested a review from a team as a code owner September 17, 2024 19:44
@BobobUnicorn BobobUnicorn requested review from crisbeto and wagnermaciel and removed request for a team September 17, 2024 19:44
@@ -223,6 +225,10 @@ export class CdkTree<T, K = T>
})
_nodeDefs: QueryList<CdkTreeNodeDef<T>>;

// signals?
Copy link
Member

Choose a reason for hiding this comment

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

Leftover?

sub.unsubscribe();
});
},
{allowSignalWrites: true},
Copy link
Member

Choose a reason for hiding this comment

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

Could we use computed instead of writing inside of an effect?

@@ -16,6 +16,7 @@ describe('CdkTree when provided LegacyTreeKeyManager', () => {

fixture = TestBed.createComponent(SimpleCdkTreeApp);
fixture.detectChanges();
fixture.detectChanges();
Copy link
Member

Choose a reason for hiding this comment

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

These consecutive detectChanges calls seem a bit suspicious. Do we know why they're necessary?

@@ -433,6 +449,8 @@ export class CdkTree<T, K = T>
this._updateCachedData(data.flattenedNodes);
this.renderNodeChanges(data.renderNodes);
this._updateKeyManagerItems(data.flattenedNodes);
// Explicitly detect the initial set of changes to this component subtree
this._changeDetectorRef.detectChanges();
Copy link
Member

@crisbeto crisbeto Sep 18, 2024

Choose a reason for hiding this comment

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

Just a heads-up that the detectChanges call was causing a "Maximum call stack exceeded" in #29733 which I've fixed with #29754. I think that this specific call is fine since it's outside of renderNodeChanges which was the recursive one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(tree): Using cdk-tree with ArrayDataSource and synchronous data, the isExpanded functionality can fail.
2 participants