[Fixes: #11545] Don't update browser if nil

Fixes: #11545
Fixes: #11544

The two issues were caused by the same bug, essentially if
`navigation-state-changed` event was fired (it's debounced) when the tab
had been closed, the browser would be updated with a `nil` id, causing
all sort of issues as it had not history etc.

This commit ensures that no changes are made if the browser is nil.

Signed-off-by: Churikova Tetiana <churikova.tm@gmail.com>
This commit is contained in:
Andrea Maria Piana 2020-12-16 10:07:42 +01:00 committed by Churikova Tetiana
parent 5643c4d537
commit 9fe7ddaf0b
No known key found for this signature in database
GPG Key ID: 0D4EA7B33B47E6D8
1 changed files with 10 additions and 9 deletions

View File

@ -189,12 +189,13 @@
[cofx browser url]
(let [history-index (:history-index browser)
history (:history browser)]
(let [new-history (conj (subvec history 0 (inc history-index)) url)
new-index (dec (count new-history))]
(update-browser cofx
(assoc browser
:history new-history
:history-index new-index)))))
(when history
(let [new-history (conj (subvec history 0 (inc history-index)) url)
new-index (dec (count new-history))]
(update-browser cofx
(assoc browser
:history new-history
:history-index new-index))))))
(defmulti storage-gateway :namespace)
@ -251,7 +252,7 @@
(let [browser (get-current-browser (:db cofx))
options (get-in cofx [:db :browser/options])
current-url (:url options)]
(when (and (not (string/blank? url)) (not= "about:blank" url) (not= current-url url) (not= (str current-url "/") url))
(when (and browser (not (string/blank? url)) (not= "about:blank" url) (not= current-url url) (not= (str current-url "/") url))
(let [resolved-ens (first (filter (fn [v]
(not= (.indexOf ^js url (second v)) -1))
(:resolved-ens options)))
@ -266,7 +267,7 @@
(fx/defn update-browser-name
[cofx title]
(let [browser (get-current-browser (:db cofx))]
(when (and (not (:dapp? browser)) title (not (string/blank? title)))
(when (and browser (not (:dapp? browser)) title (not (string/blank? title)))
(update-browser cofx (assoc browser :name title)))))
(fx/defn navigation-state-changed
@ -515,4 +516,4 @@
{:events [:browser.ui/open-empty-tab]}
[cofx]
(debounce/clear :browser/navigation-state-changed)
(navigation/navigate-to-cofx cofx :empty-tab nil))
(navigation/navigate-to-cofx cofx :empty-tab nil))