Skip to content

fix: render svg previews as images instead of inlining them - #4298

Merged
AlexAndBear merged 2 commits into
mainfrom
fix/preview-svg-as-image
Nov 9, 2026
Merged

AlexAndBear merged 2 commits into
mainfrom
fix/preview-svg-as-image

Conversation

@AlexAndBear

Copy link
Copy Markdown
Member

Description

The preview showed SVGs inline in the page, so their content ran in Web itself: an event handler on the root <svg> was executed, and a <style> inside the SVG applied to the whole page (and could load external resources where the CSP allows them). SVGs are now shown as an image like other pictures, where the browser runs no scripts, loads nothing external and keeps the CSS inside the image. The image is a data: URL instead of a blob: one, so opening it in a new tab doesn't run it on Web's origin either.

The preview no longer needs vue-inline-svg or DOMPurify. This supersedes #4221.

Related Issue

  • no issue

How Has This Been Tested?

  • test environment: unit tests (Vitest), browser tests (Playwright) against a local OpenCloud
  • test case 1: unit: SVGs, also in vaults, resolve to a data:image/svg+xml URL with the file content and never to a blob: URL, and render as a single image
  • test case 2: browser: an SVG with an onanimationstart handler on the root fired an alert on main; now it just renders
  • test case 3: browser: an SVG with a global <style> changed the page background and requested external URLs on main; now the page stays unchanged and nothing is requested
  • test case 4: browser: opening the SVG image in a new tab is blocked or runs with an opaque origin and no storage access, for normal and vault SVGs
  • test case 5: browser: zoom, rotate, switching between SVGs and other images, viewBox-only and large SVGs, broken SVGs (now an error state), public links and dark theme still work

Types of changes

  • Bugfix
  • Enhancement (a change that doesn't break existing code or deployments)
  • Breaking change (a modification that affects current functionality)
  • Technical debt (addressing code that needs refactoring or improvements)
  • Tests (adding or improving tests)
  • Documentation (updates or additions to documentation)
  • Maintenance (like dependency updates or tooling adjustments)

@AlexAndBear
AlexAndBear force-pushed the fix/preview-svg-as-image branch from 8014bd0 to 33cea2e Compare November 9, 2026 11:27

@JammingBen JammingBen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only one tiny nitpick (not 100% sure if it makes sense, but I guess).

@AlexAndBear
AlexAndBear merged commit 4990116 into main Nov 9, 2026
28 checks passed
@AlexAndBear
AlexAndBear deleted the fix/preview-svg-as-image branch November 9, 2026 12:34
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in OpenCloud Team Board Nov 9, 2026
@openclouders openclouders mentioned this pull request Nov 9, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants