From e3904fcf3c1d9de232ead1c78b0a336016d8c546 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Thu, 17 Aug 2023 14:04:18 -0600 Subject: [PATCH 1/3] Make sure only the active leader is managing the mapbox token --- src/libs/actions/MapboxToken.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/MapboxToken.js b/src/libs/actions/MapboxToken.js index 885930047817..eaf341394505 100644 --- a/src/libs/actions/MapboxToken.js +++ b/src/libs/actions/MapboxToken.js @@ -6,6 +6,7 @@ import lodashGet from 'lodash/get'; import ONYXKEYS from '../../ONYXKEYS'; import * as API from '../API'; import CONST from '../../CONST'; +import {isClientTheLeader} from '../ActiveClientManager'; let authToken; Onyx.connect({ @@ -66,6 +67,13 @@ const init = () => { * @param {String[]} [token.errors] */ callback: (token) => { + // Only the leader should be in charge of the mapbox token, or else when you have multiple tabs open, the Onyx connection fires multiple times + // and it sets up duplicate refresh timers. This would be a big waste of tokens. + if (!isClientTheLeader()) { + console.debug('[MapboxToken] This client is not the leader so ignoring onyx callback'); + return; + } + // If the user has logged out, don't do anything and ignore changes to the access token if (!authToken) { console.debug('[MapboxToken] Ignoring changes to token because user signed out'); @@ -76,7 +84,7 @@ const init = () => { // The API sets a token in Onyx with a 30 minute expiration. if (_.isEmpty(token)) { console.debug('[MapboxToken] Token does not exist so fetching one'); - API.write('GetMapboxAccessToken'); + API.read('GetMapboxAccessToken'); isCurrentlyFetchingToken = true; return; } From 9626828cbd808fe58368e4df49997abceb96d339 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Thu, 17 Aug 2023 14:25:53 -0600 Subject: [PATCH 2/3] Fix import --- src/libs/actions/MapboxToken.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/MapboxToken.js b/src/libs/actions/MapboxToken.js index eaf341394505..4b1d74dbb8d6 100644 --- a/src/libs/actions/MapboxToken.js +++ b/src/libs/actions/MapboxToken.js @@ -69,7 +69,7 @@ const init = () => { callback: (token) => { // Only the leader should be in charge of the mapbox token, or else when you have multiple tabs open, the Onyx connection fires multiple times // and it sets up duplicate refresh timers. This would be a big waste of tokens. - if (!isClientTheLeader()) { + if (!ActiveClientManager.isClientTheLeader()) { console.debug('[MapboxToken] This client is not the leader so ignoring onyx callback'); return; } From 66773f57b1f2a3f2d321ffe34c5d14c285166582 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Thu, 17 Aug 2023 14:26:05 -0600 Subject: [PATCH 3/3] Fix import for real --- src/libs/actions/MapboxToken.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/MapboxToken.js b/src/libs/actions/MapboxToken.js index 4b1d74dbb8d6..e1e643d0eabc 100644 --- a/src/libs/actions/MapboxToken.js +++ b/src/libs/actions/MapboxToken.js @@ -6,7 +6,7 @@ import lodashGet from 'lodash/get'; import ONYXKEYS from '../../ONYXKEYS'; import * as API from '../API'; import CONST from '../../CONST'; -import {isClientTheLeader} from '../ActiveClientManager'; +import * as ActiveClientManager from '../ActiveClientManager'; let authToken; Onyx.connect({