From 47e4e60b86e54554a3464a09bac0da8a9ea4d68f Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 22 Aug 2026 13:04:57 +0100 Subject: [PATCH] Enhance TemplatePreview with Clear Iframe Contents Functionality - Added a new function to clear iframe contents, improving resource management and preventing stale data display. - Integrated the clearIframeContents function into the PDF preview type change handler, ensuring a clean slate when switching to PDF previews. - Updated state management for iframe size and preview content to enhance user experience and maintain consistency. --- .../Dashboard/common/TemplatePreview.jsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/Dashboard/common/TemplatePreview.jsx b/src/components/Dashboard/common/TemplatePreview.jsx index 026e28ec..dbce1c0c 100644 --- a/src/components/Dashboard/common/TemplatePreview.jsx +++ b/src/components/Dashboard/common/TemplatePreview.jsx @@ -171,6 +171,19 @@ const TemplatePreview = ({ setPreviewContentHTML(html) } + const clearIframeContents = useCallback(() => { + iframeSizeObserverRef.current?.disconnect() + iframeSizeObserverRef.current = null + + const iframe = iframeRef.current + if (iframe) { + iframe.srcdoc = '' + } + + setPreviewContentHTML('') + setIframeSize({ width: '100%', height: 'auto' }) + }, []) + const stopRenderProgressListener = useCallback(() => { if (typeof renderUnsubscribeRef.current === 'function') { renderUnsubscribeRef.current() @@ -541,10 +554,11 @@ const TemplatePreview = ({ disabled={loading || reloadLoading} value={previewType} onChange={(value) => { - setPreviewType(value) if (value == 'PDF') { + clearIframeContents() setPDFBlob(null) } + setPreviewType(value) }} /> ) : null}