0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 02:28:18 -05:00

🐛 Fix race condition issues on workspace.

This commit is contained in:
Andrey Antukh 2021-12-09 16:49:06 +01:00
parent a3016b8400
commit 384f0a05c6
7 changed files with 58 additions and 45 deletions

View file

@ -266,12 +266,10 @@
(ptk/reify ::finalize-page
ptk/UpdateEvent
(update [_ state]
(let [page-id (or page-id (get-in state [:workspace-data :pages 0]))
local (-> (:workspace-local state)
(dissoc
:edition
:edit-path
:selected))]
(let [local (-> (:workspace-local state)
(dissoc :edition
:edit-path
:selected))]
(-> state
(assoc-in [:workspace-cache page-id] local)
(dissoc :current-page-id :workspace-local :trimmed-page :workspace-drawing))))))
@ -348,8 +346,7 @@
(declare purge-page)
(declare go-to-file)
;; TODO: properly handle positioning on undo.
;; TODO: for some reason, the page-id here in some circumstances is `nil`
(defn delete-page
[id]
(ptk/reify ::delete-page
@ -669,6 +666,7 @@
(watch [_ _ _]
(rx/of (dch/update-shapes [id] #(merge % attrs))))))
(defn start-rename-shape
[id]
(us/verify ::us/uuid id)

View file

@ -114,9 +114,9 @@
:changes changes}))))
(defn commit-changes
[{:keys [redo-changes undo-changes origin save-undo? file-id]
[{:keys [redo-changes undo-changes
origin save-undo? file-id]
:or {save-undo? true}}]
(log/debug :msg "commit-changes"
:js/redo-changes redo-changes
:js/undo-changes undo-changes)

View file

@ -31,6 +31,12 @@
(s/def ::set-of-string (s/every string? :kind set?))
(s/def ::ordered-set-of-uuid (s/every uuid? :kind d/ordered-set?))
(defn initialized?
"Check if the state is properly intialized in a workspace. This means
it has the `:current-page-id` and `:current-file-id` properly set."
[state]
(and (uuid? (:current-file-id state))
(uuid? (:current-page-id state))))
;; --- Helpers

View file

@ -136,7 +136,7 @@
(defn prepare-remove-group
[page-id group objects]
(let [shapes (:shapes group)
(let [shapes (into [] (:shapes group)) ; ensure we always have vector
parent-id (cp/get-parent (:id group) objects)
parent (get objects parent-id)

View file

@ -56,13 +56,14 @@
(rx/filter dch/commit-changes?)
(rx/debounce 2000)
(rx/merge stoper forcer))
local-file? #(as-> (:file-id %) event-file-id
(or (nil? event-file-id)
(= event-file-id file-id)))
library-file? #(as-> (:file-id %) event-file-id
(and (some? event-file-id)
(not= event-file-id file-id)))
local-file?
#(as-> (:file-id %) event-file-id
(or (nil? event-file-id)
(= event-file-id file-id)))
library-file?
#(as-> (:file-id %) event-file-id
(and (some? event-file-id)
(not= event-file-id file-id)))
on-dirty
(fn []
@ -565,6 +566,20 @@
[frame-id]
(ptk/event ::update-frame-thumbnail {:frame-id frame-id}))
(defn update-shape-thumbnail
"An event that is succeptible to be executed out of the main flow, so
it need to correctly handle the situation that there are no page-id
or file-is loaded."
[shape-id thumbnail-data]
(ptk/reify ::update-shape-thumbnail
ptk/WatchEvent
(watch [_ state _]
(when (and (dwc/initialized? state)
(uuid? shape-id))
(rx/of (dch/update-shapes [shape-id]
#(assoc % :thumbnail thumbnail-data)
{:save-undo? false}))))))
(defn- extract-frame-changes
"Process a changes set in a commit to extract the frames that are channging"
[[event [old-objects new-objects]]]

View file

@ -54,23 +54,23 @@
(ptk/reify ::finalize-editor-state
ptk/WatchEvent
(watch [_ state _]
(let [content (-> (get-in state [:workspace-editor-state id])
(ted/get-editor-current-content))]
(when (dwc/initialized? state)
(let [content (-> (get-in state [:workspace-editor-state id])
(ted/get-editor-current-content))]
(if (ted/content-has-text? content)
(let [content (d/merge (ted/export-content content)
(dissoc (:content shape) :children))]
(rx/merge
(rx/of (update-editor-state shape nil))
(when (and (not= content (:content shape))
(some? (:current-page-id state)))
(rx/of
(dch/update-shapes [id] #(assoc % :content content))
(dwu/commit-undo-transaction)))))
(if (ted/content-has-text? content)
(let [content (d/merge (ted/export-content content)
(dissoc (:content shape) :children))]
(rx/merge
(rx/of (update-editor-state shape nil))
(when (and (not= content (:content shape))
(some? (:current-page-id state)))
(rx/of
(dch/update-shapes [id] #(assoc % :content content))
(dwu/commit-undo-transaction)))))
(when (some? id)
(rx/of (dws/deselect-shape id)
(dwc/delete-shapes #{id}))))))))
(when (some? id)
(rx/of (dws/deselect-shape id)
(dwc/delete-shapes #{id})))))))))
(defn initialize-editor-state
[{:keys [id content] :as shape} decorator]

View file

@ -6,7 +6,6 @@
(ns app.main.ui.workspace.viewport.thumbnail-renderer
(:require
[app.main.data.workspace.changes :as dwc]
[app.main.data.workspace.persistence :as dwp]
[app.main.store :as st]
[app.util.dom :as dom]
@ -80,7 +79,7 @@
"Component in charge of creating thumbnails and storing them"
{::mf/wrap-props false}
[props]
(let [objects (obj/get props "objects")
(let [objects (obj/get props "objects")
background (obj/get props "background")
;; Id of the current frame being rendered
@ -97,12 +96,9 @@
updates-stream
(mf/use-memo
(fn []
(let [update-events
(->> st/stream
(rx/filter dwp/update-frame-thumbnail?))]
(->> (rx/zip update-events next)
(rx/map first)))))
#(let [update-events (rx/filter dwp/update-frame-thumbnail? st/stream)]
(->> (rx/zip update-events next)
(rx/map first))))
on-thumbnail-data
(mf/use-callback
@ -111,9 +107,7 @@
(reset! shape-id nil)
(timers/schedule
(fn []
(st/emit! (dwc/update-shapes [@shape-id]
#(assoc % :thumbnail data)
{:save-undo? false}))
(st/emit! (dwp/update-shape-thumbnail @shape-id data))
(rx/push! next :next)))))
on-frame-not-found