New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular parser should not treat table data cells like block elements. #5452
Comments
cc @ikatyang |
I tried it on Chrome and it seems the whitespaces are insensitive there, could you share more info? or did you change their <table>
<tr>
<td class="somethingReallyReallyLong" data-test="somethingElse">111</td>
<td class="somethingReallyReallyLong" data-test="somethingElse">222</td>
</tr>
</table>
<table>
<tr>
<td class="somethingReallyReallyLong" data-test="somethingElse">
333
</td>
<td class="somethingReallyReallyLong" data-test="somethingElse">
444
</td>
</tr>
</table> |
See this Stackblitz sample. You're absolutely right, the whitespace isn't normally sensitive when rendered by the browser, but it is within the angular template parser - this results in extra spaces around the content. I've had to add some CSS to make it apparent (and I suspect this may be what made it apparent to my colleague who found the issue), but when our tests check for the contents of the Perhaps this is something that should be brought up with the Angular team instead? Still, if this is supposed to be working for Angular templates, perhaps it shouldn't break the way it currently does? |
@jdpearce I just saw your stackblitz. If I remove |
It's interesting at least the fact that it actually Angular display it differently as the Browser would, but I assume is an Angular issue (or maybe a feature). Am I missing something? Update: It's not a bug, it's a feature © |
Adding that bit of CSS was deliberate just to show that there's extra white space there. This is a problem when you're doing something like comparing Arguably, this may be the wrong thing to do, but examples of these kind of tests are all over the angular docs. I suspect something like |
Thanks for following up. So the issue in this case is that node.textContent is whitespace sensitive and therefore when the formatting changes, the value changes as well. This is not a specific issue with “td” and a different issue than the css whitespace property. For css whitespace, we have mitigations in place where we respect whitespace for tags and have a comment to disable it on a per-callsite if needed: The issue with this particular issue is that it’s unclear what nodes are going to be affected. We added a You can read more about the tradeoffs on the blog post: https://prettier.io/blog/2018/11/07/1.15.0.html This is a very difficult trade-off to make. We want to make prettier a drop-in that will not break anything. Unfortunately this isn’t as easy in html (and why we just released it). My instinct is that it’s unlikely going to break much in production but has the opportunity to break tests. Broken tests are annoying but if you convert your codebase at once, you can fix your tests at once and then you don’t have to think about it. |
Seems to be a duplicate of #5463: inserting white spaces around an interpolation breaks tests. |
On the side note, if some practice is all over the angular docs, it means nothing. A great example and a blog post about it. |
@thorn0 Absolutely agreed on your side note. My pointing that out was what not to suggest that it's good practice, simply that if it's perceived to be "how things are done" then a lot of people will end up coming across this issue. |
Duplicate of #5463 |
Prettier 1.15.2
Playground link
Input:
Output:
Expected behavior:
Something more like this :
The
td
tag should be treated the same way asspan
tags because white space is sensitive within atd
.The text was updated successfully, but these errors were encountered: