Skip to content

ng2 ui-view: component sometimes created after parent ui-view destroyed. #2949

@vigie

Description

@vigie

In the latest released version, ng2's uiView creates it's components asynchronously. Sometimes, the handler for the component creation can be invoked after the uiViews ngOnDestroy() method has been called, leaving an unused, dangling component in place. This can lead to all kinds of problems (in my case the dangling component was subscribed to a stream and was causing continuous and pointless ajax requests to be sent in response to it).

This problem can be reproduced quite easily when using ng1-to-ng2 module. That module causes a new ng2 ui-view to be created and then torn down on every transition to an ng2 component. When routing between two such ng2 components, the ui-view that is about to be removed to be replaced by the new one first processes the state config change request which causes it to invoke the asynchronous procedure for creating the new component. Before that promise returns, the ui-view is removed, then the promise resolves and the dangling component is created.

I have a simple fix for this in my fork, which I will reference below. However, I see the present top of master has now moved to using angular 2 rc5 and the new synchronous way of creating components. Therefore, as long as that synchronous approach stays in place it does not make sense to issue a pull request for this and this particular bug should not be found in the next release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions