From b0dbbe828597f92d9b36a11173466e9f7ac57b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bel=C3=A9n=20Albeza?= Date: Mon, 16 Nov 2026 13:32:38 +0100 Subject: [PATCH] :bug: Fix blurry file thumbnails rendered with render-wasm (#13026) The wasm path drew file thumbnails on a 252px wide canvas, wrapped the PNG in an SVG and sent it to the rasterizer, which scaled it up to its default 300px width. The result was blurry on the dashboard on high-DPI screens and in the link preview card. Render the wasm thumbnail at 600px wide, twice the old size, and upload the canvas PNG as is, without the rasterizer round trip. The SVG render path keeps its current size. Closes #13025 AI-assisted-by: claude-opus-5-5 --- frontend/src/app/main/ui/dashboard/grid.cljs | 48 +++++++++++++------- frontend/src/app/worker/thumbnails.cljs | 38 ++-------------- 2 files changed, 35 insertions(+), 51 deletions(-) diff --git a/frontend/src/app/main/ui/dashboard/grid.cljs b/frontend/src/app/main/ui/dashboard/grid.cljs index 7673e94573..e5468ea54d 100644 --- a/frontend/src/app/main/ui/dashboard/grid.cljs +++ b/frontend/src/app/main/ui/dashboard/grid.cljs @@ -50,6 +50,10 @@ (def thumbnail-width 252) +;; Larger than the grid card: the image is also the link preview card +;; and has to stay sharp on high-DPI screens. +(def ^:private wasm-thumbnail-width 600) + ;; --- Grid Item Thumbnail (defn- persist-thumbnail @@ -58,30 +62,42 @@ (->> (rp/cmd! :create-file-thumbnail params) (rx/map :id)))) +(defn- render-thumbnail-with-wasm + "Returns a stream with the PNG blob of the file thumbnail." + [file-id revn] + (->> (mw/ask! {:cmd :thumbnails/generate-for-file-wasm + :revn revn + :file-id file-id + :width wasm-thumbnail-width}) + (rx/map :blob))) + +(defn- render-thumbnail-with-svg + "Returns a stream with the PNG blob of the file thumbnail." + [file-id revn] + (->> (mw/ask! {:cmd :thumbnails/generate-for-file + :revn revn + :file-id file-id + :width thumbnail-width}) + (rx/mapcat + (fn [{:keys [fonts] :as result}] + (->> (fonts/render-font-styles fonts) + (rx/map (fn [styles] + (-> result + (assoc :styles styles + :width thumbnail-width))))))) + (rx/mapcat thr/render))) + (defn render-thumbnail + "Returns a stream with the PNG blob of the file thumbnail." [file-id revn] (if (features/active-feature? @st/state "render-wasm/v1") - (mw/ask! {:cmd :thumbnails/generate-for-file-wasm - :revn revn - :file-id file-id - :width thumbnail-width}) - (->> (mw/ask! {:cmd :thumbnails/generate-for-file - :revn revn - :file-id file-id - :width thumbnail-width}) - (rx/mapcat - (fn [{:keys [fonts] :as result}] - (->> (fonts/render-font-styles fonts) - (rx/map (fn [styles] - (-> result - (assoc :styles styles - :width thumbnail-width)))))))))) + (render-thumbnail-with-wasm file-id revn) + (render-thumbnail-with-svg file-id revn))) (defn- ask-for-thumbnail "Creates some hooks to handle the files thumbnails cache" [file-id revn] (->> (render-thumbnail file-id revn) - (rx/mapcat thr/render) (rx/mapcat (partial persist-thumbnail file-id revn)))) (mf/defc grid-item-thumbnail* diff --git a/frontend/src/app/worker/thumbnails.cljs b/frontend/src/app/worker/thumbnails.cljs index bed81a00e9..70f8933303 100644 --- a/frontend/src/app/worker/thumbnails.cljs +++ b/frontend/src/app/worker/thumbnails.cljs @@ -7,7 +7,6 @@ (ns app.worker.thumbnails (:require ["react-dom/server" :as rds] - [app.common.data.macros :as dm] [app.common.geom.rect :as grc] [app.common.geom.shapes.bounds :as gsb] [app.common.logging :as log] @@ -107,37 +106,6 @@ ;; WASM RENDERING ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(mf/defc svg-wrapper* - {::mf/private true} - [{:keys [uri background width height]}] - [:svg {:version "1.1" - :xmlns "http://www.w3.org/2000/svg" - :xmlnsXlink "http://www.w3.org/1999/xlink" - - :style {:width "100%" - :height "100%" - :background background} - :fill "none" - :viewBox (dm/str "0 0 " width " " height)} - [:image {:xlinkHref uri - :width width - :height height}]]) - -(defn- blob->uri - [blob] - (.readAsDataURL (js/FileReaderSync.) blob)) - -(defn- render-canvas-blob - [canvas width height background] - (->> (.convertToBlob ^js canvas) - (p/fmap (fn [blob] - (rds/renderToStaticMarkup - (mf/element svg-wrapper* - #js {:uri (blob->uri blob) - :width width - :height height - :background background})))))) - (defn- render-thumbnail-with-wasm [{:keys [file-id revn width] :as _message}] (->> (rx/from @wwasm/module) @@ -170,13 +138,13 @@ (wasm.api/render-sync-shape (:id frame)) (wasm.api/render-sync)) - (->> (render-canvas-blob canvas width height bgcolor) - (p/fnly (fn [data cause] + (->> (.convertToBlob ^js canvas #js {:type "image/png"}) + (p/fnly (fn [blob cause] (wasm.api/clear-canvas) (if cause (rx/error! subs cause) (rx/push! subs - {:data data + {:blob blob :file-id file-id :revn revn})) (rx/end! subs)))))))