Skip to content

fix(core): destroy embedded views when creation fails - #72220

Closed
jipeng6036-del wants to merge 1 commit into
angular:mainfrom
jipeng6036-del:codex/destroy-failed-embedded-view-72210
Closed

jipeng6036-del wants to merge 1 commit into
angular:mainfrom
jipeng6036-del:codex/destroy-failed-embedded-view-72210

Conversation

@jipeng6036-del

Copy link
Copy Markdown
Contributor

PR Checklist

  • The commit message follows the commit message guidelines.
  • A regression test was added.
  • Docs have been added / updated. This fix changes internal view cleanup.

PR Type

  • Bugfix

What is the current behavior?

If a sibling throws while an embedded view is being created, the view is never attached to a container that could destroy it. Earlier siblings keep their destroy hooks and subscriptions alive across retries.

Fixes #72210

What is the new behavior?

Destroy the partially created view before rethrowing the render error. The cleanup loop skips entries that the failed instance did not reach, so teardown can still run when a previous instance registered more listeners on the same template.

Does this PR introduce a breaking change?

  • No

Other information

The regression test first renders a healthy view, then triggers an update error and retries with a constructor error. On the original code, the retry leaves one earlier sibling alive. With this change both siblings are destroyed and the boundary still reports the constructor error.

The new test failed on the original code. The full render3 Jasmine target passed with the fix (609 specs, 0 failures, 2 existing pending specs). Prettier passed for the changed files.

Thanks to @SkyZeroZx for the reproduction and for pointing out which destroy hooks were missing.

Tear down partially created embedded views before rethrowing a render
error. Skip cleanup entries that the failed instance did not register.

Fixes angular#72210
@angular-robot angular-robot Bot added the area: core Issues related to the framework runtime label Nov 26, 2026
@ngbot ngbot Bot added this to the Backlog milestone Nov 26, 2026
@pullapprove
pullapprove Bot requested a review from JeanMeche November 26, 2026 08:32
@JeanMeche

Copy link
Copy Markdown
Member

Thanks for investigating #72210 and putting this together!

Calling destroyLView on a partially created view exposes a few additional edge cases that aren't handled here:

  • executeOnDestroys would invoke ngOnDestroy with this = null/undefined for any uninstantiated directives, pipes, or unrendered child views already present in tView.destroyHooks.
  • Any error thrown during destroyLView teardown would escape and mask the original creation error.
  • Dynamic component creation (ComponentFactory.create) has the same partial-view leak when creation fails.

Closing this in favor of #72222, which addresses these cases as well.

@JeanMeche JeanMeche closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Issues related to the framework runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@boundary keeps subscriptions alive after a sibling constructor throws

2 participants