diff --git a/backend/src/app/features/components_v2.clj b/backend/src/app/features/components_v2.clj index 3591d9dc2..f38804693 100644 --- a/backend/src/app/features/components_v2.clj +++ b/backend/src/app/features/components_v2.clj @@ -436,6 +436,28 @@ (-> file-data (update :components update-vals fix-container)))) + fix-non-existing-component-ids + ;; Check component ids have valid values. + (fn [file-data] + (let [libraries (assoc-in libraries [(:id file-data) :data] file-data)] + (letfn [(fix-container [container] + (d/update-when container :objects update-vals fix-shape)) + + (fix-shape [shape] + (let [component-id (:component-id shape) + component-file (:component-file shape) + library (get libraries component-file)] + + (cond-> shape + (and (some? component-id) + (some? library) + (nil? (ctkl/get-component (:data library) component-id))) + (ctk/detach-shape))))] + + (-> file-data + (update :pages-index update-vals fix-container) + (d/update-when :components update-vals fix-container))))) + fix-misc-shape-issues (fn [file-data] (letfn [(fix-container [container] @@ -943,6 +965,7 @@ (fix-shape-geometry) (fix-empty-components) (fix-components-with-component-root) + (fix-non-existing-component-ids) (fix-completly-broken-shapes) (fix-bad-children) (fix-broken-parents)