mirror of
https://github.com/penpot/penpot.git
synced 2026-09-11 06:28:47 +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
|
(defn del-page
|
||||||
[changes page]
|
[changes page]
|
||||||
(-> changes
|
(let [page-id (:id page)]
|
||||||
(update :redo-changes conj {:type :del-page :id (:id page)})
|
(assert (some? page-id) "page must have a valid :id")
|
||||||
(update :undo-changes conj {:type :add-page :id (:id page) :page page})
|
(-> changes
|
||||||
(apply-changes-local)))
|
(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
|
(defn move-page
|
||||||
[changes page-id index prev-index]
|
[changes page-id index prev-index]
|
||||||
|
|||||||
@ -379,15 +379,18 @@
|
|||||||
pages (:pages fdata)
|
pages (:pages fdata)
|
||||||
|
|
||||||
index (d/index-of pages id)
|
index (d/index-of pages id)
|
||||||
page (get pindex id)
|
page (get pindex id)]
|
||||||
page (assoc page :index index)
|
|
||||||
pages (filter #(not= % id) pages)
|
|
||||||
|
|
||||||
changes (-> (pcb/empty-changes it)
|
(if (nil? page)
|
||||||
(pcb/with-library-data fdata)
|
(rx/empty)
|
||||||
(delete-page-components page)
|
(let [page (assoc page :index index)
|
||||||
(pcb/del-page page))]
|
pages (filter #(not= % id) pages)
|
||||||
|
|
||||||
(rx/of (dch/commit-changes changes)
|
changes (-> (pcb/empty-changes it)
|
||||||
(when (= id (:current-page-id state))
|
(pcb/with-library-data fdata)
|
||||||
(dcm/go-to-workspace {:page-id (first pages)})))))))
|
(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