Skip to content

Commit

Permalink
Merge pull request #5411 from nextcloud-libraries/fix/noid/reference-…
Browse files Browse the repository at this point in the history
…widget-idle

fix(NcReferenceWidget): set timeout to destroy idle widgets outside of viewports
  • Loading branch information
Antreesy authored Mar 15, 2024
2 parents 708e697 + 4952a5f commit 51b1027
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/components/NcRichText/NcReferenceWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import { renderWidget, isWidgetRegistered, destroyWidget, hasInteractiveView, ha
import NcButton from '../../components/NcButton/index.js'
const IDLE_TIMEOUT = 3 * 60 * 1000 // 3 minutes outside of viewport before widget is removed from the DOM
export default {
name: 'NcReferenceWidget',
components: {
Expand Down Expand Up @@ -92,6 +94,7 @@ export default {
return {
showInteractive: false,
rendered: false,
idleTimeout: null,
}
},
Expand Down Expand Up @@ -154,10 +157,23 @@ export default {
isVisible: {
handler(val) {
if (!val) {
this.destroyWidget()
this.idleTimeout = setTimeout(() => {
// If the widget is still outside of viewport after timeout, destroy it
if (!this.isVisible) {
this.destroyWidget()
}
}, IDLE_TIMEOUT)
return
}
this.renderWidget()
if (this.idleTimeout) {
clearTimeout(this.idleTimeout)
this.idleTimeout = null
}
if (!this.rendered) {
this.renderWidget()
}
},
immediate: true,
},
Expand Down

0 comments on commit 51b1027

Please sign in to comment.