🐛 Fix conditional use-ctx hook violation in shape-wrapper (#9281)

* 🐛 Fix conditional use-ctx hook violation in shape-wrapper

*  Avoid subscribing non-root shapes to active-frames context

* 🐛 Wrap render-shape-content hiccup with mf/html

---------

Signed-off-by: Andrey Antukh <niwi@niwi.nz>
Co-authored-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
Dexterity 2026-05-19 07:32:40 -04:00 committed by GitHub
parent 54a866d0b5
commit 408a9b033a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -96,31 +96,15 @@
:thumbnail? thumbnail?}]
[:& shape-wrapper {:shape shape}])]))]]]))
(mf/defc shape-wrapper
{::mf/wrap [#(mf/memo' % common/check-shape-props)]
::mf/wrap-props false}
[props]
(let [shape (unchecked-get props "shape")
shape-type (dm/get-prop shape :type)
shape-id (dm/get-prop shape :id)
;; FIXME: WARN: this breaks react rule of hooks (hooks can't be under conditional)
active-frames
(when (cfh/root-frame? shape)
(mf/use-ctx ctx/active-frames))
thumbnail?
(and (some? active-frames)
(not (contains? active-frames shape-id)))
props #js {:shape shape :thumbnail? thumbnail?}
(defn- render-shape-content
[shape thumbnail?]
(let [shape-type (dm/get-prop shape :type)
rawsvg? (= :svg-raw shape-type)
wrapper-elem (if ^boolean rawsvg? mf/Fragment "g")
wrapper-props (if ^boolean rawsvg?
#js {}
#js {:className "workspace-shape-wrapper"})]
#js {:className "workspace-shape-wrapper"})
props #js {:shape shape :thumbnail? thumbnail?}]
(when (and (some? shape)
(not ^boolean (:hidden shape)))
[:> wrapper-elem wrapper-props
@ -135,7 +119,27 @@
:bool [:> bool-wrapper props]
:frame [:> nested-frame-wrapper props]
nil)])))
nil)]))))
(mf/defc root-frame-shape-wrapper
{::mf/wrap [#(mf/memo' % common/check-shape-props)]
::mf/wrap-props false}
[props]
(let [shape (unchecked-get props "shape")
shape-id (dm/get-prop shape :id)
active-frames (mf/use-ctx ctx/active-frames)
thumbnail? (and (some? active-frames)
(not (contains? active-frames shape-id)))]
(render-shape-content shape thumbnail?)))
(mf/defc shape-wrapper
{::mf/wrap [#(mf/memo' % common/check-shape-props)]
::mf/wrap-props false}
[props]
(let [shape (unchecked-get props "shape")]
(if ^boolean (cfh/root-frame? shape)
[:> root-frame-shape-wrapper props]
(render-shape-content shape false))))
(def group-wrapper (group/group-wrapper-factory shape-wrapper))
(def svg-raw-wrapper (svg-raw/svg-raw-wrapper-factory shape-wrapper))