Repository: penpot/penpot
File: frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs (ClojureScript)

Code before:
  (-> (l/in [:workspace-local :shape-for-rename])
      (l/derived st/state)))

(mf/defc layer-name*
  {::mf/wrap-props false
   ::mf/forward-ref true}
  [{:keys [shape-id shape-name is-shape-touched disabled-double-click
           on-start-edit on-stop-edit depth parent-size is-selected
           type-comp type-frame component-id is-hidden is-blocked
           variant-id variant-name variant-properties variant-error]} external-ref]
  (let [edition*         (mf/use-state false)
        edition?         (deref edition*)

        local-ref        (mf/use-ref)
        ref              (d/nilv external-ref local-ref)

        shape-for-rename (mf/deref lens:shape-for-rename)

        shape-name       (if variant-id
                           (d/nilv variant-error variant-name)
                           shape-name)

        default-value    (if variant-id
                           (if variant-error
                             variant-error
                             (ctv/properties-map->string variant-properties))
                           shape-name)

        has-path?        (str/includes? shape-name "/")

        start-edit
        (mf/use-fn
         (mf/deps disabled-double-click on-start-edit shape-id is-blocked)
         (fn []
           (when (and (not is-blocked)
                      (not disabled-double-click))
             (on-start-edit)
             (reset! edition* true)
             (st/emit! (dw/start-rename-shape shape-id)))))

        accept-edit
        (mf/use-fn
         (mf/deps shape-id on-stop-edit component-id variant-id variant-name variant-properties)
         (fn []
           (let [name-input     (mf/ref-val ref)
                 name           (str/trim (dom/get-value name-input))]
             (on-stop-edit)
             (reset! edition* false)
             (if variant-name
               (if (ctv/valid-properties-string? name)
                 (st/emit! (dwv/update-properties-names-and-values component-id variant-id variant-properties (ctv/properties-string->map name))

Review comment (performance):
```
(or variant-error (ctv/properties-map->string variant-properties))
```
Is shorter and more efficient

Code after:
  (-> (l/in [:workspace-local :shape-for-rename])
      (l/derived st/state)))

(mf/defc layer-name*
  {::mf/wrap-props false
   ::mf/forward-ref true}
  [{:keys [shape-id shape-name is-shape-touched disabled-double-click
           on-start-edit on-stop-edit depth parent-size is-selected
           type-comp type-frame component-id is-hidden is-blocked
           variant-id variant-name variant-properties variant-error]} external-ref]
  (let [edition*         (mf/use-state false)
        edition?         (deref edition*)

        local-ref        (mf/use-ref)
        ref              (d/nilv external-ref local-ref)

        shape-for-rename (mf/deref lens:shape-for-rename)

        shape-name       (if variant-id
                           (d/nilv variant-error variant-name)
                           shape-name)

        default-value    (if variant-id
                           (or variant-error (ctv/properties-map->string variant-properties))
                           shape-name)

        has-path?        (str/includes? shape-name "/")

        start-edit
        (mf/use-fn
         (mf/deps disabled-double-click on-start-edit shape-id is-blocked)
         (fn []
           (when (and (not is-blocked)
                      (not disabled-double-click))
             (on-start-edit)
             (reset! edition* true)
             (st/emit! (dw/start-rename-shape shape-id)))))

        accept-edit
        (mf/use-fn
         (mf/deps shape-id on-stop-edit component-id variant-id variant-name variant-properties)
         (fn []
           (let [name-input     (mf/ref-val ref)
                 name           (str/trim (dom/get-value name-input))]
             (on-stop-edit)
             (reset! edition* false)
             (if variant-name
               (if (ctv/valid-properties-string? name)
                 (st/emit! (dwv/update-properties-names-and-values component-id variant-id variant-properties (ctv/properties-string->map name))
                           (dwv/update-error component-id nil))
                 (st/emit! (dwv/update-properties-names-and-values component-id variant-id variant-properties {})