AUR0502
Error Message
AUR0502: Trying to activate a disposed controller: <ControllerName>
Where <ControllerName> is the name of the controller (often derived from the component's name) that was already disposed.
Description
This error occurs when Aurelia's rendering engine attempts to activate a component's controller (part of the process of rendering and attaching the component), but finds that the controller instance has already been marked as disposed.
Cause
This situation typically arises from incorrect manual manipulation of component lifecycles or asynchronous operations that complete after a component has been removed. Common causes include:
Premature Disposal: Manually calling the controller's
dispose()method or related disposal logic prematurely, before Aurelia has finished its deactivation sequence or while an activation is pending.Race Conditions: An asynchronous operation related to component activation (e.g., fetching data needed for the component) completes, and its callback attempts to proceed with activation steps, but the component was deactivated and disposed in the meantime (e.g., user navigated away quickly).
Reusing Disposed Controllers: Attempting to reuse a controller instance that has already gone through its disposal lifecycle. Controller instances are generally meant to be used once per component instantiation.
Incorrect Lifecycle Management: Custom logic that interferes with Aurelia's standard activation/deactivation flow might lead to controllers being disposed while still being considered for activation.
Solution
Avoid Manual Disposal (Usually): Do not manually call
controller.dispose()unless you have a very specific reason and fully understand the lifecycle implications. Let Aurelia manage the disposal as part of its standard deactivation process.Handle Asynchronous Activation Safely: If activation involves asynchronous operations, ensure that callbacks or subsequent steps check if the controller/component is still active before proceeding. Often, Aurelia's lifecycle hooks (
detaching,unbinding) can be used to cancel pending operations or set flags indicating the component is no longer active.Do Not Reuse Controllers: Treat controller instances as single-use. When a component is re-rendered or navigated back to, Aurelia will typically create a fresh controller instance.
Review Custom Lifecycle Logic: If you have custom code interacting with component controllers or lifecycles, ensure it doesn't conflict with Aurelia's internal state management. Check for places where
disposemight be called inappropriately.
Example
Debugging Tips
Identify which component's controller is causing the error (
<ControllerName>).Examine the code paths leading to the activation attempt. Is it part of the standard Aurelia rendering process, or is it triggered by custom code?
Look for any custom code that might be calling
controller.dispose()or methods that lead to disposal.Set breakpoints in the component's lifecycle hooks (
dispose,detaching,unbinding) and the code attempting activation to understand the sequence of events.Analyze asynchronous operations within the component's lifecycle methods (
activate,binding,bound,attaching). Ensure they handle cancellation or check the component's status before proceeding upon completion.
Last updated
Was this helpful?