From 9fe7ddaf0b5547c9de9981558e301a216ee01fc5 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Wed, 16 Dec 2020 10:07:42 +0100 Subject: [PATCH] [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 --- src/status_im/browser/core.cljs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/status_im/browser/core.cljs b/src/status_im/browser/core.cljs index 034e40f8c4..fa7fdc2370 100644 --- a/src/status_im/browser/core.cljs +++ b/src/status_im/browser/core.cljs @@ -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)) \ No newline at end of file + (navigation/navigate-to-cofx cofx :empty-tab nil))