From 3da74ed864a9c56a7da586753ea8ff852c6df401 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 21 Apr 2026 12:50:38 +0200 Subject: [PATCH 1/2] :bug: Fix problem with component thumbnails in swap component panel --- .../main/data/workspace/thumbnails_wasm.cljs | 36 ++++++++------- .../ui/workspace/sidebar/assets/common.cljs | 2 +- .../sidebar/options/menus/component.cljs | 2 +- render-wasm/src/main.rs | 4 ++ render-wasm/src/render/surfaces.rs | 45 ++++++++++++------- 5 files changed, 54 insertions(+), 35 deletions(-) diff --git a/frontend/src/app/main/data/workspace/thumbnails_wasm.cljs b/frontend/src/app/main/data/workspace/thumbnails_wasm.cljs index 82bf85cc2c..ff82e15972 100644 --- a/frontend/src/app/main/data/workspace/thumbnails_wasm.cljs +++ b/frontend/src/app/main/data/workspace/thumbnails_wasm.cljs @@ -61,23 +61,25 @@ (js/requestAnimationFrame (fn [_] (try - (let [objects (dsh/lookup-page-objects @st/state file-id page-id) - frame (get objects frame-id) - {:keys [width height]} (:selrect frame) - max-size (mth/max width height) - scale (mth/max 1 (/ target-size max-size)) - png-bytes (wasm.api/render-shape-pixels frame-id scale)] - (if (or (nil? png-bytes) (zero? (.-length png-bytes))) - (do - (l/error :hint "render-shape-pixels returned empty" :frame-id (str frame-id)) - (rx/end! subs)) - (.then - (png-bytes->data-uri png-bytes) - (fn [data-uri] - (rx/push! subs data-uri) - (rx/end! subs)) - (fn [err] - (rx/error! subs err))))) + (let [objects (dsh/lookup-page-objects @st/state file-id page-id)] + (if-let [frame (get objects frame-id)] + (let [{:keys [width height]} (:selrect frame) + max-size (mth/max width height) + scale (mth/max 1 (/ target-size max-size)) + png-bytes (wasm.api/render-shape-pixels frame-id scale)] + (if (or (nil? png-bytes) (zero? (.-length png-bytes))) + (do + (l/error :hint "render-shape-pixels returned empty" :frame-id (str frame-id)) + (rx/end! subs)) + (.then + (png-bytes->data-uri png-bytes) + (fn [data-uri] + (rx/push! subs data-uri) + (rx/end! subs)) + (fn [err] + (rx/error! subs err))))) + + (rx/error! subs "Frame not found"))) (catch :default err (rx/error! subs err)))))] #(js/cancelAnimationFrame req-id))))) diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs index 41fd1c4088..227cbf77b4 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs @@ -309,7 +309,7 @@ ;; while the component is still not rendered and the thumbnail URI ;; is not available. (mf/use-effect - (mf/deps is-hidden thumbnail-uri wasm? current-page-id) + (mf/deps is-hidden thumbnail-uri wasm? current-page-id file-id page-id) (fn [] (if (some? thumbnail-uri) (mf/set-ref-val! thumbnail-requested? false) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs index 401b01d67b..3a8f07a136 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs @@ -589,7 +589,7 @@ :on-click on-select :disabled loop} (when visible? - [:> cmm/component-item-thumbnail* {:file-id (:file-id item) + [:> cmm/component-item-thumbnail* {:file-id file-id :class (stl/css :swap-item-thumbnail) :root-shape root-shape :component item diff --git a/render-wasm/src/main.rs b/render-wasm/src/main.rs index 957955d3e0..9f298c3900 100644 --- a/render-wasm/src/main.rs +++ b/render-wasm/src/main.rs @@ -1017,6 +1017,10 @@ pub extern "C" fn render_shape_pixels( ) -> Result<*mut u8> { let id = uuid_from_u32_quartet(a, b, c, d); + if !scale.is_finite() { + return Err(Error::CriticalError("Scale is not finite".to_string())); + } + with_state_mut!(state, { let (data, width, height) = state.render_shape_pixels(&id, scale, performance::get_time())?; diff --git a/render-wasm/src/render/surfaces.rs b/render-wasm/src/render/surfaces.rs index e3a9512e08..ca7f2a3ef2 100644 --- a/render-wasm/src/render/surfaces.rs +++ b/render-wasm/src/render/surfaces.rs @@ -938,36 +938,49 @@ impl Surfaces { if max_w > self.extra_tile_dims.width || max_h > self.extra_tile_dims.height { self.extra_tile_dims = skia::ISize::new(max_w, max_h); - self.drop_shadows = self + + if let Some(surface) = self .drop_shadows .new_surface_with_dimensions((max_w, max_h)) - .unwrap(); - self.inner_shadows = self + { + self.drop_shadows = surface; + } + + if let Some(surface) = self .inner_shadows .new_surface_with_dimensions((max_w, max_h)) - .unwrap(); - self.text_drop_shadows = self + { + self.inner_shadows = surface; + } + + if let Some(surface) = self .text_drop_shadows .new_surface_with_dimensions((max_w, max_h)) - .unwrap(); - self.text_drop_shadows = self - .text_drop_shadows - .new_surface_with_dimensions((max_w, max_h)) - .unwrap(); - self.shape_strokes = self + { + self.text_drop_shadows = surface; + } + + if let Some(surface) = self .shape_strokes .new_surface_with_dimensions((max_w, max_h)) - .unwrap(); - self.shape_fills = self + { + self.shape_strokes = surface; + } + + if let Some(surface) = self .shape_strokes .new_surface_with_dimensions((max_w, max_h)) - .unwrap(); + { + self.shape_fills = surface; + } } - self.export = self + if let Some(surface) = self .export .new_surface_with_dimensions((target_w, target_h)) - .unwrap(); + { + self.export = surface; + } } } From f89f4e0047366084ebf3cea9e29f023ca359049c Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 21 Apr 2026 13:09:21 +0200 Subject: [PATCH 2/2] :bug: Fix problem on component swap --- render-wasm/src/wasm/text.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/render-wasm/src/wasm/text.rs b/render-wasm/src/wasm/text.rs index f34aa10cf2..88726de91e 100644 --- a/render-wasm/src/wasm/text.rs +++ b/render-wasm/src/wasm/text.rs @@ -314,9 +314,9 @@ pub extern "C" fn set_shape_grow_type(grow_type: u8) { with_current_shape_mut!(state, |shape: &mut Shape| { if let Type::Text(text_content) = &mut shape.shape_type { text_content.set_grow_type(GrowType::from(grow_type)); - } else { - panic!("Trying to update grow type in a shape that it's not a text shape"); } + // Don't throw error if the object is not text. + // On swap component opperations is convenient. }); }