ReactDOMServer.renderToString: presence of onClick handler causes errors on async update
See original GitHub issueThe 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:
- Created 8 years ago
- Comments:12 (7 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I found a way to use
ReactNoopUpdateQueue
inReactServerRenderingTransaction
. That way we can do as @spicyj advised. I send you a PR as soon as possible, maybe tonight, maybe tomorrow!Answering my own question: maybe during initial mount, don’t use (yet) the ReactNoopUpdateQueue.