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.
This commit is contained in:
parent
9766f4b6c3
commit
47e4e60b86
@ -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}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user