Skip to content

Commit e67d341

Browse files
authored
fix: component destroy handling on parent destroy (#5749)
1 parent 7d06bf6 commit e67d341

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

src/components/modal/helpers/bv-modal.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { BModal, props as modalProps } from '../modal'
33
import { concat } from '../../../utils/array'
44
import { getComponentConfig } from '../../../utils/config'
5+
import { requestAF } from '../../../utils/dom'
56
import { isUndefined, isFunction } from '../../../utils/inspect'
67
import {
78
assign,
@@ -69,10 +70,11 @@ const plugin = Vue => {
6970
mounted() {
7071
// Self destruct handler
7172
const handleDestroy = () => {
72-
const self = this
7373
this.$nextTick(() => {
74-
// In a `setTimeout()` to release control back to application
75-
setTimeout(() => self.$destroy(), 0)
74+
// In a `requestAF()` to release control back to application
75+
requestAF(() => {
76+
this.$destroy()
77+
})
7678
})
7779
}
7880
// Self destruct if parent destroyed

src/components/toast/helpers/bv-toast.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,17 @@ const plugin = Vue => {
6363
}
6464
},
6565
mounted() {
66-
const self = this
6766
// Self destruct handler
6867
const handleDestroy = () => {
6968
// Ensure the toast has been force hidden
70-
self.localShow = false
71-
self.doRender = false
72-
self.$nextTick(() => {
73-
self.$nextTick(() => {
69+
this.localShow = false
70+
this.doRender = false
71+
this.$nextTick(() => {
72+
this.$nextTick(() => {
7473
// In a `requestAF()` to release control back to application
7574
// and to allow the portal-target time to remove the content
7675
requestAF(() => {
77-
self.$destroy()
76+
this.$destroy()
7877
})
7978
})
8079
})
@@ -86,7 +85,7 @@ const plugin = Vue => {
8685
// Self destruct when toaster is destroyed
8786
this.listenOnRoot('bv::toaster::destroyed', toaster => {
8887
/* istanbul ignore next: hard to test */
89-
if (toaster === self.toaster) {
88+
if (toaster === this.toaster) {
9089
handleDestroy()
9190
}
9291
})

src/components/tooltip/helpers/bv-popper.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Vue from '../../../utils/vue'
99
import Popper from 'popper.js'
10-
import { getCS, select } from '../../../utils/dom'
10+
import { getCS, requestAF, select } from '../../../utils/dom'
1111
import { toFloat } from '../../../utils/number'
1212
import { HTMLElement, SVGElement } from '../../../utils/safe-types'
1313
import { BVTransition } from '../../../utils/bv-transition'
@@ -139,12 +139,19 @@ export const BVPopper = /*#__PURE__*/ Vue.extend({
139139
this.$on('show', el => {
140140
this.popperCreate(el)
141141
})
142-
// Self destruct once hidden
143-
this.$on('hidden', () => {
144-
this.$nextTick(this.$destroy)
145-
})
146-
// If parent is destroyed, ensure we are destroyed
147-
this.$parent.$once('hook:destroyed', this.$destroy)
142+
// Self destruct handler
143+
const handleDestroy = () => {
144+
this.$nextTick(() => {
145+
// In a `requestAF()` to release control back to application
146+
requestAF(() => {
147+
this.$destroy()
148+
})
149+
})
150+
}
151+
// Self destruct if parent destroyed
152+
this.$parent.$once('hook:destroyed', handleDestroy)
153+
// Self destruct after hidden
154+
this.$once('hidden', handleDestroy)
148155
},
149156
beforeMount() {
150157
// Ensure that the attachment position is correct before mounting

src/components/tooltip/helpers/bv-tooltip.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
isElement,
2222
isVisible,
2323
removeAttr,
24+
requestAF,
2425
select,
2526
setAttr
2627
} from '../../../utils/dom'
@@ -228,7 +229,14 @@ export const BVTooltip = /*#__PURE__*/ Vue.extend({
228229

229230
// Destroy ourselves when the parent is destroyed
230231
if (this.$parent) {
231-
this.$parent.$once('hook:beforeDestroy', this.$destroy)
232+
this.$parent.$once('hook:beforeDestroy', () => {
233+
this.$nextTick(() => {
234+
// In a `requestAF()` to release control back to application
235+
requestAF(() => {
236+
this.$destroy()
237+
})
238+
})
239+
})
232240
}
233241

234242
this.$nextTick(() => {

0 commit comments

Comments
 (0)