Skip to content

Commit

Permalink
Fix crash on closing linearsynteny track
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Apr 2, 2021
1 parent 4a4ef79 commit 0cab769
Showing 1 changed file with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-continue */
import React, { useRef, useMemo, useEffect } from 'react'
import { observer } from 'mobx-react'
import { isAlive } from 'mobx-state-tree'
import SimpleFeature, {
SimpleFeatureSerialized,
Feature,
Expand Down Expand Up @@ -87,18 +88,25 @@ function LinearSyntenyRendering(props: {
[features],
)
const matches = layoutMatches(deserializedFeatures)
const views = useMemo(() => {
try {
const parentView =
'type' in displayModel
? (getContainingView(displayModel) as LinearSyntenyViewModel)
: undefined
return parentView?.views
} catch (e) {
console.warn('parent view gone')
return null
}
}, [displayModel])

const parentView =
'type' in displayModel
? (getContainingView(displayModel) as LinearSyntenyViewModel)
: undefined
const { views } = parentView || { views: undefined }
const offsets = views && views.map(view => view.offsetPx)
const offsets = views?.map(view => view.offsetPx)
useEffect(() => {
if (!(parentView && views && offsets)) {
if (!ref.current || !offsets || !views) {
return
}
if (!ref.current) {
if (!isAlive(displayModel)) {
return
}
const ctx = ref.current.getContext('2d')
Expand Down Expand Up @@ -217,7 +225,16 @@ function LinearSyntenyRendering(props: {
}
}
})
})
}, [
displayModel,
highResolutionScaling,
trackIds,
width,
views,
offsets,
height,
matches,
])

return (
<canvas
Expand Down

0 comments on commit 0cab769

Please sign in to comment.