Skip to content

Commit 692bbda

Browse files
committed
fix(theme-common): localStorage utils dispatch too many storage events leading to infinite loop (#8619)
1 parent ce8e55b commit 692bbda

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/docusaurus-theme-common/src/utils/storageUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ function dispatchChangeEvent({
3131
newValue: string | null;
3232
storage: Storage;
3333
}) {
34+
// If we set multiple times the same storage value, events should not be fired
35+
// The native events behave this way, so our manual event dispatch should
36+
// rather behave exactly the same. Not doing so might create infinite loops.
37+
// See https://github.com/facebook/docusaurus/issues/8594
38+
if (oldValue === newValue) {
39+
return;
40+
}
3441
const event = document.createEvent('StorageEvent');
3542
event.initStorageEvent(
3643
'storage',

0 commit comments

Comments
 (0)