Skip to content

Commit

Permalink
fix(web): prevent recoil error, by retaining snapshot for the duratio…
Browse files Browse the repository at this point in the history
…n of init
  • Loading branch information
ivan-aksamentov committed May 10, 2022
1 parent 0b085bc commit f500f98
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages_rs/nextclade-web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ export function RecoilStateInitializer() {

const [initialized, setInitialized] = useRecoilState(isInitializedAtom)

const initialize = useRecoilCallback(({ set, snapshot: { getPromise } }) => () => {
const initialize = useRecoilCallback(({ set, snapshot }) => () => {
if (initialized) {
return
}

const snapShotRelease = snapshot.retain()
const { getPromise } = snapshot

initializeDatasets(query)
.then(({ datasets, defaultDatasetName, defaultDatasetNameFriendly, currentDatasetName }) => {
set(datasetsAtom, {
Expand All @@ -104,6 +107,7 @@ export function RecoilStateInitializer() {
})
.then(() => {
setInitialized(true)
snapShotRelease()
})
.catch((error) => {
console.error(error)
Expand Down

0 comments on commit f500f98

Please sign in to comment.