Merge pull request #9072 from penpot/alotor-fix-swap-component

🐛 Fix problem on component swap
This commit is contained in:
Elena Torró 2026-04-21 13:53:21 +02:00 committed by GitHub
commit c636517499
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 56 additions and 37 deletions

View File

@ -61,23 +61,25 @@
(js/requestAnimationFrame (js/requestAnimationFrame
(fn [_] (fn [_]
(try (try
(let [objects (dsh/lookup-page-objects @st/state file-id page-id) (let [objects (dsh/lookup-page-objects @st/state file-id page-id)]
frame (get objects frame-id) (if-let [frame (get objects frame-id)]
{:keys [width height]} (:selrect frame) (let [{:keys [width height]} (:selrect frame)
max-size (mth/max width height) max-size (mth/max width height)
scale (mth/max 1 (/ target-size max-size)) scale (mth/max 1 (/ target-size max-size))
png-bytes (wasm.api/render-shape-pixels frame-id scale)] png-bytes (wasm.api/render-shape-pixels frame-id scale)]
(if (or (nil? png-bytes) (zero? (.-length png-bytes))) (if (or (nil? png-bytes) (zero? (.-length png-bytes)))
(do (do
(l/error :hint "render-shape-pixels returned empty" :frame-id (str frame-id)) (l/error :hint "render-shape-pixels returned empty" :frame-id (str frame-id))
(rx/end! subs)) (rx/end! subs))
(.then (.then
(png-bytes->data-uri png-bytes) (png-bytes->data-uri png-bytes)
(fn [data-uri] (fn [data-uri]
(rx/push! subs data-uri) (rx/push! subs data-uri)
(rx/end! subs)) (rx/end! subs))
(fn [err] (fn [err]
(rx/error! subs err))))) (rx/error! subs err)))))
(rx/error! subs "Frame not found")))
(catch :default err (catch :default err
(rx/error! subs err)))))] (rx/error! subs err)))))]
#(js/cancelAnimationFrame req-id))))) #(js/cancelAnimationFrame req-id)))))

View File

@ -309,7 +309,7 @@
;; while the component is still not rendered and the thumbnail URI ;; while the component is still not rendered and the thumbnail URI
;; is not available. ;; is not available.
(mf/use-effect (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 [] (fn []
(if (some? thumbnail-uri) (if (some? thumbnail-uri)
(mf/set-ref-val! thumbnail-requested? false) (mf/set-ref-val! thumbnail-requested? false)

View File

@ -589,7 +589,7 @@
:on-click on-select :on-click on-select
:disabled loop} :disabled loop}
(when visible? (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) :class (stl/css :swap-item-thumbnail)
:root-shape root-shape :root-shape root-shape
:component item :component item

View File

@ -1017,6 +1017,10 @@ pub extern "C" fn render_shape_pixels(
) -> Result<*mut u8> { ) -> Result<*mut u8> {
let id = uuid_from_u32_quartet(a, b, c, d); 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, { with_state_mut!(state, {
let (data, width, height) = let (data, width, height) =
state.render_shape_pixels(&id, scale, performance::get_time())?; state.render_shape_pixels(&id, scale, performance::get_time())?;

View File

@ -938,36 +938,49 @@ impl Surfaces {
if max_w > self.extra_tile_dims.width || max_h > self.extra_tile_dims.height { 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.extra_tile_dims = skia::ISize::new(max_w, max_h);
self.drop_shadows = self
if let Some(surface) = self
.drop_shadows .drop_shadows
.new_surface_with_dimensions((max_w, max_h)) .new_surface_with_dimensions((max_w, max_h))
.unwrap(); {
self.inner_shadows = self self.drop_shadows = surface;
}
if let Some(surface) = self
.inner_shadows .inner_shadows
.new_surface_with_dimensions((max_w, max_h)) .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 .text_drop_shadows
.new_surface_with_dimensions((max_w, max_h)) .new_surface_with_dimensions((max_w, max_h))
.unwrap(); {
self.text_drop_shadows = self self.text_drop_shadows = surface;
.text_drop_shadows }
.new_surface_with_dimensions((max_w, max_h))
.unwrap(); if let Some(surface) = self
self.shape_strokes = self
.shape_strokes .shape_strokes
.new_surface_with_dimensions((max_w, max_h)) .new_surface_with_dimensions((max_w, max_h))
.unwrap(); {
self.shape_fills = self self.shape_strokes = surface;
}
if let Some(surface) = self
.shape_strokes .shape_strokes
.new_surface_with_dimensions((max_w, max_h)) .new_surface_with_dimensions((max_w, max_h))
.unwrap(); {
self.shape_fills = surface;
}
} }
self.export = self if let Some(surface) = self
.export .export
.new_surface_with_dimensions((target_w, target_h)) .new_surface_with_dimensions((target_w, target_h))
.unwrap(); {
self.export = surface;
}
} }
} }

View File

@ -314,9 +314,9 @@ pub extern "C" fn set_shape_grow_type(grow_type: u8) {
with_current_shape_mut!(state, |shape: &mut Shape| { with_current_shape_mut!(state, |shape: &mut Shape| {
if let Type::Text(text_content) = &mut shape.shape_type { if let Type::Text(text_content) = &mut shape.shape_type {
text_content.set_grow_type(GrowType::from(grow_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.
}); });
} }