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
Collapses spaces between words in JSX #1661
Comments
It looks like Babel also preserves spaces at the beginning and end of text: Input: x = <div> a b </div> Babel: "use strict";
x = React.createElement(
"div",
null,
" a b "
); |
This regression was probably caused by #1120 which splits JSX text across multiple lines. I'm not sure at the moment how to marry up preserving whitespace between words with allowing line breaks. It will need some investigation! |
I've tested preserving spaces at the beginning and end of text and both master and 1.3.1 fail to preserve the spaces. |
I've been thinking about this issue. Personally, I like the behavior on master. It forces people to be explicit if they want unusual spaces ( |
I feel exactly the same about this @lydell! I'm torn between personally preferring Prettier to collapse multiple spaces as part of it's formatting and the fact that doing so wouldn't be following the JSX spec. I've been playing around with how we might keep multiple spaces intact while still being able to reformat JSX and I think it should be possible. I don't have anything to show for it yet, but I think it should be possible in a way that follows the spec while keeping all the JSX formatting behaviour we currently have. The generally idea would be to convert multiple spaces to |
Current release of prettier changes the snapshots already. diff --git c/src/main/webapp/modules/safeTrade/seller/payment/statusDetails/handleCancelPurchaseDetails.jsx w/src/main/webapp/modules/safeTrade/seller/payment/statusDetails/handleCancelPurchaseDetails.jsx
index 99600568fc..e192d49230 100644
--- c/src/main/webapp/modules/safeTrade/seller/payment/statusDetails/handleCancelPurchaseDetails.jsx
+++ w/src/main/webapp/modules/safeTrade/seller/payment/statusDetails/handleCancelPurchaseDetails.jsx
@@ -12,7 +12,10 @@ const HandleCancelPurchaseDetails = ({ agreement, partner, handleClickCancelPurc
<div className="phl">
<div className="pbl">
<p>
- Hvis du hever kjøpet, bryter du en avtale du har inngått med {partner.name}, og FINN vil tilbakebetale hele beløpet
+ Hvis du hever kjøpet, bryter du en avtale du har inngått med
+ {' '}
+ {partner.name}
+ , og FINN vil tilbakebetale hele beløpet
til {partner.name}.
</p>
<p>
diff --git c/src/test/js/unit/test/safeTrade/seller/payment/statusDetails/__snapshots__/handleCancelPurchaseDetails-test.jsx.snap w/src/test/js/unit/test/safeTrade/seller/payment/statusDetails/__snapshots__/handleCancelPurchaseDetails-test.jsx.snap
index 832215844d..6d1923f3ae 100644
--- c/src/test/js/unit/test/safeTrade/seller/payment/statusDetails/__snapshots__/handleCancelPurchaseDetails-test.jsx.snap
+++ w/src/test/js/unit/test/safeTrade/seller/payment/statusDetails/__snapshots__/handleCancelPurchaseDetails-test.jsx.snap
@@ -45,7 +45,8 @@ exports[`HandleCancelPurchaseDetails renders correctly 1`] = `
className="pbl"
>
<p>
- Hvis du hever kjøpet, bryter du en avtale du har inngått med
+ Hvis du hever kjøpet, bryter du en avtale du har inngått med
+
Ole Brumm
, og FINN vil tilbakebetale hele beløpet til
Ole Brumm |
Good point, @SimenB! I guess there's no need to worry about that, then. |
Is this still an issue or has it been fixed? |
It has not been fixed. (If we want to fix it.) |
@vjeux @lydell The PR to allow JSX lines to be recombined has tweaked how we handle multiple space characters between words/tags/expressions. We now always collapse multiple spaces. This is officially against spec, but is means that Prettier now behaves consistently with respect to multiple spaces. If it is important for multiple spaces to be preserved then they need to be represented as an expression (e.g. Would we be happy to close this for now? We can re-open it if we find that the behaviour is causing real world problems. |
No one has complained about this for 3 months so it doesn’t seem to be an issue in practice. I’m going to close this issue and will be happy to re-open it if any issues crop up. |
Babel does not collapse spaces between words. Prettier 1.3.1 respects that, but latest master collapses it into 1 space.
Input:
Babel:
Prettier 1.3.1:
Prettier master (commit 6f0707a):
Extracted from #1658 (comment)
The text was updated successfully, but these errors were encountered: