Skip to content

fix: improve view teardown process for reusable views#11260

Open
edusperoni wants to merge 1 commit into
mainfrom
fix/reusable-views-teardown
Open

fix: improve view teardown process for reusable views#11260
edusperoni wants to merge 1 commit into
mainfrom
fix/reusable-views-teardown

Conversation

@edusperoni
Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

When destroying a reusable view's node, two issues exist:

  1. destroyNode() calls callUnloaded() unconditionally, even when the view was never loaded. This can fire unloaded lifecycle events (and run unload logic) on views that are not in a loaded state.
  2. During _tearDownUI(), children are torn down by inheriting the parent's force flag (child._tearDownUI(force)). When the parent is being destroyed but a child is marked as reusable, the child's native view is preserved and skipped, leaving orphaned/leaked native views behind.

What is the new behavior?

  1. destroyNode() now uses unloadView(this), which guards on view.isLoaded before calling callUnloaded(), so the unloaded path only runs for views that are actually loaded.
  2. When a view is torn down, its children are now always torn down with force = true (child._tearDownUI(true)), regardless of whether they are marked reusable. Once a parent is being destroyed, its children are destroyed too. Developers who want to reuse a child elsewhere are responsible for detaching it beforehand.

Together these changes make the teardown process for reusable views more correct and prevent native view leaks.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jun 4, 2026

View your CI Pipeline Execution ↗ for commit 134c9e5

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 57s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-04 18:31:27 UTC

@farfromrefug
Copy link
Copy Markdown
Collaborator

@edusperoni destroyNode is only used by angular?

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.

2 participants