Skip to content

preserveWhitespaces can break defer placeholder detection #61725

@LeonEck

Description

@LeonEck

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

No

Description

If the element inside the placeholder of a defer is not directly adjacent to the opening brace and preserveWhitespaces is active, the build fails with NG5002: "viewport" trigger with no parameters can only be placed on an @defer that has a @placeholder block with exactly one root element node.

Broken:

template: `
  @defer (on viewport) {
    <div></div>
  } @placeholder {
    <div></div>
  }
`,
preserveWhitespaces: true,

Working:

template: `
  @defer (on viewport) {
    <div></div>
  } @placeholder {<div></div>}
`,
preserveWhitespaces: true,

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-3q3h25jf?file=src%2Fmain.ts

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 19.2.13
Node: 22.15.0
Package Manager: npm 11.3.0
OS: darwin arm64

Angular: 19.2.13
... cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1902.13
@angular-devkit/build-angular   19.2.13
@angular-devkit/core            19.2.13
@angular-devkit/schematics      19.2.13
@schematics/angular             19.2.13
rxjs                            7.8.2
typescript                      5.7.3
zone.js                         0.15.1

Anything else?

This behavior was initially found and filed as an issue in angular-eslint since it calls the compiler with preserveWhitespaces: true: angular-eslint/angular-eslint#2474

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions