Skip to content

Commit

Permalink
fix(theme-common): localStorage utils dispatch too many storage event…
Browse files Browse the repository at this point in the history
…s leading to infinite loop (#8619)
  • Loading branch information
slorber authored Feb 2, 2023
1 parent 140f0b1 commit 5b05c0e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/docusaurus-theme-common/src/utils/storageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ function dispatchChangeEvent({
newValue: string | null;
storage: Storage;
}) {
// If we set multiple times the same storage value, events should not be fired
// The native events behave this way, so our manual event dispatch should
// rather behave exactly the same. Not doing so might create infinite loops.
// See https://github.com/facebook/docusaurus/issues/8594
if (oldValue === newValue) {
return;
}
const event = document.createEvent('StorageEvent');
event.initStorageEvent(
'storage',
Expand Down

0 comments on commit 5b05c0e

Please sign in to comment.