From 7ec5dfcdf27cf3f8681a0e161129d1ae49954243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Gran=C3=A1t?= Date: Wed, 17 Apr 2024 09:36:36 +0200 Subject: [PATCH] fix: bug when there are iframes --- src/content/contentScript.ts | 2 -- src/popup/useDetectorForm.tsx | 21 ++++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/content/contentScript.ts b/src/content/contentScript.ts index dd9691f..9b7c6ee 100644 --- a/src/content/contentScript.ts +++ b/src/content/contentScript.ts @@ -56,8 +56,6 @@ messages.startRuntimeListening(); messages.listenRuntime('DETECT_TOLGEE', async () => { if (configuration) { messages.sendToPlugin('TOLGEE_CONFIG_LOADED', configuration); - } else { - messages.sendToPlugin('TOLGEE_CONFIG_NOT_LOADED'); } }); diff --git a/src/popup/useDetectorForm.tsx b/src/popup/useDetectorForm.tsx index df68cbb..ad05c8d 100644 --- a/src/popup/useDetectorForm.tsx +++ b/src/popup/useDetectorForm.tsx @@ -167,6 +167,22 @@ export const useDetectorForm = () => { }); }, []); + // timeout when Tolgee is not detected + useEffect(() => { + if (!state.libConfig) { + const timer = setTimeout( + () => + dispatch({ + type: 'CHANGE_LIB_CONFIG', + payload: { frameId: null, libData: null }, + }), + 300 + ); + return () => clearTimeout(timer); + } + return undefined; + }, [state.libConfig]); + // after tolgee config is loaded // get applied values and stored values const onLibConfigChange = async () => { @@ -199,11 +215,6 @@ export const useDetectorForm = () => { type: 'CHANGE_LIB_CONFIG', payload: { libData: data, frameId: frameId || null }, }); - } else if (type === 'TOLGEE_CONFIG_NOT_LOADED') { - dispatch({ - type: 'CHANGE_LIB_CONFIG', - payload: { libData: null, frameId: null }, - }); } }; chrome.runtime.onMessage.addListener(listener);