-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Inconsistent JSX whitespace handling #22186
Comments
Hello! Just to share what the status of the Babel issue is, we are waiting from some input from React maintainers to check if there's any problem with the JSX spec and how to solve this problem on the spec side, so that every other implementation (i.e. the TypeScript one) is aligned to it and not to Babel specific implementation. |
Hi @LucaColonnello, is there an issue we can track on https://github.com/facebook/jsx/? That's probably the most appropriate venue for all JSX implementers/targets. |
Hey @DanielRosenwasser I didn’t open an issue yet. Thanks! :) |
This should be handled here Looking at the HTML spec, this is not entirely right https://www.w3.org/TR/html4/appendix/notes.html#notes-line-breaks |
I've read the Babel and JSX issues on this and the JSX authors are clear that this is the intended behavior. |
This is cross-post of babel#7360, which the maintainers of the JSX babel transform haven't commented on yet - I'm cross-posting the issue here, because the Typescript implementation is consistent with the Babel JSX transform, likely because it (or it's test suite) was referenced by the Typescript team (?)
I'm hoping that the Typescript team will be more attentive and perhaps we can push for this issue to get resolved, so that the behavior is consistent between Babel and Typescript.
It appears the whitespace handling of the JSX transform is inconsistent.
For example:
The two
<code>
tags in this example end up rendering differently - it appears the line-break before the word "other" on the first line gets discarded, while the actual spaces before/after the first code-tag, and after the second one, do get rendered.This currently forces me to make sure I never start an inline tag at the beginning of a line of text.
Here's the output of a fiddle to illustrate why whitespace is important to HTML rendering in this case:
Here's a fiddle demonstrating the transform problem.
And here's
console.log()
output from that fiddle illustrating the problem:While this behavior may be consistent with XML whitespace handling, it's a real problem when you're trying to render HTML where inline whitespace means something.
HTML, as far as I know, collapses whitespace-only sequences, and collapses leading/trailing serial whitespace to a single whitespace.
I also tested this with Typescript, and it does look like it's transform is identical to babel's:
Since the 99% use-case for JSX is rendering HTML, I'd like to suggest that both babel and Typescript ought to be consistent with HTML on this point.
The text was updated successfully, but these errors were encountered: