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.

ReactDOMServer.renderToString: presence of onClick handler causes errors on async update

See original GitHub issue

The code

class Comp extends React.Component {
  componentWillMount() {
    setTimeout(() => {
      this.setState({});
    });
  }

  render() {
    return <div onClick={() => {}} />;
  }
}

ReactDOMServer.renderToString(<Comp />);

produces errors:

Warning: React can’t find the root component node for data-reactid value .0. If you’re seeing this message, it probably means that you’ve loaded two copies of React on the page. At this time, only a single copy of React can be loaded at a time.

Uncaught TypeError: Cannot read property ‘firstChild’ of undefined

But if I remove onClick handler the errors go away…

See demo: http://codepen.io/dened/pen/YyByYr

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rricardcommented, Jun 26, 2016

I think I found a way to use ReactNoopUpdateQueue in ReactServerRenderingTransaction. That way we can do as @spicyj advised. I send you a PR as soon as possible, maybe tonight, maybe tomorrow!

0reactions
rricardcommented, Jun 27, 2016

Answering my own question: maybe during initial mount, don’t use (yet) the ReactNoopUpdateQueue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

onClick handler not registering with ReactDOMServer ...
React DOM render to string only sends the initial HTML as a string without any JS. ... React.js Serverside rendering and Event Handlers....
Read more >
react-test-renderer | Yarn - Package Manager
Design simple views for each state in your application, and React will efficiently update and render just the right components when your data...
Read more >
Functional Web Development with React and Redux
onclick handler that creates an alert box to display the index. Declaring i in the for loop creates a global variable named i,...
Read more >
The React Handbook – Learn React for Beginners
The React Handbook follows the 80/20 rule: learn in 20% of the time the 80% of a topic. I find this approach gives...
Read more >
Events - Qwik - Builder.io
In the above example, the onClick$ attribute of the <button> element is used ... Because of the async nature of Qwik, an event's...
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