From 861b0b165b20edb5048b629f4a2f6905f90d798b Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Fri, 15 Mar 2024 16:13:30 +0100 Subject: [PATCH] fix(NcReferenceWidget): set timeout to destroy idle widgets outside of viewports Signed-off-by: Maksim Sukharev --- .../NcRichText/NcReferenceWidget.vue | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/NcRichText/NcReferenceWidget.vue b/src/components/NcRichText/NcReferenceWidget.vue index 268d1f88c6..6f7687b9d6 100644 --- a/src/components/NcRichText/NcReferenceWidget.vue +++ b/src/components/NcRichText/NcReferenceWidget.vue @@ -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: { @@ -92,6 +94,7 @@ export default { return { showInteractive: false, rendered: false, + idleTimeout: null, } }, @@ -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, },