-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Nested <noscript> renders invalid HTML #6204
Comments
Thank you for reporting! This appears to be fixed in 15.0: http://codepen.io/anon/pen/ONMeor?editors=1010. To me, this does not look like a high-priority issue so I would suggest to work around it by using an empty |
Confirmed, fixed: http://jsfiddle.net/smw2cLe1/ |
This may be a dumb question, but…what does "fixed" mean? i.e., I'm of the opinion that the expected output for the static markup for the component const c = (
<noscript>
<span />
<noscript>
<div />
</noscript>
<p>sneaky</p>
</noscript>
); should be <noscript>
<span></span>
<div></div>
<p>sneaky</p>
</noscript> with all nested <noscript>
<span></span>
<noscript>
<div></div>
</noscript>
<p>sneaky</p>
</noscript> is incorrect because the first (indented) The argument for this is that it enables local reasoning about code. Otherwise, I have to audit any components that might appear in any noscript I create, and make sure that they themselves don't have noscripts, and also that my component will never appear in a noscript, or the whole app would break. It seems like a no-brainer to me that it should be React's job to handle this, not the author's. Under this definition of "fixed," the code is not fixed as of 15.3.1: $ babel-node
> const ReactDOMServer = require("react-dom/server");
'use strict'
> const React = require("react");
'use strict'
> const c = <noscript><span /><noscript><div /></noscript><p>sneaky</p></noscript>;
'use strict'
> ReactDOMServer.renderToStaticMarkup(c);
'<noscript><span></span><noscript><div></div></noscript><p>sneaky</p></noscript>'
> ReactDOMServer.renderToString(c);
'<noscript data-reactroot="" data-reactid="1" data-react-checksum="1778990683"><span data-reactid="2"></span><noscript data-reactid="3"><div data-reactid="4"></div></noscript><p data-reactid="5">sneaky</p></noscript>'
> (The fiddles above also demonstrate this IMO-incorrect behavior, which is why I was confused that this is marked "fixed.") |
Shouldn't this warn like other invalid nesting situations? |
Given that no one else has chimed in…in my opinion, no, this should not warn like other invalid nesting situations. In my understanding (please correct if wrong), the current invalid nesting situations happen when you forget a On the other hand, nesting Yes, in HTML it is invalid to treat nested |
No, in HTML the browser changes the parse tree when it encounters certain types of invalid nesting which causes React to get confused at nodes in the wrong place. It sounds like the precise mechanics of how noscript parsing works are slightly different, but it would have the same effect of messing the hierarchy up. |
@spicyj: Okay—that makes sense that the parse tree changing confuses React. But if React never emits nested |
Maybe. I could go either way. It could also be surprising to ask to render a I am happy to make validateDOMNesting warn about nested noscripts if it doesn't already – send a PR? |
While it doesn't really make sense to nest
<noscript />
, there are instances where it can happen unintentionally: mui/material-ui#3586In this case, React renders invalid HTML: http://codepen.io/anon/pen/BKjVpZ?editors=1010
In a setup with HMR, this ends up causing invariant violations. It might be worth adding a warning for this case.
React Version: 0.14.7 (should be fixed in 15.0 due to the changes to
<noscript />
)The text was updated successfully, but these errors were encountered: