Repository: penpot/penpot
File: frontend/src/app/main/ui/comments.cljs (ClojureScript)

Code before:
        zoom-scale-step     1.75
        scaled-zoom         (* zoom zoom-scale-step)
        zoomed-wl           (dwz/impl-update-zoom wl position scaled-zoom)]
    (if (or (= num-threads num-grouped-threads)
            (some #((comp not inside-vbox?) % zoomed-wl) grouped-threads))
      zoom
      (calculate-zoom-scale position scaled-zoom threads zoomed-wl))))

(mf/defc comment-floating-group*
  {::mf/wrap [mf/memo]}
  [{:keys [thread-group zoom position-modifier]}]
  (let [positions   (mapv :position thread-group)

        position    (gpt/center-points positions)
        position    (cond-> position
                      (some? position-modifier)
                      (gpt/transform position-modifier))
        pos-x       (* (:x position) zoom)
        pos-y       (* (:y position) zoom)

        unread?     (some #(pos? (:count-unread-comments %)) thread-group)
        num-threads (str (count thread-group))

        test-id     (str/join "-" (map :seqn (sort-by :seqn thread-group)))

        wl          (mf/deref refs/workspace-local)

        on-click
        (mf/use-fn
         (mf/deps thread-group position zoom wl)
         (fn []
           (let [centered-wl  (dwv/calculate-centered-viewbox wl position)
                 updated-zoom (calculate-zoom-scale position zoom thread-group centered-wl)
                 scale-zoom   (/ updated-zoom zoom)]
             (st/emit! (dwv/update-viewport-position-center position)
                       (dwz/set-zoom position scale-zoom)))))]

    [:div {:style {:top (dm/str pos-y "px")
                   :left (dm/str pos-x "px")}
           :on-click on-click
           :class (stl/css :floating-preview-wrapper :floating-preview-bubble)}
     [:> comment-avatar*
      {:class (stl/css :avatar-lg)
       :variant (if unread? "unread" "read")
       :data-testid (dm/str "floating-thread-bubble-" test-id)}
      num-threads]]))

(mf/defc comment-floating-bubble*
  {::mf/wrap [mf/memo]}
  [{:keys [thread zoom is-open on-click origin position-modifier]}]
  (let [owner        (mf/with-memo [thread]

Review comment (suggestion):
if the `wl` value is only needed on time of executing the click event, the value can be derefed with plain deref on the click handler instead of creating this reactive deref that adds a watcher on workspace-local ref.

Code after:
        zoom-scale-step     1.75
        scaled-zoom         (* zoom zoom-scale-step)
        zoomed-wl           (dwz/impl-update-zoom wl position scaled-zoom)
        outside-vbox?       (complement inside-vbox?)]
    (if (or (= num-threads num-grouped-threads)
            (some #(outside-vbox? % zoomed-wl) grouped-threads))
      zoom
      (calculate-zoom-scale position scaled-zoom threads zoomed-wl))))

(mf/defc comment-floating-group*
  {::mf/wrap [mf/memo]}
  [{:keys [thread-group zoom position-modifier]}]
  (let [positions   (mapv :position thread-group)

        position    (gpt/center-points positions)
        position    (cond-> position
                      (some? position-modifier)
                      (gpt/transform position-modifier))
        pos-x       (* (:x position) zoom)
        pos-y       (* (:y position) zoom)

        unread?     (some #(pos? (:count-unread-comments %)) thread-group)
        num-threads (str (count thread-group))

        test-id     (str/join "-" (map :seqn (sort-by :seqn thread-group)))

        on-click
        (mf/use-fn
         (mf/deps thread-group position zoom)
         (fn []
           (let [wl           (deref refs/workspace-local)
                 centered-wl  (dwv/calculate-centered-viewbox wl position)
                 updated-zoom (calculate-zoom-scale position zoom thread-group centered-wl)
                 scale-zoom   (/ updated-zoom zoom)]
             (st/emit! (dwv/update-viewport-position-center position)
                       (dwz/set-zoom position scale-zoom)))))]

    [:div {:style {:top (dm/str pos-y "px")
                   :left (dm/str pos-x "px")}
           :on-click on-click
           :class (stl/css :floating-preview-wrapper :floating-preview-bubble)}
     [:> comment-avatar*
      {:class (stl/css :avatar-lg)
       :variant (if unread? "unread" "read")
       :data-testid (dm/str "floating-thread-bubble-" test-id)}
      num-threads]]))

(mf/defc comment-floating-bubble*
  {::mf/wrap [mf/memo]}
  [{:keys [thread zoom is-open on-click origin position-modifier]}]
  (let [owner        (mf/with-memo [thread]