Skip to content

fix(aria/accordion): avoid errors when destroyed before initialization - #34061

Merged
crisbeto merged 2 commits into
angular:mainfrom
nagahara-naoki:fix-aria-accordion-destroy-before-init
Nov 11, 2026
Merged

crisbeto merged 2 commits into
angular:mainfrom
nagahara-naoki:fix-aria-accordion-destroy-before-init

Conversation

@nagahara-naoki

@nagahara-naoki nagahara-naoki commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #34060.

AccordionTrigger.ngOnDestroy() reads the required panel() input even if the trigger is destroyed before the first change detection and ngOnInit has not run. Destroying a newly created TestBed fixture therefore throws NG0950, despite the template binding [panel] correctly.

Retain the panel associated during ngOnInit and only clear that association during destruction if initialization established it. Unregistering from the group remains safe for an unregistered trigger. This follows the registration/cleanup approach in #33974 (combobox).

Adds an early-destruction regression test and an initialized control that verifies the panel association exists before destruction and is cleared afterward. The changes are based on main after #34053.

Related Tree PR: #34059. This PR is independent and contains only accordion changes.

Validation

  • Before the fix, the Chromium accordion suite reports 44 passed, 1 failed; the new early-destruction test throws NG0950: Input "panel" is required but no value is available yet. The initialized control passes.
  • After the fix, pnpm test src/aria/accordion --no-watch passes: 45 specs, 0 failures, including the strengthened initialized cleanup assertion.
  • pnpm bazelisk test //goldens:aria_api passes.
  • pnpm ng-dev format changed --check passes.
  • TSLint passes for both changed TypeScript files.
  • git diff --check and commit-message validation pass.

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. Complete reproduction code, steps, environment, and actual error are in #34060.

Retain the panel associated during initialization so destruction does not read an unset required input. Cover early destruction and verify that initialized triggers still clear their panel association.

Fixes angular#34060
@ok7sai

ok7sai commented Nov 5, 2026

Copy link
Copy Markdown
Member

See the comment #34059 (comment)

@nagahara-naoki

Copy link
Copy Markdown
Contributor Author

Thanks! I’ll apply the same approach here and verify it with tests.

Keep panel registration and cleanup together using an effect instead of a retained reference. Cover panel input changes and update the API golden for removed lifecycle hooks.
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Nov 11, 2026
@crisbeto
crisbeto merged commit 17b4f1f into angular:main Nov 11, 2026
33 of 35 checks passed
@crisbeto

Copy link
Copy Markdown
Member

This PR was merged into the repository. The changes were merged into the following branches:

crisbeto pushed a commit that referenced this pull request Nov 11, 2026
#34061)

* fix(aria/accordion): avoid errors when destroyed before initialization

Retain the panel associated during initialization so destruction does not read an unset required input. Cover early destruction and verify that initialized triggers still clear their panel association.

Fixes #34060

* fix(aria/accordion): manage registration with effects

Keep panel registration and cleanup together using an effect instead of a retained reference. Cover panel input changes and update the API golden for removed lifecycle hooks.

(cherry picked from commit 17b4f1f)
DuncanFaulkner added a commit to DuncanFaulkner/components that referenced this pull request Nov 30, 2026
…fter first render

Since angular#34061, `AccordionTrigger` links itself to its panel inside an effect, which can run after
the panel's first render. `AccordionPanel.visible` is a computed over `_pattern`, which was a plain
field. If anything reads `visible()` before the trigger links (for example a template binding such
as `[class.hidden]="!panel.visible()"`), the computed caches `false` with no reactive
dependencies and never re-evaluates. The panel's own `[attr.inert]` host binding reads the same
computed, so the panel stays hidden and inert even though the trigger reports
`aria-expanded="true"`.

The panel's `_pattern` field is replaced by a `_triggerPattern` signal that the trigger sets, so
`visible()` updates when the trigger links or unlinks the panel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: aria/accordion target: patch This PR is targeted for the next patch release

3 participants