🐛 Fix dependency libraries visible in UI after unlinking main library (#9511)

This commit is contained in:
Pablo Alba 2026-05-13 15:35:42 +02:00 committed by GitHub
parent 7617e42547
commit bf880467b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 4 deletions

View File

@ -125,6 +125,7 @@
- Fix `:heigth` typo in clipboard frame-same-size? (by @iot2edge) [Github #9250](https://github.com/penpot/penpot/pull/9250)
- Fix Settings and Notifications "Update Settings" button enabled state when form has no changes (by @moorsecopers99) [Github #9090](https://github.com/penpot/penpot/issues/9090)
- Fix library updates reappear after being applied and the file is reloaded [Taiga #14040](https://tree.taiga.io/project/penpot/issue/14040)
- Fix dependency libraries remaining visible in UI after unlinking main library [Taiga #14020](https://tree.taiga.io/project/penpot/issue/14020)
## 2.15.0 (Unreleased)

View File

@ -1558,6 +1558,27 @@
:variants-count variants-count
:library-used-in (:used-in library-usage)}))))))))))
(defn cleanup-unlinked-libraries
"Remove libraries from state that are no longer linked to the given file.
This is used after unlinking a library to clean up transitive dependencies."
[file-id libraries]
(ptk/reify ::cleanup-unlinked-libraries
ptk/UpdateEvent
(update [_ state]
(let [linked-ids (into #{} (map :id) libraries)]
(update state :files
(fn [files]
(reduce-kv
(fn [acc id file]
(if (and (= (:library-of file) file-id)
(not (contains? linked-ids id))
(not= id file-id))
(dissoc acc id)
acc))
files
files)))))))
(defn unlink-file-from-library
[file-id library-id]
(ptk/reify ::detach-library
@ -1573,7 +1594,11 @@
ptk/WatchEvent
(watch [_ _ _]
(let [params {:file-id file-id
:library-id library-id}]
(->> (rp/cmd! :unlink-file-from-library params)
(rx/ignore))))))
;; Unlink the library, then fetch the current list of linked libraries
;; and remove any that are no longer linked (e.g., transitive dependencies)
(->> (rp/cmd! :unlink-file-from-library {:file-id file-id :library-id library-id})
(rx/mapcat (fn [_]
(rp/cmd! :get-file-libraries {:file-id file-id})))
(rx/map (partial cleanup-unlinked-libraries file-id))))))