ReactJS renders multiple ThreeJS canvases on save

To resolve ReactJS rendering an additional canvas every time a hot reload takes place, remove the renderer from the scenes ref when the component unmounts.

Oscar de la Hera Gomez
Written by Oscar de la Hera Gomez
First published on 11/06/2023 at 09:55
Last Updated on 11/10/2023 at 23:26
<p>Two flowers that represent ReactJS and ThreeJS side by side. Beneath them sits the text "ReactJS &amp; ThreeJS Error: Multiple Canvases on Hot Reload."</p>

To resolve ReactJS rendering an additional canvas every time a hot reload takes place, remove the renderer from the scenes ref when the component unmounts.

SubscribeDownload Open Source Starter Project

The solution for this issue can be found in our Open Source React-Redux Starter Project on the tutorial/three-js/starter branch.

git clone git@github.com:delasign/react-redux-starter-project.git
View Repository
<p>A screenshot of Chrome highliting how an extra canvas have been added to the website after making a code change when we intended for only one to remain present.</p>

An example of ReactJS rendering an additional after a code change.

The error that this article covers is how to make sure that ReactJS does not render an additional canvas every time a change is made to a ReactJS file.

To resolve this, make sure that you remove the renderer from the ref of the scene.

Looking to learn more about ReactJS and ThreeJS ?

Search our blog to find educational content on learning how to use ReactJS and ThreeJS.

Search our BlogReact, ThreeJS & GLSL Resources

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
SubscribeContact UsVisit our BlogView our ServicesView our Work

Partner with us

We would love to get to know you and see how we can help your organization with its goals and needs.
Let's Talk

Stay Informed

Get occasional updates about our company, research, and product launches.
Subscribe