From 692bbdad64dcca9a5113a759b8afce6415a25798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Thu, 2 Feb 2023 15:39:40 +0100 Subject: [PATCH] fix(theme-common): localStorage utils dispatch too many storage events leading to infinite loop (#8619) --- packages/docusaurus-theme-common/src/utils/storageUtils.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/docusaurus-theme-common/src/utils/storageUtils.ts b/packages/docusaurus-theme-common/src/utils/storageUtils.ts index c668cfaa4fff..dacfa1632b28 100644 --- a/packages/docusaurus-theme-common/src/utils/storageUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/storageUtils.ts @@ -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',