mirror of
https://github.com/penpot/penpot.git
synced 2026-06-09 17:02:05 +00:00
🐛 Fix del-page change constructed with nil id (#9990)
Guard against nil id and missing page in delete-page to prevent broken changes from being sent to the server. This can happen due to a race condition where the page is no longer present in the pages-index. Also add assertion in changes-builder/del-page as defense-in-depth. Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
parent
a57833f3cd
commit
6bf7c33c43
@ -311,10 +311,12 @@
|
||||
|
||||
(defn del-page
|
||||
[changes page]
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :del-page :id (:id page)})
|
||||
(update :undo-changes conj {:type :add-page :id (:id page) :page page})
|
||||
(apply-changes-local)))
|
||||
(let [page-id (:id page)]
|
||||
(assert (some? page-id) "page must have a valid :id")
|
||||
(-> changes
|
||||
(update :redo-changes conj {:type :del-page :id page-id})
|
||||
(update :undo-changes conj {:type :add-page :id page-id :page page})
|
||||
(apply-changes-local))))
|
||||
|
||||
(defn move-page
|
||||
[changes page-id index prev-index]
|
||||
|
||||
@ -379,15 +379,18 @@
|
||||
pages (:pages fdata)
|
||||
|
||||
index (d/index-of pages id)
|
||||
page (get pindex id)
|
||||
page (assoc page :index index)
|
||||
pages (filter #(not= % id) pages)
|
||||
page (get pindex id)]
|
||||
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data fdata)
|
||||
(delete-page-components page)
|
||||
(pcb/del-page page))]
|
||||
(if (nil? page)
|
||||
(rx/empty)
|
||||
(let [page (assoc page :index index)
|
||||
pages (filter #(not= % id) pages)
|
||||
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(when (= id (:current-page-id state))
|
||||
(dcm/go-to-workspace {:page-id (first pages)})))))))
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-library-data fdata)
|
||||
(delete-page-components page)
|
||||
(pcb/del-page page))]
|
||||
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(when (= id (:current-page-id state))
|
||||
(dcm/go-to-workspace {:page-id (first pages)})))))))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user