question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

noscript contents cause invariant violation

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
BabakMNcommented, Sep 11, 2016

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

import React from 'react';
import ReactDOM from 'react-dom/server';


export default function Noscript(props) {

    // https://github.com/facebook/react/issues/1252

    const staticMarkup = ReactDOM.renderToStaticMarkup(
        props.children
    );

    return <noscript dangerouslySetInnerHTML={{ __html: staticMarkup }} />;

}

Usage:

import Noscript from './Noscript.js';
<Noscript>
   <div className="noJavascript">
      <div>
         <p>
         Your browser has disabled Javascript. Please note this website requires Javsacript to function correctly.
         </p>
      </div>
   </div>
</Noscript>
1reaction
matthewwithanmcommented, Mar 26, 2014

Now that we have renderComponentToStaticMarkup, maybe the best solution for this is just to do:

<noscript dangerouslySetInnerHTML={{__html: React.renderComponentToStaticMarkup(c)}} />

where c is the component you want to render for people without JS.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught Error: Invariant Violation: findComponentRoot ...
$110): Unable to find element. This probably means the DOM was unexpectedly mutated.
Read more >
The Noscript element - HTML: HyperText Markup Language
Permitted content, When scripting is disabled and when it is a descendant of the <head> element: in any order, zero or more <link>...
Read more >
main.18b409e1.js.map - Google Git
n\n var error = new Error(message);\n error.name = 'Invariant Violation';\n error.framesToPop = 1; // we don't care about reactProdInvariant's own frame\n\n ...
Read more >
React Error: Target Container is not a DOM Element-Reactjs
This error comes when the Javascript that tries to render the React component is included before the static parent dom element in the...
Read more >
HTML Standard
Table of contents. 1 Introduction; 2 Common infrastructure; 3 Semantics, structure, and APIs of HTML documents; 4 The elements of HTML; 5 Microdata ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found