Skip to content

Commit 7a7f33d

Browse files
authored
fix(b-alert): memory leak by using the correct method to clear the countdown timeout (#5158)
1 parent f544bd5 commit 7a7f33d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/components/alert/alert.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
6565
},
6666
data() {
6767
return {
68-
countDownTimerId: null,
6968
countDown: 0,
69+
countDownTimeout: null,
7070
// If initially shown, we need to set these for SSR
7171
localShow: parseShow(this.show)
7272
}
@@ -77,7 +77,7 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
7777
this.localShow = parseShow(newVal)
7878
},
7979
countDown(newVal) {
80-
this.clearTimer()
80+
this.clearCountDownInterval()
8181
if (isNumericLike(this.show)) {
8282
// Ignore if this.show transitions to a boolean value.
8383
this.$emit('dismiss-count-down', newVal)
@@ -87,7 +87,7 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
8787
}
8888
if (newVal > 0) {
8989
this.localShow = true
90-
this.countDownTimerId = setTimeout(() => {
90+
this.countDownTimeout = setTimeout(() => {
9191
this.countDown--
9292
}, 1000)
9393
} else {
@@ -120,18 +120,18 @@ export const BAlert = /*#__PURE__*/ Vue.extend({
120120
this.localShow = parseShow(this.show)
121121
},
122122
beforeDestroy() {
123-
this.clearTimer()
123+
this.clearCountDownInterval()
124124
},
125125
methods: {
126126
dismiss() {
127-
this.clearTimer()
127+
this.clearCountDownInterval()
128128
this.countDown = 0
129129
this.localShow = false
130130
},
131-
clearTimer() {
132-
if (this.countDownTimerId) {
133-
clearInterval(this.countDownTimerId)
134-
this.countDownTimerId = null
131+
clearCountDownInterval() {
132+
if (this.countDownTimeout) {
133+
clearTimeout(this.countDownTimeout)
134+
this.countDownTimeout = null
135135
}
136136
}
137137
},

0 commit comments

Comments
 (0)