diff --git a/packages/lib-helpers/vue3/src/useFieldPlugin.ts b/packages/lib-helpers/vue3/src/useFieldPlugin.ts index e37a0ee8..4ff91437 100644 --- a/packages/lib-helpers/vue3/src/useFieldPlugin.ts +++ b/packages/lib-helpers/vue3/src/useFieldPlugin.ts @@ -4,7 +4,7 @@ import { FieldPluginData, FieldPluginResponse, } from '@storyblok/field-plugin' -import { onMounted, reactive, UnwrapRef } from 'vue' +import { onMounted, onUnmounted, reactive, UnwrapRef } from 'vue' import { convertToRaw } from './utils' const updateObjectWithoutChangingReference = ( @@ -28,8 +28,10 @@ export const useFieldPlugin = ( type: 'loading', }) + let cleanup: () => void = () => undefined + onMounted(() => { - createFieldPlugin({ + cleanup = createFieldPlugin({ ...options, onUpdateState: (state) => { if (state.type === 'error') { @@ -90,5 +92,7 @@ export const useFieldPlugin = ( }) }) + onUnmounted(cleanup) + return plugin }