You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
appear differently if used in an HTML file and rendered (the first one has spaces around the foo part of its text, the second doesn't), Iβ―would expect the emitted code to be different also.
I can of course force spaces in the emitted code by using {" foo" } instead of foo, but that is somewhat contrived and make it harder to simply copy/paste HTML code into a JSX element.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
The current behavior is correct. The JSX specification does not trim whitespace in the same manner that HTML does; it's much more aggressive. You can often copy true HTML and paste it as JSX and get something that is pretty close to correct, but it's not guaranteed to be identical in behavior and this is one instance where they differ.
This matches all other JSX-for-React implementations. If you have a JSX variant that cares about leading whitespace, you'll need to use jsx: "preserve" and downlevel it using a variant-specific transpiler.
π Search Terms
Typescript JSX trimming text
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?jsx=4&ts=5.3.3#code/MYewdgzgLgBAZiEMC8MAUAoGMA8AjAVyinAD4ttcIAHAQzFIBsQAnAUwFscB6G+8yvEQVsOPgwCW1CAS686DCj0LEyGAJQBuDBlCRYeWixTolKkosFiFTVpx7jSCENf5SZcx0u7m1WoA
π» Code
π Actual behavior
With
"jsx": "react-jsx"
, both variables get emitted in the.js
file as:Notably, the
"foo"
part is identical.Similar behaviour happens for
react-jsxdev
andreact
(other emitters do not actually change the JSX).π Expected behavior
Given that the two HTML elements:
appear differently if used in an HTML file and rendered (the first one has spaces around the
foo
part of its text, the second doesn't), Iβ―would expect the emitted code to be different also.I can of course force spaces in the emitted code by using
{" foo" }
instead offoo
, but that is somewhat contrived and make it harder to simply copy/paste HTML code into a JSX element.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: