mirror of
https://github.com/penpot/penpot.git
synced 2026-03-14 14:27:11 +00:00
🐛 Fix TypeError when path content is nil in get-points calls
Use nil-safe path/get-points wrapper (some-> based) instead of direct path.segment/get-points calls in edition.cljs to prevent 'Cannot read properties of undefined (reading get)' crash. Add nil-safety test to verify path/get-points returns nil without throwing when content is nil. Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
@@ -270,6 +270,15 @@
|
||||
(t/is (= result1 result2))
|
||||
(t/is (= result2 result3))))
|
||||
|
||||
(t/deftest path-get-points-nil-safe
|
||||
(t/testing "path/get-points returns nil for nil content without throwing"
|
||||
(t/is (nil? (path/get-points nil))))
|
||||
(t/testing "path/get-points returns correct points for valid content"
|
||||
(let [content (path/content sample-content)
|
||||
points (path/get-points content)]
|
||||
(t/is (some? points))
|
||||
(t/is (= 3 (count points))))))
|
||||
|
||||
(defn calculate-extremities
|
||||
"Calculate extremities for the provided content.
|
||||
A legacy implementation used mainly as reference for testing"
|
||||
|
||||
@@ -59,8 +59,8 @@
|
||||
content (get shape :content)
|
||||
new-content (path/apply-content-modifiers content content-modifiers)
|
||||
|
||||
old-points (path.segment/get-points content)
|
||||
new-points (path.segment/get-points new-content)
|
||||
old-points (path/get-points content)
|
||||
new-points (path/get-points new-content)
|
||||
point-change (->> (map hash-map old-points new-points) (reduce merge))]
|
||||
|
||||
(when (and (some? new-content) (some? shape))
|
||||
@@ -162,7 +162,7 @@
|
||||
start-position (apply min-key #(gpt/distance start-position %) selected-points)
|
||||
|
||||
content (st/get-path state :content)
|
||||
points (path.segment/get-points content)]
|
||||
points (path/get-points content)]
|
||||
|
||||
(rx/concat
|
||||
;; This stream checks the consecutive mouse positions to do the dragging
|
||||
@@ -255,7 +255,7 @@
|
||||
start-delta-y (dm/get-in modifiers [index cy] 0)
|
||||
|
||||
content (st/get-path state :content)
|
||||
points (path.segment/get-points content)
|
||||
points (path/get-points content)
|
||||
|
||||
point (-> content (nth (if (= prefix :c1) (dec index) index)) (path.helpers/segment->point))
|
||||
handler (-> content (nth index) (path.segment/get-handler prefix))
|
||||
|
||||
Reference in New Issue
Block a user