diff --git a/app/javascript/react-components/src/components/ChatwootProvider.jsx b/app/javascript/react-components/src/components/ChatwootProvider.jsx index 5470bc89912..785ef0d97f5 100644 --- a/app/javascript/react-components/src/components/ChatwootProvider.jsx +++ b/app/javascript/react-components/src/components/ChatwootProvider.jsx @@ -78,7 +78,14 @@ export const ChatwootProvider = ({ window.axios = createAxios(axios); // Initialize user in store and ActionCable - store.dispatch('setUser').then(() => { + store.dispatch('setUser').then(async () => { + // Fetch inboxes once per session. Guarded against the shared Vuex store + // so remounting the provider (e.g. when the consumer re-keys per + // conversation) doesn't trigger redundant /inboxes requests. + const hasInboxes = store.getters['inboxes/getInboxes'].length > 0; + if (!hasInboxes) { + await store.dispatch('inboxes/get'); + } vueActionCable.init(store, config.pubsubToken); setInitializationComplete(true); }); diff --git a/app/javascript/ui/MessageList.vue b/app/javascript/ui/MessageList.vue index 284f0421fe4..6a0d9ce84b9 100644 --- a/app/javascript/ui/MessageList.vue +++ b/app/javascript/ui/MessageList.vue @@ -74,7 +74,6 @@ const fetchMore = async () => { }; onMounted(async () => { - await store.dispatch('inboxes/get'); await Promise.all([ store.dispatch('getConversation', conversationId.value), store.dispatch('fetchAllAttachments', conversationId.value),