Skip to content

Commit

Permalink
avoid infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Lily Kuang committed Aug 23, 2022
1 parent b1e0f2b commit ccaf011
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions superset-frontend/src/hooks/useTabId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,24 @@ export function useTabId() {
}
}
useEffect(() => {
const updateTabId = () => {
if (isStorageAvailable()) {
const lastTabId = window.localStorage.getItem('last_tab_id');
const newTabId = String(
lastTabId ? Number.parseInt(lastTabId, 10) + 1 : 1,
);
window.sessionStorage.setItem('tab_id', newTabId);
window.localStorage.setItem('last_tab_id', newTabId);
setTabId(newTabId);
} else {
if (!isStorageAvailable()) {
if (!tabId) {
setTabId(shortid.generate());
}
return;
}

const updateTabId = () => {
const lastTabId = window.localStorage.getItem('last_tab_id');
const newTabId = String(
lastTabId ? Number.parseInt(lastTabId, 10) + 1 : 1,
);
window.sessionStorage.setItem('tab_id', newTabId);
window.localStorage.setItem('last_tab_id', newTabId);
setTabId(newTabId);
};

const storedTabId =
isStorageAvailable() && window.sessionStorage.getItem('tab_id');
const storedTabId = window.sessionStorage.getItem('tab_id');
if (storedTabId) {
channel.postMessage({
type: 'REQUESTING_TAB_ID',
Expand Down

0 comments on commit ccaf011

Please sign in to comment.