🐛 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:
Andrey Antukh 2026-06-02 17:23:13 +02:00 committed by GitHub
parent a57833f3cd
commit 6bf7c33c43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 14 deletions

View File

@ -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]

View File

@ -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)})))))))))