mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
fix(theme-common): localStorage utils dispatch too many storage events leading to infinite loop (#8619)
This commit is contained in:
parent
140f0b1d4c
commit
5b05c0e73e
1 changed files with 7 additions and 0 deletions
|
@ -31,6 +31,13 @@ function dispatchChangeEvent({
|
||||||
newValue: string | null;
|
newValue: string | null;
|
||||||
storage: Storage;
|
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');
|
const event = document.createEvent('StorageEvent');
|
||||||
event.initStorageEvent(
|
event.initStorageEvent(
|
||||||
'storage',
|
'storage',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue