From 604e30b3f089f9592bef03381b0dea5dd5b70f78 Mon Sep 17 00:00:00 2001 From: Lily Kuang Date: Wed, 24 Aug 2022 09:38:20 -0700 Subject: [PATCH] fix: Filter throwing an error on Embedded Dashboard (#21157) * fix: Filter throwing an error on Embedded Dashboard * use short_id if storage not available * avoid infinite loop --- superset-frontend/src/hooks/useTabId.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/superset-frontend/src/hooks/useTabId.ts b/superset-frontend/src/hooks/useTabId.ts index 1bd0df3a36aa..4f60763c8887 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(