Skip to content

Commit

Permalink
fix: Filter throwing an error on Embedded Dashboard (#21157)
Browse files Browse the repository at this point in the history
* fix: Filter throwing an error on Embedded Dashboard

* use short_id if storage not available

* avoid infinite loop
  • Loading branch information
lilykuang committed Aug 24, 2022
1 parent 53de94c commit 604e30b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions superset-frontend/src/hooks/useTabId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import { useEffect, useState } from 'react';
import shortid from 'shortid';
import { BroadcastChannel } from 'broadcast-channel';

interface TabIdChannelMessage {
Expand All @@ -32,7 +33,21 @@ const channel = new BroadcastChannel<TabIdChannelMessage>('tab_id_channel');
export function useTabId() {
const [tabId, setTabId] = useState<string>();

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(
Expand Down

0 comments on commit 604e30b

Please sign in to comment.