diff --git a/superset-frontend/src/hooks/useTabId.ts b/superset-frontend/src/hooks/useTabId.ts index 1bd0df3a36aa7..4f60763c88875 100644 --- a/superset-frontend/src/hooks/useTabId.ts +++ b/superset-frontend/src/hooks/useTabId.ts @@ -17,6 +17,7 @@ * under the License. */ import { useEffect, useState } from 'react'; +import shortid from 'shortid'; import { BroadcastChannel } from 'broadcast-channel'; interface TabIdChannelMessage { @@ -32,7 +33,21 @@ const channel = new BroadcastChannel('tab_id_channel'); export function useTabId() { const [tabId, setTabId] = useState(); + function isStorageAvailable() { + try { + return window.localStorage && window.sessionStorage; + } catch (error) { + return false; + } + } useEffect(() => { + if (!isStorageAvailable()) { + if (!tabId) { + setTabId(shortid.generate()); + } + return; + } + const updateTabId = () => { const lastTabId = window.localStorage.getItem('last_tab_id'); const newTabId = String(