Skip to content

Commit 991a348

Browse files
Destroy old root model on pluginManager reload (#5140)
1 parent f605caf commit 991a348

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

products/jbrowse-web/src/components/Loader.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Suspense, lazy, useEffect, useState } from 'react'
33
import { FatalErrorDialog } from '@jbrowse/core/ui'
44
import { ErrorBoundary } from '@jbrowse/core/ui/ErrorBoundary'
55
import { observer } from 'mobx-react'
6+
import { destroy } from 'mobx-state-tree'
67
import {
78
QueryParamProvider,
89
StringParam,
@@ -128,7 +129,12 @@ const Renderer = observer(function ({
128129

129130
try {
130131
if (ready) {
131-
setPluginManager(createPluginManager(loader, reloadPluginManager))
132+
setPluginManager(previousPluginManager => {
133+
if (previousPluginManager?.rootModel) {
134+
destroy(previousPluginManager.rootModel)
135+
}
136+
return createPluginManager(loader, reloadPluginManager)
137+
})
132138
}
133139
} catch (e) {
134140
console.error(e)

products/jbrowse-web/src/tests/Loader.test.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { FatalErrorDialog } from '@jbrowse/core/ui'
2+
import { ErrorBoundary } from '@jbrowse/core/ui/ErrorBoundary'
13
import { render, waitFor } from '@testing-library/react'
24
import { Image, createCanvas } from 'canvas'
35
import { LocalFile } from 'generic-filehandle2'
@@ -116,7 +118,17 @@ test('can use config from a url with nonexistent share param ', async () => {
116118

117119
test('can catch error from loading a bad config', async () => {
118120
const { findAllByText } = render(
119-
<App search="?config=test_data/bad_config_test/config.json" />,
121+
<ErrorBoundary
122+
FallbackComponent={props => (
123+
<FatalErrorDialog
124+
{...props}
125+
resetButtonText="Reset Session"
126+
onFactoryReset={() => {}}
127+
/>
128+
)}
129+
>
130+
<App search="?config=test_data/bad_config_test/config.json" />
131+
</ErrorBoundary>,
120132
)
121133
await findAllByText(/Error while converting/)
122134
}, 20000)

0 commit comments

Comments
 (0)