Skip to content

Commit

Permalink
fix(Form): memory leak (#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
romhml committed Jan 2, 2024
1 parent 4a25a12 commit ea2a24b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/runtime/components/forms/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</template>

<script lang="ts">
import { provide, ref, type PropType, defineComponent } from 'vue'
import { provide, ref, type PropType, defineComponent, onUnmounted, onMounted } from 'vue'
import { useEventBus } from '@vueuse/core'
import type { ZodSchema } from 'zod'
import type { ValidationError as JoiError, Schema as JoiSchema } from 'joi'
Expand Down Expand Up @@ -51,10 +51,16 @@ export default defineComponent({
setup (props, { expose, emit }) {
const bus = useEventBus<FormEvent>(`form-${uid()}`)
bus.on(async (event) => {
if (event.type !== 'submit' && props.validateOn?.includes(event.type)) {
await validate(event.path, { silent: true })
}
onMounted(() => {
bus.on(async (event) => {
if (event.type !== 'submit' && props.validateOn?.includes(event.type)) {
await validate(event.path, { silent: true })
}
})
})
onUnmounted(() => {
bus.reset()
})
const errors = ref<FormError[]>([])
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/utils/uid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
let _id = 0

export function uid () {
return `nuid-${_id++}`
_id = (_id + 1) % Number.MAX_SAFE_INTEGER
return `nuid-${_id}`
}

1 comment on commit ea2a24b

@vercel
Copy link

@vercel vercel bot commented on ea2a24b Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui.nuxt.com
ui-git-dev-nuxt-js.vercel.app
ui-nuxt-js.vercel.app

Please sign in to comment.