diff --git a/resources/js/components/GraphqlMutation.vue b/resources/js/components/GraphqlMutation.vue index 1b7e1aab2..73e8486fb 100644 --- a/resources/js/components/GraphqlMutation.vue +++ b/resources/js/components/GraphqlMutation.vue @@ -80,6 +80,7 @@ export default { data: {}, mutate: () => null, redirectUrl: '', + stopMutateListener: () => null, }), render() { @@ -128,18 +129,23 @@ export default { mounted() { if (this.mutateEvent) { - this.$nextTick(() => - window.$on( - this.mutateEvent, - () => { - this.mutate() - }, - { defer: false }, - ), + this.$nextTick( + () => + (this.stopMutateListener = window.$on( + this.mutateEvent, + () => { + this.mutate() + }, + { defer: false }, + )), ) } }, + unmounted() { + this.stopMutateListener() + }, + methods: { async mutateFn() { if (this.running && JSON.stringify(this.data) === JSON.stringify(this.runningVariables)) { diff --git a/resources/js/polyfills/emit.js b/resources/js/polyfills/emit.js index 9a4a1487a..d84984b83 100644 --- a/resources/js/polyfills/emit.js +++ b/resources/js/polyfills/emit.js @@ -32,8 +32,9 @@ export const on = (window.$on = (event, callback, options = {}) => { } if (options.autoRemove) { - useEventListener(document, event, callbackFn) + return useEventListener(document, event, callbackFn) } else { document.addEventListener(event, callbackFn) + return () => document.removeEventListener(event, callbackFn) } })