🐛 Fix unexpected exception on viewer caused by nil objects

This issue is started to happening because of an unrelated change
on frame-shape react component where shapes are looked up directly
on objects having in supposition that objects will be exists but on
viewer there are two objects: fixed and not-fixed, and in some cases
objects map can be empty or don't contain the object.

For solve the issue, we just filter not existing objects before
progragate the children down to the inner react components, avoiding
the exception when an object appears as `nil`.
This commit is contained in:
Andrey Antukh 2023-09-19 12:23:12 +02:00 committed by Alonso Torres
parent 9e07999537
commit df2d242746

View file

@ -7,6 +7,7 @@
(ns app.main.ui.viewer.shapes (ns app.main.ui.viewer.shapes
"The main container for a frame in viewer mode" "The main container for a frame in viewer mode"
(:require (:require
[app.common.data :as d]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.types.shape.interactions :as ctsi] [app.common.types.shape.interactions :as ctsi]
@ -381,18 +382,17 @@
(defn frame-container-factory (defn frame-container-factory
[objects all-objects] [objects all-objects]
(let [shape-container (shape-container-factory objects all-objects) (let [shape-container (shape-container-factory objects all-objects)
frame-wrapper (frame-wrapper shape-container)] frame-wrapper (frame-wrapper shape-container)
lookup-xf (keep (d/getf objects))]
(mf/fnc frame-container (mf/fnc frame-container
{::mf/wrap-props false} {::mf/wrap-props false}
[props] [props]
(let [shape (obj/get props "shape") (let [shape (unchecked-get props "shape")
childs (mapv #(get objects %) (:shapes shape)) childs (into [] lookup-xf (:shapes shape))
props (obj/merge! #js {} props props (obj/merge props
#js {:shape shape #js {:childs childs
:childs childs
:objects objects :objects objects
:all-objects all-objects})] :all-objects all-objects})]
[:> frame-wrapper props])))) [:> frame-wrapper props]))))
(defn group-container-factory (defn group-container-factory