@@ -64,8 +64,20 @@ export default function plotComponentFactory(Plotly) {
64
64
}
65
65
66
66
componentDidMount ( ) {
67
+ this . unmounting = false ;
68
+
67
69
this . p = this . p
68
70
. then ( ( ) => {
71
+ if ( ! this . el ) {
72
+ let error ;
73
+ if ( this . unmounting ) {
74
+ error = new Error ( 'Component is unmounting' ) ;
75
+ error . reason = 'unmounting' ;
76
+ } else {
77
+ error = new Error ( 'Missing element reference' ) ;
78
+ }
79
+ throw error ;
80
+ }
69
81
return Plotly . newPlot ( this . el , {
70
82
data : this . props . data ,
71
83
layout : this . props . layout ,
@@ -78,6 +90,9 @@ export default function plotComponentFactory(Plotly) {
78
90
. then ( this . attachUpdateEvents )
79
91
. then ( ( ) => this . figureCallback ( this . props . onInitialized ) )
80
92
. catch ( err => {
93
+ if ( err . reason === 'unmounting' ) {
94
+ return ;
95
+ }
81
96
console . error ( 'Error while plotting:' , err ) ; // eslint-disable-line no-console
82
97
if ( this . props . onError ) {
83
98
this . props . onError ( err ) ;
@@ -86,6 +101,8 @@ export default function plotComponentFactory(Plotly) {
86
101
}
87
102
88
103
componentWillUpdate ( nextProps ) {
104
+ this . unmounting = false ;
105
+
89
106
if ( nextProps . revision !== void 0 && nextProps . revision === this . props . revision ) {
90
107
// if revision is set and unchanged, do nothing
91
108
return ;
@@ -108,6 +125,16 @@ export default function plotComponentFactory(Plotly) {
108
125
109
126
this . p = this . p
110
127
. then ( ( ) => {
128
+ if ( ! this . el ) {
129
+ let error ;
130
+ if ( this . unmounting ) {
131
+ error = new Error ( 'Component is unmounting' ) ;
132
+ error . reason = 'unmounting' ;
133
+ } else {
134
+ error = new Error ( 'Missing element reference' ) ;
135
+ }
136
+ throw error ;
137
+ }
111
138
return Plotly . react ( this . el , {
112
139
data : nextProps . data ,
113
140
layout : nextProps . layout ,
@@ -119,6 +146,9 @@ export default function plotComponentFactory(Plotly) {
119
146
. then ( ( ) => this . syncWindowResize ( nextProps ) )
120
147
. then ( ( ) => this . figureCallback ( nextProps . onUpdate ) )
121
148
. catch ( err => {
149
+ if ( err . reason === 'unmounting' ) {
150
+ return ;
151
+ }
122
152
console . error ( 'Error while plotting:' , err ) ; // eslint-disable-line no-console
123
153
if ( this . props . onError ) {
124
154
this . props . onError ( err ) ;
@@ -127,6 +157,8 @@ export default function plotComponentFactory(Plotly) {
127
157
}
128
158
129
159
componentWillUnmount ( ) {
160
+ this . unmounting = true ;
161
+
130
162
this . figureCallback ( this . props . onPurge ) ;
131
163
132
164
if ( this . resizeHandler && isBrowser ) {
0 commit comments