From d0cc859bc2e7d9d0710efa2db221868dc2cf8431 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 19 May 2026 17:41:41 +0200 Subject: [PATCH] :sparkles: Migrate svg-attrs, optimize set-shape-svg-attrs, filter invalid URLs (#9118) * :sparkles: Add svg-attrs casing fix migration * :zap: Optimize set-shape-svg-attrs by removing redundant operations - Remove backward compatibility for kebab-case SVG attribute keys (fill-rule, stroke-linecap, stroke-linejoin) since svg-attrs are already normalized to camelCase by the attrs->props migration. - Remove unnecessary select-keys filtering and intermediate map construction (dissoc :style + merge style). - Directly extract values from style and attrs using or, avoiding any intermediate map allocation. Signed-off-by: Andrey Antukh * :bug: Filter non-http(s) URLs in upload-images to prevent invalid calls Skip upload for image items that are not data URIs and do not have an http:// or https:// URL, avoiding unnecessary RPC calls with invalid URLs to create-file-media-object-from-url. Signed-off-by: Andrey Antukh --------- Signed-off-by: Andrey Antukh --- common/src/app/common/files/migrations.cljc | 18 +++++++++++++++++- .../app/main/data/workspace/svg_upload.cljs | 8 +++++--- frontend/src/app/render_wasm/api.cljs | 14 ++++---------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index eeb11e9067..5721910890 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -1805,6 +1805,21 @@ {})] (cfcp/sync-component-id-with-ref-shape data libraries))) +(defmethod migrate-data "0021-fix-shape-svg-attrs" + [data _] + (some-> cfeat/*new* (swap! conj "fdata/shape-data-type")) + (letfn [(update-object [object] + (-> object + (d/update-when :svg-attrs csvg/attrs->props) + (d/update-when :svg-viewbox grc/make-rect))) + + (update-container [container] + (d/update-when container :objects d/update-vals update-object))] + + (-> data + (update :pages-index d/update-vals update-container) + (d/update-when :components d/update-vals update-container)))) + (def available-migrations (into (d/ordered-set) ["legacy-2" @@ -1882,4 +1897,5 @@ "0017-fix-layout-flex-dir" "0018-remove-unneeded-objects-from-components" "0019-fix-missing-swap-slots" - "0020-sync-component-id-with-near-main"])) + "0020-sync-component-id-with-near-main" + "0021-fix-shape-svg-attrs"])) diff --git a/frontend/src/app/main/data/workspace/svg_upload.cljs b/frontend/src/app/main/data/workspace/svg_upload.cljs index a573cd594b..265c31b0b2 100644 --- a/frontend/src/app/main/data/workspace/svg_upload.cljs +++ b/frontend/src/app/main/data/workspace/svg_upload.cljs @@ -47,10 +47,12 @@ (-> item (assoc :name (extract-name href)) (assoc :url href)))))) + (rx/filter (fn [item] + (or (contains? item :content) + (let [url (:url item)] + (or (str/starts-with? url "http://") + (str/starts-with? url "https://")))))) (rx/mapcat (fn [item] - ;; TODO: :create-file-media-object-from-url is - ;; deprecated and this should be resolved in - ;; frontend (->> (rp/cmd! (if (contains? item :content) :upload-file-media-object :create-file-media-object-from-url) diff --git a/frontend/src/app/render_wasm/api.cljs b/frontend/src/app/render_wasm/api.cljs index 6924456411..2d3b106451 100644 --- a/frontend/src/app/render_wasm/api.cljs +++ b/frontend/src/app/render_wasm/api.cljs @@ -762,16 +762,10 @@ (defn set-shape-svg-attrs [attrs] (let [style (:style attrs) - ;; Filter to only supported attributes - allowed-keys #{:fill :fillRule :fill-rule :strokeLinecap :stroke-linecap :strokeLinejoin :stroke-linejoin} - attrs (-> attrs - (dissoc :style) - (merge style) - (select-keys allowed-keys)) - fill-rule (-> (or (:fill-rule attrs) (:fillRule attrs)) sr/translate-fill-rule) - stroke-linecap (-> (or (:stroke-linecap attrs) (:strokeLinecap attrs)) sr/translate-stroke-linecap) - stroke-linejoin (-> (or (:stroke-linejoin attrs) (:strokeLinejoin attrs)) sr/translate-stroke-linejoin) - fill-none (= "none" (-> attrs :fill))] + fill-rule (-> (or (:fillRule style) (:fillRule attrs)) sr/translate-fill-rule) + stroke-linecap (-> (or (:strokeLinecap style) (:strokeLinecap attrs)) sr/translate-stroke-linecap) + stroke-linejoin (-> (or (:strokeLinejoin style) (:strokeLinejoin attrs)) sr/translate-stroke-linejoin) + fill-none (= "none" (or (:fill style) (:fill attrs)))] (h/call wasm/internal-module "_set_shape_svg_attrs" fill-rule stroke-linecap stroke-linejoin fill-none))) (defn set-shape-path-content