Skip to content

$onChanges fires after $onDestroy causing "Cannot update an unmounted root" in React 19 #33

@ZvozdaB

Description

@ZvozdaB

Bug

$onChanges can be called after $onDestroy during the same AngularJS digest cycle. This calls root.render() on an already-unmounted React root, producing the React 19 error: Cannot update an unmounted root.

React 18 silently ignored this, but React 19 made it a hard error.

Root cause

AngularJS does not guarantee that $onChanges won't fire after $onDestroy when both a binding change and component destruction occur in the same digest cycle.

Reproduction

  1. Angularized React component with bindings on a routed page
  2. Trigger an action that simultaneously:
    • Changes a binding value (e.g. via $rootScope.$broadcast → scope update)
    • Navigates to a different route via $location.path()
  3. Single digest processes both → $onDestroy fires first (root.unmount()), then $onChanges fires (root.render() on unmounted root)

Suggested fix

Add a _destroyed flag in $onDestroy, guard $onChanges and $doCheck with early return. PR incoming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions