From 9ffd00d8218bc13320661370bdd14a38d4661471 Mon Sep 17 00:00:00 2001
From: Alejandro Alonso <alejandroalonsofernandez@gmail.com>
Date: Wed, 3 Aug 2022 12:48:48 +0200
Subject: [PATCH] :bug: Fix clipped elements affect artboards centering

---
 CHANGES.md                                    |  1 +
 common/src/app/common/geom/shapes/bounds.cljc | 31 ++++++++++---------
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index ca06d87d7..50f914595 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -34,6 +34,7 @@
 
 ### :bug: Bugs fixed
 
+- Fix clipped elements affect boards and centering [Taiga #3666](https://tree.taiga.io/project/penpot/issue/3666)
 - Fix intro action in multi input [Taiga #3541](https://tree.taiga.io/project/penpot/issue/3541)
 - Fix team default image [Taiga #3919](https://tree.taiga.io/project/penpot/issue/3919)
 - Fix problem with group coordinates [#2008](https://github.com/penpot/penpot/issues/2008)
diff --git a/common/src/app/common/geom/shapes/bounds.cljc b/common/src/app/common/geom/shapes/bounds.cljc
index 83a1b25f5..367935298 100644
--- a/common/src/app/common/geom/shapes/bounds.cljc
+++ b/common/src/app/common/geom/shapes/bounds.cljc
@@ -129,26 +129,27 @@
           (-> (get-shape-filter-bounds shape)
               (add-padding (calculate-padding shape true))))
 
-        bounds
-        (cph/reduce-objects
-         objects
-         (fn [shape]
-           (and (d/not-empty? (:shapes shape))
-                (or (not (cph/frame-shape? shape))
-                    (:show-content shape))
+        bounds (if (cph/frame-shape? shape)
+                 [(calculate-base-bounds shape)]
+                 (cph/reduce-objects
+                  objects
+                  (fn [shape]
+                    (and (d/not-empty? (:shapes shape))
+                         (or (not (cph/frame-shape? shape))
+                             (:show-content shape))
 
-                (or (not (cph/group-shape? shape))
-                    (not (:masked-group? shape)))))
+                         (or (not (cph/group-shape? shape))
+                             (not (:masked-group? shape)))))
 
-         (:id shape)
+                  (:id shape)
 
-         (fn [result shape]
-           (conj result (get-object-bounds objects shape)))
+                  (fn [result shape]
+                    (conj result (get-object-bounds objects shape)))
 
-         [(calculate-base-bounds shape)])
+                  [(calculate-base-bounds shape)]))
 
-
-        children-bounds (or (:children-bounds shape) (gsr/join-selrects bounds))
+        children-bounds (cond->> (gsr/join-selrects bounds)
+                          (not (cph/frame-shape? shape)) (or (:children-bounds shape)))
 
         filters (shape->filters shape)
         blur-value (or (-> shape :blur :value) 0)]