From 3855c82f8e6b933e01068fa7e5a5e39602a89bce Mon Sep 17 00:00:00 2001 From: Ritul Date: Fri, 27 Mar 2026 01:15:14 +0530 Subject: [PATCH] Another runtime context issue fix --- client/src/utils/runtimeContext.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/client/src/utils/runtimeContext.js b/client/src/utils/runtimeContext.js index fab55fb..fed9ead 100644 --- a/client/src/utils/runtimeContext.js +++ b/client/src/utils/runtimeContext.js @@ -4,6 +4,7 @@ const COMPANY_ID_QUERY_KEYS = [ 'blt-gtw-fc-cid', 'bltt-gtw-f-c-cid', ]; +const COMPANY_ID_STORAGE_KEY = 'sms_runtime_company_id'; function getRuntimeUrl() { if (typeof window === 'undefined') return null; @@ -30,6 +31,26 @@ function getPathMatch(pathname, regex) { return match?.[1] || ''; } +function readStoredCompanyId() { + if (typeof sessionStorage === 'undefined') return ''; + + try { + return (sessionStorage.getItem(COMPANY_ID_STORAGE_KEY) || '').trim(); + } catch { + return ''; + } +} + +function persistCompanyId(companyId) { + if (!companyId || typeof sessionStorage === 'undefined') return; + + try { + sessionStorage.setItem(COMPANY_ID_STORAGE_KEY, companyId); + } catch { + // Ignore storage errors; URL/referrer extraction still works for the current request. + } +} + function getFirstSearchParam(url, keys) { if (!url) return ''; @@ -44,14 +65,17 @@ function getFirstSearchParam(url, keys) { export function getRuntimeCompanyId() { const runtimeUrl = getRuntimeUrl(); const referrerUrl = getReferrerUrl(); - - return ( + const companyId = ( getFirstSearchParam(runtimeUrl, COMPANY_ID_QUERY_KEYS) || getPathMatch(runtimeUrl?.pathname || '', /\/company\/([^/]+)/i) || getFirstSearchParam(referrerUrl, COMPANY_ID_QUERY_KEYS) || getPathMatch(referrerUrl?.pathname || '', /\/company\/([^/]+)/i) + || readStoredCompanyId() || '' ); + + persistCompanyId(companyId); + return companyId; } export function getRuntimeApplicationId() {