-
Notifications
You must be signed in to change notification settings - Fork 47.6k
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
Noscript tags no longer rendering components in 16.5.0 #15238
Comments
This change was intentional I think: #11423. As a workaround, maybe this works for you? <noscript
dangerouslySetInnerHTML={{
__html: '<a href="page">link</a>'
}}
/> ? |
@gaearon thanks for the response! Unfortunately in my use case Consider the code:
Prior to 16.4.3, this worked fine: the HTML generated by React included the links in the I read #11423 in more detail and it does seem like a pretty complicated issue. I can see why that solution was preferred. I do have two points to add:
|
I just noticed this issue and as the one who caused it I would like to chip in, first of all, sorry for the trouble. 😄 I don't think anyone (at least not me), were considering prerenderers in #11423 which is unfortunate, breaking this use case should of course have been an intentional choice rather than an unintentional side effect. That said, I do still think the fix is a correct one. Using JS to create markup that will never be used in the current environment seems wasteful to the vast majority of targets that run this code. The If you need to put the result of a rendered component into a All this said, if this use case is strong enough it should be possible to introduce a special prop on |
I've been struggling with this aswell, but we have a slightly different usecase. Our project leverages noscript for server markup intended for SEO crawlers. Then after the app is running clientside we use react-intersection-observer to infill the DOM. This preserves crawlability for some less advanced search engines and markedly improves Lighthouse's excessive DOM depth scores. I'm not an SEO expert by any stretch so the above might be overkill but I do think this is fairly standard practice? |
@designreact Without knowing your exact usecase that sounds.. Complex. I'm not sure exactly what you are doing, but it sounds like the noscript-part of that should work since it's generating the content serverside with So just to clear up any confusion, I'll try to summarize how this should work today (though I haven't tested in a while): function NoscriptFallback() {
return 'I will be shown only when JS is disabled';
}
function Component() {
return (
<noscript>
<NoscriptFallback />
</noscript>
);
} Server The above code should work as intended when running on the server with Hydration If you do Client only If you do TL;DR: Content gets generated inside of |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Starting in version 16.4.3, the following code:
is being rendered in the browser as:
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
Prior to 16.4.3: https://codesandbox.io/embed/5mww4nzpwp
After 16.4.3: https://codesandbox.io/embed/6v8m4yo303
(The changes are not visible, but if you
inspect element
you can see that, in the first example, the links are being rendered, and in the second example they're not being rendered.)What is the expected behavior?
It should render in the browser the same as in the code:
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
See above, it was working in versions prior to 16.4.3. (I couldn't find a previous issue mentioning this bug. I think it could have been introduced in the fix for #11423)
Why is this a problem?
I use a snapshot tool with React to generate a set of static pages from a React project. These pages have less functionality than the full application, but they allow webcrawlers and users who have disabled JavaScript to use the site at a basic level. For example, the code might look like this:
Preventing components in
<noscript>
tags from rendering breaks this functionality for users with JavaScript disabled. The generated snapshots no longer contain the links. It also makes the site harder to navigate by webcrawlers, even if they have JavaScript enabled, because they have to be smart enough to use the fancy button instead of following the link.The text was updated successfully, but these errors were encountered: