mirror of
https://github.com/penpot/penpot.git
synced 2025-05-25 22:06:11 +02:00
🐛 Fix race-condition on 404 states.
This commit is contained in:
parent
6722ca41bf
commit
9c1c755836
6 changed files with 46 additions and 49 deletions
|
@ -11,7 +11,6 @@
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.main.data.events :as ev]
|
[app.main.data.events :as ev]
|
||||||
[app.main.data.messages :as dm]
|
|
||||||
[app.main.data.users :as du]
|
[app.main.data.users :as du]
|
||||||
[app.main.sentry :as sentry]
|
[app.main.sentry :as sentry]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
@ -75,7 +74,7 @@
|
||||||
(st/emit! (rt/nav :auth-login))
|
(st/emit! (rt/nav :auth-login))
|
||||||
|
|
||||||
(nil? match)
|
(nil? match)
|
||||||
(st/emit! (dm/assign-exception {:type :not-found}))
|
(st/emit! (rt/assign-exception {:type :not-found}))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(st/emit! (rt/navigated match)))))
|
(st/emit! (rt/navigated match)))))
|
||||||
|
|
|
@ -128,12 +128,3 @@
|
||||||
:controls controls
|
:controls controls
|
||||||
:actions actions
|
:actions actions
|
||||||
:tag tag})))
|
:tag tag})))
|
||||||
|
|
||||||
(defn assign-exception
|
|
||||||
[error]
|
|
||||||
(ptk/reify ::assign-exception
|
|
||||||
ptk/UpdateEvent
|
|
||||||
(update [_ state]
|
|
||||||
(if (nil? error)
|
|
||||||
(dissoc state :exception)
|
|
||||||
(assoc state :exception error)))))
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
[app.main.data.users :as du]
|
[app.main.data.users :as du]
|
||||||
[app.main.sentry :as sentry]
|
[app.main.sentry :as sentry]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
[app.util.router :as rt]
|
||||||
[app.util.timers :as ts]
|
[app.util.timers :as ts]
|
||||||
[cljs.pprint :refer [pprint]]
|
[cljs.pprint :refer [pprint]]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
|
@ -34,7 +35,7 @@
|
||||||
(let [hint (ex-message error)
|
(let [hint (ex-message error)
|
||||||
msg (str "Internal Error: " hint)]
|
msg (str "Internal Error: " hint)]
|
||||||
(sentry/capture-exception error)
|
(sentry/capture-exception error)
|
||||||
(ts/schedule (st/emitf (dm/assign-exception error)))
|
(ts/schedule (st/emitf (rt/assign-exception error)))
|
||||||
|
|
||||||
(js/console.group msg)
|
(js/console.group msg)
|
||||||
(ex/ignoring (js/console.error error))
|
(ex/ignoring (js/console.error error))
|
||||||
|
@ -60,7 +61,7 @@
|
||||||
(defmethod ptk/handle-error ::exceptional-state
|
(defmethod ptk/handle-error ::exceptional-state
|
||||||
[error]
|
[error]
|
||||||
(ts/schedule
|
(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
|
;; Error that happens on an active bussines model validation does not
|
||||||
;; passes an validation (example: profile can't leave a team). From
|
;; passes an validation (example: profile can't leave a team). From
|
||||||
|
@ -149,7 +150,7 @@
|
||||||
(let [hint (ex-message error)
|
(let [hint (ex-message error)
|
||||||
msg (str "Unhandled Internal Error: " hint)]
|
msg (str "Unhandled Internal Error: " hint)]
|
||||||
(sentry/capture-exception error)
|
(sentry/capture-exception error)
|
||||||
(ts/schedule (st/emitf (dm/assign-exception error)))
|
(ts/schedule (st/emitf (rt/assign-exception error)))
|
||||||
(js/console.group msg)
|
(js/console.group msg)
|
||||||
(ex/ignoring (js/console.error error))
|
(ex/ignoring (js/console.error error))
|
||||||
(js/console.groupEnd msg))))]
|
(js/console.groupEnd msg))))]
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.main.data.messages :as dm]
|
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
[app.main.ui.auth :refer [auth]]
|
[app.main.ui.auth :refer [auth]]
|
||||||
|
@ -25,6 +24,7 @@
|
||||||
[app.main.ui.static :as static]
|
[app.main.ui.static :as static]
|
||||||
[app.main.ui.viewer :as viewer]
|
[app.main.ui.viewer :as viewer]
|
||||||
[app.main.ui.workspace :as workspace]
|
[app.main.ui.workspace :as workspace]
|
||||||
|
[app.util.router :as rt]
|
||||||
[cljs.spec.alpha :as s]
|
[cljs.spec.alpha :as s]
|
||||||
[potok.core :as ptk]
|
[potok.core :as ptk]
|
||||||
[rumext.alpha :as mf]))
|
[rumext.alpha :as mf]))
|
||||||
|
@ -91,7 +91,7 @@
|
||||||
|
|
||||||
(mf/defc on-main-error
|
(mf/defc on-main-error
|
||||||
[{:keys [error] :as props}]
|
[{: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"])
|
[:span "Internal application errror"])
|
||||||
|
|
||||||
(mf/defc main-page
|
(mf/defc main-page
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
(ns app.main.ui.static
|
(ns app.main.ui.static
|
||||||
(:require
|
(:require
|
||||||
[app.main.data.messages :as dm]
|
|
||||||
[app.main.data.users :as du]
|
[app.main.data.users :as du]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
[app.main.store :as st]
|
[app.main.store :as st]
|
||||||
|
@ -72,7 +71,7 @@
|
||||||
[:div.desc-message (tr "labels.internal-error.desc-message")]
|
[:div.desc-message (tr "labels.internal-error.desc-message")]
|
||||||
[:div.sign-info
|
[:div.sign-info
|
||||||
[:a.btn-primary.btn-small
|
[:a.btn-primary.btn-small
|
||||||
{:on-click (st/emitf (dm/assign-exception nil))}
|
{:on-click (st/emitf (rt/assign-exception nil))}
|
||||||
(tr "labels.retry")]]])
|
(tr "labels.retry")]]])
|
||||||
|
|
||||||
(mf/defc exception-page
|
(mf/defc exception-page
|
||||||
|
|
|
@ -21,12 +21,12 @@
|
||||||
|
|
||||||
(defn resolve
|
(defn resolve
|
||||||
([router id] (resolve router id {} {}))
|
([router id] (resolve router id {} {}))
|
||||||
([router id params] (resolve router id params {}))
|
([router id path-params] (resolve router id path-params {}))
|
||||||
([router id params qparams]
|
([router id path-params query-params]
|
||||||
(when-let [match (r/match-by-name router id params)]
|
(when-let [match (r/match-by-name router id path-params)]
|
||||||
(if (empty? qparams)
|
(if (empty? query-params)
|
||||||
(r/match->path match)
|
(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))
|
(-> (u/uri (r/match->path match))
|
||||||
(assoc :query query)
|
(assoc :query query)
|
||||||
(str)))))))
|
(str)))))))
|
||||||
|
@ -48,12 +48,12 @@
|
||||||
[router path]
|
[router path]
|
||||||
(let [uri (u/uri path)]
|
(let [uri (u/uri path)]
|
||||||
(when-let [match (r/match-by-path router (:path uri))]
|
(when-let [match (r/match-by-path router (:path uri))]
|
||||||
(let [qparams (u/query-string->map (:query uri))
|
(let [query-params (u/query-string->map (:query uri))
|
||||||
params {:path (:path-params match)
|
params {:path (:path-params match)
|
||||||
:query qparams}]
|
:query query-params}]
|
||||||
(-> match
|
(-> match
|
||||||
(assoc :params params)
|
(assoc :params params)
|
||||||
(assoc :query-params qparams))))))
|
(assoc :query-params query-params))))))
|
||||||
|
|
||||||
;; --- Navigate (Event)
|
;; --- Navigate (Event)
|
||||||
|
|
||||||
|
@ -65,58 +65,65 @@
|
||||||
|
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(assoc state :route match))))
|
(-> state
|
||||||
|
(assoc :route match)
|
||||||
|
(dissoc :exception)))))
|
||||||
|
|
||||||
(defn navigate*
|
(defn navigate*
|
||||||
[id params qparams replace]
|
[id path-params query-params replace]
|
||||||
(ptk/reify ::navigate
|
(ptk/reify ::navigate
|
||||||
IDeref
|
IDeref
|
||||||
(-deref [_]
|
(-deref [_]
|
||||||
{:id id
|
{:id id
|
||||||
:path-params params
|
:path-params path-params
|
||||||
:query-params qparams
|
:query-params query-params
|
||||||
:replace replace})
|
:replace replace})
|
||||||
|
|
||||||
ptk/UpdateEvent
|
|
||||||
(update [_ state]
|
|
||||||
(dissoc state :exception))
|
|
||||||
|
|
||||||
ptk/EffectEvent
|
ptk/EffectEvent
|
||||||
(effect [_ state _]
|
(effect [_ state _]
|
||||||
(ts/asap
|
(let [router (:router state)
|
||||||
#(let [router (:router state)
|
history (:history state)
|
||||||
history (:history state)
|
path (resolve router id path-params query-params)]
|
||||||
path (resolve router id params qparams)]
|
(ts/asap
|
||||||
(if ^boolean replace
|
#(if ^boolean replace
|
||||||
(bhistory/replace-token! history path)
|
(bhistory/replace-token! history path)
|
||||||
(bhistory/set-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
|
(defn nav
|
||||||
([id] (nav id nil nil))
|
([id] (nav id nil nil))
|
||||||
([id params] (nav id params nil))
|
([id path-params] (nav id path-params nil))
|
||||||
([id params qparams] (navigate* id params qparams false)))
|
([id path-params query-params] (navigate* id path-params query-params false)))
|
||||||
|
|
||||||
(defn nav'
|
(defn nav'
|
||||||
([id] (nav id nil nil))
|
([id] (nav id nil nil))
|
||||||
([id params] (nav id params nil))
|
([id path-params] (nav id path-params nil))
|
||||||
([id params qparams] (navigate* id params qparams true)))
|
([id path-params query-params] (navigate* id path-params query-params true)))
|
||||||
|
|
||||||
(def navigate nav)
|
(def navigate nav)
|
||||||
|
|
||||||
(deftype NavigateNewWindow [id params qparams]
|
(deftype NavigateNewWindow [id path-params query-params]
|
||||||
ptk/EffectEvent
|
ptk/EffectEvent
|
||||||
(effect [_ state _]
|
(effect [_ state _]
|
||||||
(let [router (:router 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)
|
uri (-> (u/uri cfg/public-uri)
|
||||||
(assoc :fragment path))
|
(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))))
|
(dom/open-new-window (str uri) name))))
|
||||||
|
|
||||||
(defn nav-new-window
|
(defn nav-new-window
|
||||||
([id] (nav-new-window id nil nil))
|
([id] (nav-new-window id nil nil))
|
||||||
([id params] (nav-new-window id params nil))
|
([id path-params] (nav-new-window id path-params nil))
|
||||||
([id params qparams] (NavigateNewWindow. id params qparams)))
|
([id path-params query-params] (NavigateNewWindow. id path-params query-params)))
|
||||||
|
|
||||||
(defn nav-new-window*
|
(defn nav-new-window*
|
||||||
[{:keys [rname path-params query-params name]}]
|
[{:keys [rname path-params query-params name]}]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue