Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,15 @@ const stateModelFactory = (configSchema: ApolloInternetAccountConfigModel) => {
}
// fires when app transitions from prerender, user returns to the app / tab.
if (document.visibilityState === 'visible') {
const { session } = getRoot<ApolloRootModel>(self)
session.broadcastLocations()
try {
const { session } = getRoot<ApolloRootModel>(self)
if (session && !session.isDestroyed) {
session.broadcastLocations()
}
} catch (error) {
// Silently handle the error to prevent crashes
console.warn('Failed to broadcast locations:', error)
}
}
})
}),
Expand Down
22 changes: 14 additions & 8 deletions packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,23 @@ export function clientDataStoreFactory(
return self.assemblies.put(assemblySnapshot)
},
addFeature(assemblyId: string, feature: AnnotationFeatureSnapshot) {
const assembly = self.assemblies.get(assemblyId)
let assembly = self.assemblies.get(assemblyId)
if (!assembly) {
throw new Error(
`Could not find assembly "${assemblyId}" to add feature "${feature._id}"`,
)
// Auto-create the assembly if it doesn't exist in client state
// This handles the race condition where assembly exists on server but not in client state
assembly = self.assemblies.put({
_id: assemblyId,
refSeqs: {},
})
}
const ref = assembly.refSeqs.get(feature.refSeq)
let ref = assembly.refSeqs.get(feature.refSeq)
if (!ref) {
throw new Error(
`Could not find refSeq "${feature.refSeq}" to add feature "${feature._id}"`,
)
// Auto-create the refSeq if it doesn't exist
ref = assembly.refSeqs.put({
_id: feature.refSeq,
name: feature.refSeq,
features: {},
})
}
ref.features.put(feature)
},
Expand Down