fix(theme-common): localStorage utils dispatch too many storage events leading to infinite loop (#8619)

This commit is contained in:
Sébastien Lorber 2023-02-02 15:39:40 +01:00 committed by GitHub
parent 140f0b1d4c
commit 5b05c0e73e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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',