Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispose ydocs provider when closing app #8990

Merged
merged 1 commit into from
Feb 8, 2024
Merged
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
6 changes: 5 additions & 1 deletion app/gui2/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { useSuggestionDbStore } from '@/stores/suggestionDatabase'
import { configValue, type ApplicationConfig, type ApplicationConfigValue } from '@/util/config'
import ProjectView from '@/views/ProjectView.vue'
import { isDevMode } from 'shared/util/detect'
import { computed, onMounted, toRaw } from 'vue'
import { computed, onMounted, onUnmounted, toRaw } from 'vue'
import { useProjectStore } from './stores/project'

const props = defineProps<{
config: ApplicationConfig
Expand All @@ -26,6 +27,9 @@ onMounted(() => {
;(window as any).suggestionDb = toRaw(suggestionDb.entries)
}
})
onUnmounted(() => {
useProjectStore().disposeYDocsProvider()
})
</script>

<template>
Expand Down
13 changes: 9 additions & 4 deletions app/gui2/src/stores/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ export const useProjectStore = defineStore('project', () => {
return tryQualifiedName(`${fullName.value}.${withDotSeparators}`)
})

let yDocsProvider: ReturnType<typeof attachProvider> | undefined
watchEffect((onCleanup) => {
if (lsUrls.rpcUrl.startsWith('mock://')) {
doc.load()
Expand All @@ -510,16 +511,14 @@ export const useProjectStore = defineStore('project', () => {
const socketUrl = new URL(location.origin)
socketUrl.protocol = location.protocol.replace(/^http/, 'ws')
socketUrl.pathname = '/project'
const provider = attachProvider(
yDocsProvider = attachProvider(
socketUrl.href,
'index',
{ ls: lsUrls.rpcUrl },
doc,
awareness.internal,
)
onCleanup(() => {
provider.dispose()
})
onCleanup(disposeYDocsProvider)
})

const projectModel = new DistributedProject(doc)
Expand Down Expand Up @@ -675,6 +674,11 @@ export const useProjectStore = defineStore('project', () => {

const { executionMode } = setupSettings(projectModel)

function disposeYDocsProvider() {
yDocsProvider?.dispose()
yDocsProvider = undefined
}

return {
setObservedFileName(name: string) {
observedFileName.value = name
Expand All @@ -699,6 +703,7 @@ export const useProjectStore = defineStore('project', () => {
executionMode,
dataflowErrors,
executeExpression,
disposeYDocsProvider,
}
})

Expand Down
Loading