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
{{ message }}
Repository navigation
Document parsing of (X)HTML entities, or drop it even? #4
We should probably document how (X)HTML entities are parsed.
However, I can imagine dropping HTML entities instead and adopt the escaping used by JS-strings, i.e. bla \< \{ \u1234 bla. To me it would make sense in many ways:
JSX is the JavaScript-equivalent of HTML (it's not HTML), using JavaScript syntax seems preferable.
JSX explicitly disallows inline HTML in-favor of just JSXElements and JSXText, HTML entities seem a bit malplaced in that context.
It's currently <a href="&\" /> vs <a href={'&\\'} /> which is kind of awkward.
The downside of dropping HTML entities is obviously that you wouldn't be able to copy-paste HTML and it could be a mental disconnect for a lot of users. But I think it makes a lot of sense from a technical perspective.
I think it makes even more sense if you look beyond HTML. Why would you be using HTML entities for non-HTML frontends? Like iOS, QT, etc.
The downside of dropping HTML entities is obviously that you wouldn't be able to copy-paste HTML and it could be a mental disconnect for a lot of users. But I think it makes a lot of sense from a technical perspective.
Third, our thinking is that JSX's primary advantage is the symmetry of matching closing tags which make code easier to read, not the direct resemblance to HTML or XML. It's convenient to copy/paste HTML directly, but other minor differences (in self-closing tags, for example) make this a losing battle and we have a HTML to JSX converter to help you anyway. Finally, to translate HTML to idiomatic React code, a fair amount of work is usually involved in breaking up the markup into components that make sense, so changing class to className is only a small part of that anyway.
Well, I am biased. I want JSX to allow template strings in JSXAttributeValue. The fate of that issue depends on whether HTML entity support is dropped or not. This is another consideration to have when deciding on this.
That is true. But consistency/conventions lower bug count (sorry, no reference for this stats). Assuming that is true, then if the rest of the code base is using convention X (template string in this case), it would make sense if JSX supported that too.
That arguments has two sides - on one hand, you're increasing consistency for those who work with JS for developing logic, an on another you at the same time decrease consistency and familiarity for those who develop views (HTML/XML coders).
@sebmarkbage I'd say #28 is a candidate for otherwise keeping JSX as it is and being able to drop XHTML entities.
That arguments has two sides - on one hand, you're increasing consistency for those who work with JS for developing logic, an on another you at the same time decrease consistency and familiarity for those who develop views (HTML/XML coders).
IMHO the problem is that it is inconsistent, it would be fine if <a href=" " /> was the same as <a href={" "} />, which it isn't... to be honest I'm quite sure that many don't even realize this difference exists.
Oh right. I've actually broken backslashes in JSX attributes before in Babel and it took over 7 days for someone to notice and file an issue: babel/babel#2114.
I believe that entities (or other specific things) should be handled by the renderer which transforms JSX-output to HTML DOM/HTML string, but not by the transformer which transforms JSX to JSX-output.
@NekR It would then apply to all strings equally so even user input would be subject to HTML entity decoding (aside from it being a runtime cost too), you definitely do not want that.
...by the renderer which transforms JSX-output to HTML DOM/HTML string...
@NekR I interpreted that differently. IMHO what you are proposing is runtime decoding (which is for everyone to decide on their own) and outside this discussion about entities/escape codes in JSX source code. EDIT: That is to say, JSX needs to support escaping to some extent (like { and <), regardless of whether or not JSX will drop support for HTML entities.
Yes, I meanе that renderers are responsible for parsing entities. One could support EntitiesString, other don't.
. IMHO what you are proposing is runtime decoding (which is for everyone to decide on their own) and outside this discussion about entities/escape codes in JSX source code.
Of course I do not propose such decoding method here for JSX, it's implementation detail of JSX consumers. What I am saying is that entities parsing on a transpilation stage is not needed (because of runtime possibilities) and hence it's in scope of this discussion, right?
EDIT: That is to say, JSX needs to support escaping to some extent (like { and <), regardless of whether or not JSX will drop support for HTML entities.
What I am saying is that entities parsing on a transpilation stage is not needed (because of runtime possibilities) and hence it's in scope of this discussion, right?
IMHO no, entity parsing during transpilation and runtime decoding of entities are "complementary". Runtime decoding of static source code strings in this context is inefficient and cumbersome.
Produces React.createElement('div', null, '{test}', '<div>') and yeah it will visually render the same as it would if you had {'{test}<div>'}, but it's not the same. So yes, you can work around the problem that way (but you're inserting a JS string, not escaping in JSX). However, this all-or-nothing if you don't want to affect runtime behavior is really inconvenient, especially considering <div>{' '}</div> is very different from <div> </div> at current.
IMHO no, entity parsing during transpilation and runtime decoding of entities are "complementary". Runtime decoding of static source code strings in this context is inefficient and cumbersome.
Sorry, but topic is "Document parsing of (X)HTML entities, or drop it even?" and I am saying: Drop it. How it's not related? Runtime parsing was suggested as a solution. Some one who do not want runtime solution could write plugin which will pre-parse entities to JS escapes or something like that. But you are not even listening to me. What I am saying is that it makes sense to have JSXText to equal to simple JS string (sugar). Like these two should be equivalent: <div> </div> and <div>{' '}</div>.
Runtime decoding of static source code strings in this context is inefficient and cumbersome.
This is only problem of React since it's doing re-render on every move. I use JSX in a different way and it's perfectly fine for me.
So yes, you can work around the problem that way (but you're inserting a JS string, not escaping in JSX). However, this all-or-nothing if you don't want to affect runtime behavior is really inconvenient, especially considering <div>{' '}</div> is very different from <div> </div> at current.
Why we need to do work arounds or escape JSX? Just have JS string everywhere. I do not see any difference here except that transpiration entities parsing is benefit for React.
P.S. Interesting that you made this repository public and asked for feedback from non-React implementations and when people came here with their opinions, you say: "This is not related". Just make it private repository and then no problem with "not related".
P.S. Interesting that you made this repository public and asked for feedback from non-React implementations and when people came here with their opinions, you say: "This is not related". Just make it private repository and then no problem with "not related".
@NekR I'm only one collaborator of many, these are my opinions. Feel free to refute them, but there are many things to consider. If I didn't care about your opinion I wouldn't have responded.
Sorry, but topic is "Document parsing of (X)HTML entities, or drop it even?" and I am saying: Drop it. How it's not related? Runtime parsing was suggested as a solution.
Decoding at compile-time (source code and static strings) and run-time (dynamic strings) can both co-exist and make sense. In the context of language design, run-time decoding being possible is not an argument against a syntax feature, nor vice versa. They are solutions to different problems.
Yes, we both agree that HTML entities should be dropped, that's not what I objected to. I undoubtedly think that is the way forward, but the holes left behind by dropping HTML entities still needs to be considered, runtime decoding is not it.
Activity
gajus commentedon Sep 2, 2015
React has already chose to deviate from HTML. react/react#2781
and
from @spicyj answer https://www.quora.com/Why-do-I-have-to-use-className-instead-of-class-in-ReactJs-components-done-in-JSX/answer/Ben-Alpert
Therefore, I am in favour of dropping HTML entity support.
RReverser commentedon Sep 2, 2015
@gajus From HTML - yes, from XML - not so much (apart from JS injections).
gajus commentedon Sep 2, 2015
Well, I am biased. I want JSX to allow template strings in JSXAttributeValue. The fate of that issue depends on whether HTML entity support is dropped or not. This is another consideration to have when deciding on this.
RReverser commentedon Sep 2, 2015
Do those two braces around really mean that much to you to change two behaviors? 😄
gajus commentedon Sep 2, 2015
One is HTML entities. Whats the second?
RReverser commentedon Sep 2, 2015
Template strings without braces on their own.
gajus commentedon Sep 2, 2015
I think that since JSX is present in JS and that it is in essence a syntactic sugar for
createElement, then it should behave in the same way, i.e.,should not be different from
RReverser commentedon Sep 2, 2015
Then we return to questions like numeric literals, object and array literals and so.
gajus commentedon Sep 2, 2015
@RReverser Explain?
If I understand correctly, then yes, objects, strings,
nulland numbers (thats all there is) should be valid attribute values.Does this clash with anything in the spec?
RReverser commentedon Sep 2, 2015
It doesn't clash, but increases complexity for purely aesthetic reason.
gajus commentedon Sep 2, 2015
That is true. But consistency/conventions lower bug count (sorry, no reference for this stats). Assuming that is true, then if the rest of the code base is using convention X (template string in this case), it would make sense if JSX supported that too.
RReverser commentedon Sep 3, 2015
That arguments has two sides - on one hand, you're increasing consistency for those who work with JS for developing logic, an on another you at the same time decrease consistency and familiarity for those who develop views (HTML/XML coders).
sebmarkbage commentedon Sep 3, 2015
I think that it probably only makes sense to do this if we also drop it from JSXText or drop JSXText completely, as described in #8 and #35 .
syranide commentedon Sep 3, 2015
@sebmarkbage I'd say #28 is a candidate for otherwise keeping JSX as it is and being able to drop XHTML entities.
IMHO the problem is that it is inconsistent, it would be fine if
<a href=" " />was the same as<a href={" "} />, which it isn't... to be honest I'm quite sure that many don't even realize this difference exists.16 remaining items
sebmarkbage commentedon Sep 25, 2015
Or backslashes...
sebmck commentedon Sep 25, 2015
Oh right. I've actually broken backslashes in JSX attributes before in Babel and it took over 7 days for someone to notice and file an issue: babel/babel#2114.
NekR commentedon Sep 25, 2015
I believe that entities (or other specific things) should be handled by the renderer which transforms JSX-output to HTML DOM/HTML string, but not by the transformer which transforms JSX to JSX-output.
syranide commentedon Sep 25, 2015
@NekR It would then apply to all strings equally so even user input would be subject to HTML entity decoding (aside from it being a runtime cost too), you definitely do not want that.
NekR commentedon Sep 25, 2015
@syranide what is user input in JSX? I did not say everything in runtime should be parsed with entities.
syranide commentedon Sep 25, 2015
@NekR I interpreted that differently. IMHO what you are proposing is runtime decoding (which is for everyone to decide on their own) and outside this discussion about entities/escape codes in JSX source code. EDIT: That is to say, JSX needs to support escaping to some extent (like
{and<), regardless of whether or not JSX will drop support for HTML entities.NekR commentedon Sep 25, 2015
Yes, I meanе that renderers are responsible for parsing entities. One could support
EntitiesString, other don't.Of course I do not propose such decoding method here for JSX, it's implementation detail of JSX consumers. What I am saying is that entities parsing on a transpilation stage is not needed (because of runtime possibilities) and hence it's in scope of this discussion, right?
Hmm..
<div>{ '{test}' } { '<div>' }</div>seems like it's escaped?syranide commentedon Sep 25, 2015
IMHO no, entity parsing during transpilation and runtime decoding of entities are "complementary". Runtime decoding of static source code strings in this context is inefficient and cumbersome.
Produces
React.createElement('div', null, '{test}', '<div>')and yeah it will visually render the same as it would if you had{'{test}<div>'}, but it's not the same. So yes, you can work around the problem that way (but you're inserting a JS string, not escaping in JSX). However, this all-or-nothing if you don't want to affect runtime behavior is really inconvenient, especially considering<div>{' '}</div>is very different from<div> </div>at current.NekR commentedon Sep 25, 2015
Sorry, but topic is "Document parsing of (X)HTML entities, or drop it even?" and I am saying: Drop it. How it's not related? Runtime parsing was suggested as a solution. Some one who do not want runtime solution could write plugin which will pre-parse entities to JS escapes or something like that. But you are not even listening to me. What I am saying is that it makes sense to have
JSXTextto equal to simple JS string (sugar). Like these two should be equivalent:<div> </div>and<div>{' '}</div>.This is only problem of React since it's doing re-render on every move. I use JSX in a different way and it's perfectly fine for me.
Why we need to do work arounds or escape JSX? Just have JS string everywhere. I do not see any difference here except that transpiration entities parsing is benefit for React.
P.S. Interesting that you made this repository public and asked for feedback from non-React implementations and when people came here with their opinions, you say: "This is not related". Just make it private repository and then no problem with "not related".
syranide commentedon Sep 25, 2015
@NekR I'm only one collaborator of many, these are my opinions. Feel free to refute them, but there are many things to consider. If I didn't care about your opinion I wouldn't have responded.
Decoding at compile-time (source code and static strings) and run-time (dynamic strings) can both co-exist and make sense. In the context of language design, run-time decoding being possible is not an argument against a syntax feature, nor vice versa. They are solutions to different problems.
Yes, we both agree that HTML entities should be dropped, that's not what I objected to. I undoubtedly think that is the way forward, but the holes left behind by dropping HTML entities still needs to be considered, runtime decoding is not it.
NekR commentedon Sep 25, 2015
I saw many such arguments and decisions in TC-39, but okay, you do not accepts this as argument then nevermind.
Why? Where is a big performance problem with it except of React contact re-render?
dantman commentedon Jan 5, 2016
Personally I don't think the DX argument is valid. And that is not through an expectation of everyone using character maps, etc...
JSX is JavaScript and it doesn't really make sense that the solution when writing JS+JSX to "I can't type © with my keyboard" is "You can use
©in JSX strings but you're SOL in every other part of the JS". Which of course leads to a mess like:Same code. But you can use
©in one part of the JSX and you can't in the other because you have something – which doesn't have to be i18n, it can be collection processing or anything else – that requires that one of the strings be part of JS space and not JSX space.If this is a problem, it is a problem universal to JS and not one that should have a JSX-only fix.
Rather I think the solution is to embrace the fact we're writing JS and fix this with JS. Specifically, given #25 I think the solution to "I can't type © with my keyboard and don't want to use a character map, C&P, or use some other tooling" is this.
[Normative] Capture the HTML entity behaviors (#136)