react: noscript contents cause invariant violation
When using server rendering, putting an <img>
in a <noscript>
seems to invariably cause an invariant violation (it can’t find the image).
I believe this is because, to the JS enabled browser, the noscript content looks like CDATA.
This can be worked around by using dangerouslySetInnerHTML
to actually set the contents to an HTML string, however, you can’t nest components with this approach.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 18 (8 by maintainers)
Commits related to this issue
- Serialize children of noscript tags; fixes GH-1252 — committed to matthewwithanm/react by matthewwithanm 10 years ago
I think this issue should be highlighted somewhere on the documentation.
The following seems to work well for me both on client and server (thanks to people above):
Noscript.js
Usage:
Now that we have
renderComponentToStaticMarkup
, maybe the best solution for this is just to do:where
c
is the component you want to render for people without JS.