From 87a6266ddc07df23aeb01db1f26e060c2c3f567d Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Mon, 28 Feb 2022 14:53:11 +0530 Subject: [PATCH] fix: Add resetTriggered flag to fix reset loop (#4079) --- app/javascript/packs/sdk.js | 3 +++ app/javascript/sdk/IFrameHelper.js | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/javascript/packs/sdk.js b/app/javascript/packs/sdk.js index c4bfcdb08..66f6ba790 100755 --- a/app/javascript/packs/sdk.js +++ b/app/javascript/packs/sdk.js @@ -25,6 +25,7 @@ const runSDK = ({ baseUrl, websiteToken }) => { launcherTitle: chatwootSettings.launcherTitle || '', showPopoutButton: chatwootSettings.showPopoutButton || false, widgetStyle: chatwootSettings.widgetStyle || 'standard', + resetTriggered: false, toggle(state) { IFrameHelper.events.toggleBubble(state); @@ -100,6 +101,8 @@ const runSDK = ({ baseUrl, websiteToken }) => { baseUrl: window.$chatwoot.baseUrl, websiteToken: window.$chatwoot.websiteToken, }); + + window.$chatwoot.resetTriggered = true; }, }; diff --git a/app/javascript/sdk/IFrameHelper.js b/app/javascript/sdk/IFrameHelper.js index 2d851ba49..94d91f77f 100644 --- a/app/javascript/sdk/IFrameHelper.js +++ b/app/javascript/sdk/IFrameHelper.js @@ -136,7 +136,9 @@ export const IFrameHelper = { if (window.$chatwoot.user) { IFrameHelper.sendMessage('set-user', window.$chatwoot.user); } - dispatchWindowEvent({ eventName: CHATWOOT_READY }); + if (!window.$chatwoot.resetTriggered) { + dispatchWindowEvent({ eventName: CHATWOOT_READY }); + } }, error: ({ errorType, data }) => { dispatchWindowEvent({ eventName: CHATWOOT_ERROR, data: data });