diff --git a/src/composables/useVueFlow.ts b/src/composables/useVueFlow.ts index f3d6aa37..280b3101 100644 --- a/src/composables/useVueFlow.ts +++ b/src/composables/useVueFlow.ts @@ -59,20 +59,20 @@ export default (options?: Partial>): UseVueFlo const name = options?.id ?? `vue-flow-${id++}` vueFlow = storage.create(name, options) + + if (scope) { + provide(VueFlow, storage.get(name)) + scope.vueFlowId = name + + onScopeDispose(() => { + storage.remove(name) + vueFlow = null + }) + } } else { if (options) vueFlow.setState(options) } if (!vueFlow) throw new Error('vue flow store instance not found.') - if (scope) { - provide(VueFlow, storage.get(vueFlow.id)) - scope.vueFlowId = vueFlow.id - - onScopeDispose(() => { - storage.remove(vueFlow!.id) - vueFlow = null - }) - } - return vueFlow }