Skip to content

Commit 175048a

Browse files
fix: clean up side effects in Vue 3 helper (#423)
1 parent f426b4e commit 175048a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/lib-helpers/vue3/src/useFieldPlugin.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
FieldPluginData,
55
FieldPluginResponse,
66
} from '@storyblok/field-plugin'
7-
import { onMounted, reactive, UnwrapRef } from 'vue'
7+
import { onMounted, onUnmounted, reactive, UnwrapRef } from 'vue'
88
import { convertToRaw } from './utils'
99

1010
const updateObjectWithoutChangingReference = (
@@ -28,8 +28,10 @@ export const useFieldPlugin = <Content>(
2828
type: 'loading',
2929
})
3030

31+
let cleanup: () => void = () => undefined
32+
3133
onMounted(() => {
32-
createFieldPlugin<Content>({
34+
cleanup = createFieldPlugin<Content>({
3335
...options,
3436
onUpdateState: (state) => {
3537
if (state.type === 'error') {
@@ -90,5 +92,7 @@ export const useFieldPlugin = <Content>(
9092
})
9193
})
9294

95+
onUnmounted(cleanup)
96+
9397
return plugin
9498
}

0 commit comments

Comments
 (0)