mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 11:28:35 -05:00
[PR #23213] [CLOSED] fix: harden file preview components against crashes and stale state #65942
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/23213
Author: @Classic298
Created: 3/29/2026
Status: ❌ Closed
Base:
dev← Head:fix/file-modal-robustness📝 Commits (1)
a501195fix: harden file preview components against crashes and stale state📊 Changes
4 files changed (+89 additions, -186 deletions)
View changed files
📝
src/lib/components/chat/FileNav/FilePreview.svelte(+23 -75)📝
src/lib/components/common/FileItemModal.svelte(+33 -28)📝
src/lib/components/common/ImagePreview.svelte(+32 -81)📝
src/lib/components/common/SVGPanZoom.svelte(+1 -2)📄 Description
fix: harden file preview components against crashes and stale state
Fixes multiple crash paths, race conditions, dead code, and maintainability issues across the file preview components.
Crash fixes
FileItemModal TypeError on failed file fetch — When getFileById fails (network error, missing file), the modal template accessed item.file.data.content without optional chaining, throwing a TypeError and breaking the entire modal. Added proper optional chaining on all unguarded access paths.
FilePreview save button stuck forever — If onSave rejected in saveEdit or saveCodeFile, the saving flag was never reset. The save button became permanently disabled with no way to retry or cancel. Wrapped both functions in try/finally so the flag always resets.
Race condition fix
Functional fixes
Unreachable SVG source view in FilePreview — The Shiki syntax-highlighted SVG source branch was unreachable because the inline SVG preview branch always matched first (both checked isSvg && !showRaw). Removed the dead Shiki computation (which was wasting CPU on every SVG load) and replaced it with a proper isSvg && showRaw branch using FileCodeEditor, matching the pattern used by HTML and Markdown.
DOMPurify data- attributes silently stripped in SVGPanZoom* — The ADD_ATTR config used "data-*" as a glob pattern, but DOMPurify treats it as a literal attribute name. Data attributes on SVG content (common in Mermaid diagrams) were silently removed. Replaced with ALLOW_DATA_ATTR: true, which is the correct API.
isCode detection divergence between FileItemModal and FilePreview — FileItemModal hardcoded ~20 extensions while FilePreview used the shared isCodeFile utility. Files recognized as code in one context weren't in the other. Replaced the hardcoded list with the shared utility.
Cleanup
Stale office state between items — Excel/DOCX/PPTX state variables (excelHtml, docxHtml, pptxSlides, etc.) were not reset when switching items. Currently gated by template conditionals but would surface stale data if those conditionals ever changed. Now explicitly reset at the start of loadContent.
Triplicated download logic in ImagePreview — The blob URL and remote URL download branches were identical copy-paste. Consolidated into a single downloadImage function.
Dead variables and console.log statements — Removed unused mounted and sceneParentElement variables from ImagePreview, and removed stray console.log calls from FileItemModal, ImagePreview, and SVGPanZoom.
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.