Skip to content

Commit

Permalink
fix(NcReferenceWidget): set timeout to destroy idle widgets outside o…
Browse files Browse the repository at this point in the history
…f viewports

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Mar 15, 2024
1 parent b3c9e47 commit 861b0b1
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/NcButton.vue'
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 861b0b1

Please sign in to comment.