From c96e0dafb9e46741032c993d0e124d4910f2d7d2 Mon Sep 17 00:00:00 2001 From: tyiuhc Date: Thu, 17 Oct 2024 14:49:39 -0700 Subject: [PATCH] temp fix for unit test --- packages/experiment-tag/src/experiment.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/experiment-tag/src/experiment.ts b/packages/experiment-tag/src/experiment.ts index 05012ca..a56e61c 100644 --- a/packages/experiment-tag/src/experiment.ts +++ b/packages/experiment-tag/src/experiment.ts @@ -27,7 +27,7 @@ import { const appliedInjections: Set = new Set(); const appliedMutations: MutationController[] = []; -let previousUrl: string | undefined = undefined; +let previousUrl: string | undefined; // Cache to track exposure for the current URL, should be cleared on URL change let urlExposureCache: { [url: string]: { [key: string]: string | undefined } }; @@ -40,7 +40,7 @@ export const initializeExperiment = (apiKey: string, initialFlags: string) => { if (!isLocalStorageAvailable() || !globalScope) { return; } - // Clear the cache on initialization + previousUrl = undefined; urlExposureCache = {}; const experimentStorageName = `EXP_${apiKey.slice(0, 10)}`; let user: ExperimentUser; @@ -352,7 +352,7 @@ const exposureWithDedupe = (key: string, variant: Variant) => { const currentUrl = urlWithoutParamsAndAnchor(globalScope.location.href); // Initialize the cache if on a new URL - if (!urlExposureCache[currentUrl]) { + if (!urlExposureCache?.[currentUrl]) { urlExposureCache = {}; urlExposureCache[currentUrl] = {}; }