Repository navigation
fix(aria/tree): avoid errors when destroyed before initialization - #34059
Open
nagahara-naoki wants to merge 2 commits into
Open
nagahara-naoki wants to merge 2 commits into
nagahara-naoki wants to merge 2 commits into
Conversation
Remember the tree, parent group, and owning item used during registration so destruction does not read required inputs before ngOnInit has run. Add regression tests for early destruction and controls for initialized trees. Fixes angular#34058
This was referenced Nov 4, 2026
Open
Member
|
Thanks for the contribution! A cleaner way might be moving the required input reads from constructor() {
effect(onCleanup => {
const owner = this.ownedBy();
untracked(() => {
this._deferredContent.deferredContentAware.set(owner);
owner._register(this);
});
onCleanup(() => owner._unregister(this));
});
}so we don't need to create new pointers, and don't need to handle when those input values have changed. |
Contributor
Author
|
Thanks for the suggestion! Using |
Keep registration and cleanup together using effects instead of retained references. Cover changing tree and group owner inputs and update the API golden for removed lifecycle hooks.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #34058.
TreeItemandTreeItemGroupread required signal inputs during destruction, even when they are destroyed before the first change detection andngOnInithas not run. A synchronously destroyed TestBed fixture therefore throws NG0950 forparentorownedBy, despite the inputs being bound in its template.Retain the tree, parent group, and owning item used during registration. Destruction only unregisters those retained references, so uninitialized directives have nothing to clean up. This follows the registration/cleanup approach used for combobox in #33974 (related issue #33972).
Adds regression tests for a static flat tree and a static nested tree destroyed before their first change detection, plus controls that destroy both after initialization. This PR only changes tree; no accordion changes or public API changes are included.
Validation
parentandownedBy. Both initialized controls pass.pnpm test src/aria/tree --no-watchpasses: 146 specs, 0 failures.pnpm bazelisk test //goldens:aria_apipasses.pnpm ng-dev format changed --checkpasses.git diff --checkpasses.Tested with Node.js 22.23.4 and pnpm 12.16.1 on macOS arm64. The full Material/CDK/Aria test suites and Firefox were not run locally; validation covers the Chromium tree suite and Aria API golden check. Detailed reproduction code, setup, and actual errors are in #34058.