0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-25 07:58:49 -05:00

🐛 Fix race-condition on 404 states.

This commit is contained in:
Andrey Antukh 2021-10-05 13:28:51 +02:00 committed by Andrés Moya
parent 6722ca41bf
commit 9c1c755836
6 changed files with 46 additions and 49 deletions

View file

@ -11,7 +11,6 @@
[app.common.uuid :as uuid]
[app.config :as cf]
[app.main.data.events :as ev]
[app.main.data.messages :as dm]
[app.main.data.users :as du]
[app.main.sentry :as sentry]
[app.main.store :as st]
@ -75,7 +74,7 @@
(st/emit! (rt/nav :auth-login))
(nil? match)
(st/emit! (dm/assign-exception {:type :not-found}))
(st/emit! (rt/assign-exception {:type :not-found}))
:else
(st/emit! (rt/navigated match)))))

View file

@ -128,12 +128,3 @@
:controls controls
:actions actions
:tag tag})))
(defn assign-exception
[error]
(ptk/reify ::assign-exception
ptk/UpdateEvent
(update [_ state]
(if (nil? error)
(dissoc state :exception)
(assoc state :exception error)))))

View file

@ -14,6 +14,7 @@
[app.main.data.users :as du]
[app.main.sentry :as sentry]
[app.main.store :as st]
[app.util.router :as rt]
[app.util.timers :as ts]
[cljs.pprint :refer [pprint]]
[cuerdas.core :as str]
@ -34,7 +35,7 @@
(let [hint (ex-message error)
msg (str "Internal Error: " hint)]
(sentry/capture-exception error)
(ts/schedule (st/emitf (dm/assign-exception error)))
(ts/schedule (st/emitf (rt/assign-exception error)))
(js/console.group msg)
(ex/ignoring (js/console.error error))
@ -60,7 +61,7 @@
(defmethod ptk/handle-error ::exceptional-state
[error]
(ts/schedule
(st/emitf (dm/assign-exception error))))
(st/emitf (rt/assign-exception error))))
;; Error that happens on an active bussines model validation does not
;; passes an validation (example: profile can't leave a team). From
@ -149,7 +150,7 @@
(let [hint (ex-message error)
msg (str "Unhandled Internal Error: " hint)]
(sentry/capture-exception error)
(ts/schedule (st/emitf (dm/assign-exception error)))
(ts/schedule (st/emitf (rt/assign-exception error)))
(js/console.group msg)
(ex/ignoring (js/console.error error))
(js/console.groupEnd msg))))]

View file

@ -8,7 +8,6 @@
(:require
[app.common.spec :as us]
[app.config :as cf]
[app.main.data.messages :as dm]
[app.main.refs :as refs]
[app.main.store :as st]
[app.main.ui.auth :refer [auth]]
@ -25,6 +24,7 @@
[app.main.ui.static :as static]
[app.main.ui.viewer :as viewer]
[app.main.ui.workspace :as workspace]
[app.util.router :as rt]
[cljs.spec.alpha :as s]
[potok.core :as ptk]
[rumext.alpha :as mf]))
@ -91,7 +91,7 @@
(mf/defc on-main-error
[{:keys [error] :as props}]
(mf/use-effect (st/emitf (dm/assign-exception error)))
(mf/use-effect (st/emitf (rt/assign-exception error)))
[:span "Internal application errror"])
(mf/defc main-page

View file

@ -6,7 +6,6 @@
(ns app.main.ui.static
(:require
[app.main.data.messages :as dm]
[app.main.data.users :as du]
[app.main.refs :as refs]
[app.main.store :as st]
@ -72,7 +71,7 @@
[:div.desc-message (tr "labels.internal-error.desc-message")]
[:div.sign-info
[:a.btn-primary.btn-small
{:on-click (st/emitf (dm/assign-exception nil))}
{:on-click (st/emitf (rt/assign-exception nil))}
(tr "labels.retry")]]])
(mf/defc exception-page

View file

@ -21,12 +21,12 @@
(defn resolve
([router id] (resolve router id {} {}))
([router id params] (resolve router id params {}))
([router id params qparams]
(when-let [match (r/match-by-name router id params)]
(if (empty? qparams)
([router id path-params] (resolve router id path-params {}))
([router id path-params query-params]
(when-let [match (r/match-by-name router id path-params)]
(if (empty? query-params)
(r/match->path match)
(let [query (u/map->query-string qparams)]
(let [query (u/map->query-string query-params)]
(-> (u/uri (r/match->path match))
(assoc :query query)
(str)))))))
@ -48,12 +48,12 @@
[router path]
(let [uri (u/uri path)]
(when-let [match (r/match-by-path router (:path uri))]
(let [qparams (u/query-string->map (:query uri))
params {:path (:path-params match)
:query qparams}]
(let [query-params (u/query-string->map (:query uri))
params {:path (:path-params match)
:query query-params}]
(-> match
(assoc :params params)
(assoc :query-params qparams))))))
(assoc :query-params query-params))))))
;; --- Navigate (Event)
@ -65,58 +65,65 @@
ptk/UpdateEvent
(update [_ state]
(assoc state :route match))))
(-> state
(assoc :route match)
(dissoc :exception)))))
(defn navigate*
[id params qparams replace]
[id path-params query-params replace]
(ptk/reify ::navigate
IDeref
(-deref [_]
{:id id
:path-params params
:query-params qparams
:path-params path-params
:query-params query-params
:replace replace})
ptk/UpdateEvent
(update [_ state]
(dissoc state :exception))
ptk/EffectEvent
(effect [_ state _]
(ts/asap
#(let [router (:router state)
history (:history state)
path (resolve router id params qparams)]
(if ^boolean replace
(let [router (:router state)
history (:history state)
path (resolve router id path-params query-params)]
(ts/asap
#(if ^boolean replace
(bhistory/replace-token! history path)
(bhistory/set-token! history path)))))))
(defn assign-exception
[error]
(ptk/reify ::assign-exception
ptk/UpdateEvent
(update [_ state]
(if (nil? error)
(dissoc state :exception)
(assoc state :exception error)))))
(defn nav
([id] (nav id nil nil))
([id params] (nav id params nil))
([id params qparams] (navigate* id params qparams false)))
([id path-params] (nav id path-params nil))
([id path-params query-params] (navigate* id path-params query-params false)))
(defn nav'
([id] (nav id nil nil))
([id params] (nav id params nil))
([id params qparams] (navigate* id params qparams true)))
([id path-params] (nav id path-params nil))
([id path-params query-params] (navigate* id path-params query-params true)))
(def navigate nav)
(deftype NavigateNewWindow [id params qparams]
(deftype NavigateNewWindow [id path-params query-params]
ptk/EffectEvent
(effect [_ state _]
(let [router (:router state)
path (resolve router id params qparams)
path (resolve router id path-params query-params)
uri (-> (u/uri cfg/public-uri)
(assoc :fragment path))
name (str (name id) "-" (:file-id params))]
name (str (name id) "-" (:file-id path-params))]
(dom/open-new-window (str uri) name))))
(defn nav-new-window
([id] (nav-new-window id nil nil))
([id params] (nav-new-window id params nil))
([id params qparams] (NavigateNewWindow. id params qparams)))
([id path-params] (nav-new-window id path-params nil))
([id path-params query-params] (NavigateNewWindow. id path-params query-params)))
(defn nav-new-window*
[{:keys [rname path-params query-params name]}]