Skip to content

Commit

Permalink
fix: ImageViewer crashes when render are too fast
Browse files Browse the repository at this point in the history
The problem has been encountered when updating a page is too fast for example with an useQuery. Each time thee ImageViewer is unmounted, we also teardown all the gestures. The imageViewer crashes because the Gesture object have not yet been defined. This fix checks if Gesture exists before calling any functions on it
  • Loading branch information
cballevre committed Feb 22, 2023
1 parent 49d0fda commit c9e7698
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions react/Viewer/ViewersByFile/ImageViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ class ImageViewer extends Component {
}

tearDownGestures() {
this.gestures.off('swipe')
this.gestures.on('swipe', this.props.onSwipe)
this.gestures.off('panstart')
this.gestures.off('pinchstart')
this.gestures.off('pinchend')
this.gestures.off('pan')
this.gestures.off('pinch')
this.gestures.off('panend')
if (this.gestures) {
this.gestures.off('swipe')
this.gestures.on('swipe', this.props.onSwipe)
this.gestures.off('panstart')
this.gestures.off('pinchstart')
this.gestures.off('pinchend')
this.gestures.off('pan')
this.gestures.off('pinch')
this.gestures.off('panend')
}
}

onSwipe = e => {
Expand Down

0 comments on commit c9e7698

Please sign in to comment.