Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
stramel authored Feb 12, 2021
1 parent 6e3eb78 commit bec2eb5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ function usePrimitiveFlags<F extends Flags>(

let latestFetchId: number;
const listener = async () => {
if (typeof document !== 'object' || document.visibilityState === 'hidden') return;

const fetchId = (latestFetchId = Date.now());

try {
Expand All @@ -390,9 +392,9 @@ function usePrimitiveFlags<F extends Flags>(
}
};

window.addEventListener('focus', listener);
window.addEventListener('visibilitychange', listener);
return () => {
window.removeEventListener('focus', listener);
window.removeEventListener('visibilitychange', listener);
};
}, [revalidateOnFocus, setFlags, userAttributes]);

Expand Down

0 comments on commit bec2eb5

Please sign in to comment.