From d62c3304e3f0a8111d899c0f2381a43bd4fa3c94 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Wed, 27 Jul 2022 21:01:54 +0200 Subject: [PATCH] fix(store): only run scope dispose on parent caller # What's changed? * Only run scope disposal on parent scopes * the uppermost `useVueFlow` call * Do not reset store on flow unmount * Fixes issue that flow is broken after a `v-if` toggle --- .../vue-flow/src/composables/useVueFlow.ts | 20 ++++++++++++------- .../src/container/VueFlow/VueFlow.vue | 1 - 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/vue-flow/src/composables/useVueFlow.ts b/packages/vue-flow/src/composables/useVueFlow.ts index 3142f289..85ac58f4 100644 --- a/packages/vue-flow/src/composables/useVueFlow.ts +++ b/packages/vue-flow/src/composables/useVueFlow.ts @@ -93,6 +93,8 @@ export default (options?: FlowProps): VueFlowStore => { let vueFlow: Injection + let isParentScope = false + /** * check if we can get a store instance through injections * this should be the regular way after initialization @@ -122,6 +124,7 @@ export default (options?: FlowProps): VueFlowStore => { if (scope) { scope.vueFlowId = name + isParentScope = true } } else { // if composable was called with additional options after initialization, overwrite state with the options values @@ -137,13 +140,16 @@ export default (options?: FlowProps): VueFlowStore => { if (scope) { provide(VueFlow, vueFlow) - // dispose of state values and storage entry - tryOnScopeDispose(() => { - if (storage.get(vueFlow!.id)) { - storage.remove(vueFlow!.id) - } - vueFlow = null - }) + if (isParentScope) { + // dispose of state values and storage entry + tryOnScopeDispose(() => { + if (storage.get(vueFlow!.id)) { + vueFlow!.$destroy() + } + + vueFlow = null + }) + } } return vueFlow diff --git a/packages/vue-flow/src/container/VueFlow/VueFlow.vue b/packages/vue-flow/src/container/VueFlow/VueFlow.vue index 8fc5a1a3..ae03f2e7 100644 --- a/packages/vue-flow/src/container/VueFlow/VueFlow.vue +++ b/packages/vue-flow/src/container/VueFlow/VueFlow.vue @@ -121,7 +121,6 @@ const el = ref() onUnmounted(() => { dispose() - $reset() }) onMounted(() => {