question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Whitespaces are not trimmed in Text Node with `preserveWhitespaces: false`

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/compiler

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

No idea

Description

A clear and concise description of the problem...

https://github.com/angular/angular/blob/d1ea1f4c7f3358b730b0d94e65b00bc28cae279c/packages/compiler/src/ml_parser/html_whitespaces.ts#L78

<!-- input -->
<span>
  {{ 'text' }}
</span>

<!-- output -->
<span> {{ 'text' }} </span>


<!-- expected -->
<span>{{ 'text' }}</span>

There is no way to trim the text.

πŸ”¬ Minimal Reproduction

https://stackblitz.com/edit/angular-ivy-pkkssb

🌍 Your Environment

Angular Version:




Angular CLI: 9.1.1
Node: 12.18.0
OS: darwin x64

Angular: 9.1.2
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.1
@angular-devkit/build-angular     0.901.1
@angular-devkit/build-optimizer   0.901.1
@angular-devkit/build-webpack     0.901.1
@angular-devkit/core              9.1.1
@angular-devkit/schematics        9.1.1
@angular/cdk                      9.2.1
@angular/cli                      9.1.1
@angular/flex-layout              9.0.0-beta.29
@ngtools/webpack                  9.1.1
@schematics/angular               9.1.1
@schematics/update                0.901.1
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.42.0

Anything else relevant?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
JoostKcommented, Jun 18, 2020

This is on purpose, actually. Whitespace is significant in HTML but collapsed to a single whitespace Because of this, the following is equivalent when rendered:

<strong>Bold</strong> text
<strong>Bold</strong>        text
<strong>Bold</strong>
text

However, the following would not be:

<strong>Bold</strong>text

as it would join the two words together.

1reaction
petebacondarwincommented, Jun 18, 2020

Two things to note with that tool:

  1. It has a β€œconservative collapse” option which is the same as our collapsing strategy.
  2. It tries to be intelligent in cases where there might be a problem:
Screenshot 2020-06-18 at 10 39 40

As @pkozlowski-opensource mentioned, there is room for discussion here but I don’t think this would be a high priority for us.

Read more comments on GitHub >

github_iconTop Results From Across the Web

XDocument.Parse preserving whitespace when not asked to
"Not preserving whitespace" means that any text nodes that contain only whitespace will be ignored while loading the XDocument .
Read more >
White Space and Significant White Space Handling when ...
To create white space nodes, set the PreserveWhitespace property to true. If the property is set to false, which is the default, white...
Read more >
How whitespace is handled by HTML, CSS, and in the DOM
There will be some text nodes that contain only whitespace, and; Some text ... Most whitespace characters are ignored, not all of them...
Read more >
State.ng2component - UI-Router
preserveWhitespaces } is set to false potentially superfluous whitespace ... removed (trimmed);; text nodes consisting of whitespaces only are removed (ex.
Read more >
DOMDocument - Manual - PHP
Last child element or null . preserveWhiteSpace. Do not remove redundant white space. Default to true . Setting this to false has the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found