From 17c1145ee4a99915ae8fdec80da4b333f8d95620 Mon Sep 17 00:00:00 2001 From: Bruce Martin Date: Thu, 16 Jul 2020 09:53:15 -0700 Subject: [PATCH] protect against reference detach (#1634) --- client/src/components/scatterplot/scatterplot.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/client/src/components/scatterplot/scatterplot.js b/client/src/components/scatterplot/scatterplot.js index 6943a5e9..d084faa0 100644 --- a/client/src/components/scatterplot/scatterplot.js +++ b/client/src/components/scatterplot/scatterplot.js @@ -59,6 +59,11 @@ class Scatterplot extends React.PureComponent { /* Must be created for each canvas */ + + // regl will create a top-level, full-screen canvas if we pass it a null. + // canvas should never be null, so protect against that. + if (!canvas) return {}; + // setup canvas, webgl draw function and camera const regl = _regl(canvas); const drawPoints = _drawPoints(regl); @@ -175,9 +180,12 @@ class Scatterplot extends React.PureComponent { setReglCanvas = (canvas) => { this.reglCanvas = canvas; - this.setState({ - ...Scatterplot.createReglState(canvas), - }); + if (canvas) { + // no need to update this state if we are detaching. + this.setState({ + ...Scatterplot.createReglState(canvas), + }); + } }; getViewportDimensions = () => {