From bf880467b4980a245ad2e4225c8eb584b9f7bf45 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Wed, 13 May 2026 15:35:42 +0200 Subject: [PATCH] :bug: Fix dependency libraries visible in UI after unlinking main library (#9511) --- CHANGES.md | 1 + .../app/main/data/workspace/libraries.cljs | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 683cba1efd..6691112759 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 0685502a3c..5128f054d5 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -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)))))) + +