From d9714e6d6e53b236aa9a4f86c0e5b57a5c634759 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 14 Oct 2025 16:51:35 +0200 Subject: [PATCH] :bug: Add migration for fix pages without name and invalid shapes Invalid shapes means, shapes that is stored as plain map instead of a proper shape type. We try to preserve all the attributes on coercing it to shape but if incorrect state is generated, as the last resort we replace the shape with a dummy rect --- common/src/app/common/files/migrations.cljc | 35 ++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 96f7dcca78..c8f16d02c9 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -1621,6 +1621,38 @@ (update :pages-index d/update-vals update-container) (d/update-when :components d/update-vals update-container)))) +(defmethod migrate-data "0016-clear-pages-and-shapes" + [data _] + (letfn [(fix-invalid-shape [objects id shape] + ;; This function ensures that we don't have completly + ;; invalid shapes; i3f non-shape instance if found, we + ;; suppose it is a map and proceed to sanitize to a valid + ;; shape preserving all properties as possible; if the + ;; result shape is still invalid, we replace the shape + ;; with a dummy rectangle; + ;; + ;; This apprach is less destructive and does not need any + ;; parents manipulation + (if (cts/shape? shape) + objects + (let [shape (-> shape + (assoc :id id) + (update :type #(d/nilv % :rect)) + (cts/setup-shape))] + (if (cts/valid-shape? shape) + (assoc objects id shape) + (assoc objects id (cts/setup-shape {:type :rect})))))) + + (update-container [container] + (-> container + (d/update-when :name #(d/nilv % "")) + (d/update-when :objects (fn [objects] + (reduce-kv fix-invalid-shape objects objects)))))] + + (-> 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" @@ -1691,4 +1723,5 @@ "0012-fix-position-data" "0013-fix-component-path" "0014-fix-tokens-lib-duplicate-ids" - "0015-clear-invalid-strokes-and-fills"])) + "0015-clear-invalid-strokes-and-fills" + "0016-clear-pages-and-shapes"]))