-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Hug JSX text after multi line tags #1671
Conversation
. | ||
this collection and the list it contained on <b> | ||
{humanDate(since)} | ||
</b>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like an edge case with the current implementation. When we have tag that would just fit on a line and it is followed by text it causes this unusual formatting.
I imagine in this case we would be aiming for:
this collection and the list it contained on
<b>
{humanDate(since)}
</b>.
I haven't had a chance to investigate why this is happening yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR looks great to me. Do you feel this is a blocker? I don't. We could always improve things in another PR.
Btw, I this would be a pretty nice formatting:
this collection and the list it contained on
{" "}<b>{humanDate(since)}</b>.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I don't really care about this.
src/printer.js
Outdated
// tags and text. | ||
// Unfortunately Facebook have a custom translation pipeline | ||
// (https://github.com/prettier/prettier/issues/1581#issuecomment-300975032) | ||
// that uses the JSX syntax, but does not follow the JSX whitespace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call this "the React whitespace rules" since JSX does not seem to have whitespace rules.
Thanks so much for working on this! Could you also ensure that it works before as well? <div>Elements Elements Elements Elements Elements Elements Elements Elements (<span>{count}</span>) Elements Elements Elements</div> currently outputs <div>
Elements Elements Elements Elements Elements Elements Elements Elements (
<span>{count}</span>) Elements Elements Elements
</div>; which would add a space between |
008550e
to
c38ff4f
Compare
252be5b
to
3872b24
Compare
I've pushed a quick change which hugs text to the beginning of tags as well. Although there are some degenerative cases where you can end up with a line that never gets split. Input:
Output:
I'll investigate what we might be able to do to fix this. |
Do people write this in practice? |
Yep, totally agree that the degenerative case shouldn't block merging this! |
@lydell mind reviewing this PR? |
@lydell I believe it should be theoretically possible to split it by doing something like:
|
Just found a case where it's not stable the first time if you are interested. I don't think it's a big deal and it's okay if it's not fixed, but you may be interested. <div className="yourScore">
Your score: <span className="score">{`${mini.crosstable.users[sessionUserId]} - ${mini.crosstable.users[user.id]}`}</span>
</div> <div className="yourScore">
Your score:
{" "}
<span className="score">{`${mini.crosstable.users[sessionUserId]} - ${mini
.crosstable.users[user.id]}`}</span>
</div>; <div className="yourScore">
Your score:
{" "}
<span className="score">{`${mini.crosstable.users[sessionUserId]} - ${mini.crosstable.users[user.id]}`}</span>
</div>; |
@vjeux I've created an issue for the unstable formatting and added it to my TODO list. |
A fix for #1581
This PR no longer allows a line break between tags and text in JSX. This fixes an issue that was blocking adoption at Facebook (#1581 (comment)) with little adverse effects for our standard formatting.