Skip to content

Warn on negated async pipes #44867

@dgp1130

Description

@dgp1130

Which @angular/* package(s) are relevant/releated to the feature request?

@angular/compiler-cli

Description

Negating an async pipe in an *ngIf thrashes the layout because the pipe emits null immediately before checking the condition. This can lead cause unnecessary rendering work and trigger component events which cause XHR's or other work to be done that shouldn't be needed.

<div *ngIf="!(myConditional | async)">
  <!-- ... -->
</div>

http://codelyzer.com/rules/template-no-negated-async/

Proposed solution

We should consider an extended diagnostic to detect and warn the user of this anti-pattern to head-off their confusing and suggest a better alternative.

I'm not entirely sure what that alternative should be, but I imagine there's an easily transformable way of doing this?

Alternatives considered

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: compilerIssues related to `ngc`, Angular's template compilercompiler: extended diagnosticsfeatureIssue that requests a new featurefeature: under considerationFeature request for which voting has completed and the request is now under consideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions