Skip to content

Commit 9155d00

Browse files
fix(docs): clear event listeners before component unmounts (#7193)
* Clear event listeners before component unmounts * fix: don't use optional chaining --------- Co-authored-by: Jacob Müller <jacob.mueller.elz@gmail.com>
1 parent 5bb20ce commit 9155d00

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

docs/components/contributors.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ export default {
135135
}
136136
137137
xhr.open('GET', url, true)
138-
xhr.addEventListener('load', onLoad)
138+
xhr.addEventListener('load', onLoad, {
139+
signal: this.controller ? this.controller.signal : undefined
140+
})
139141
// Initiate the request
140142
xhr.send()
141143
},
@@ -248,6 +250,14 @@ export default {
248250
// Donors are people/organizations with one-time (paid) donations
249251
this.makeOcRequest(this.processDonors.bind(this), { status: 'paid' })
250252
}
253+
},
254+
255+
beforeDestroy() {
256+
this.controller.abort()
257+
},
258+
259+
created() {
260+
this.controller = new window.AbortController()
251261
}
252262
}
253263
</script>

docs/components/quick-links.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,16 @@ export default {
5252
}
5353
},
5454
created() {
55-
this.$root.$on('docs-set-toc', toc => {
55+
const handleDocsSetToc = toc => {
5656
this.expanded = false
5757
// Update the TOC content
5858
this.toc = toc
59+
}
60+
61+
this.$root.$on('docs-set-toc', handleDocsSetToc)
62+
63+
this.$once('hook:beforeDestroy', () => {
64+
this.$root.$off('docs-set-toc', handleDocsSetToc)
5965
})
6066
},
6167
mounted() {

docs/components/toc.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,14 @@ export default {
5757
}
5858
},
5959
created() {
60-
this.$root.$on('docs-set-toc', toc => {
60+
const handleDocsSetToc = toc => {
6161
this.toc = toc
62+
}
63+
64+
this.$root.$on('docs-set-toc', handleDocsSetToc)
65+
66+
this.$once('hook:beforeDestroy', () => {
67+
this.$root.$off('docs-set-toc', handleDocsSetToc)
6268
})
6369
},
6470
mounted() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy