From 04fdaed772c883af34ff666c16bb3f3ffec10d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Mon, 11 May 2026 10:33:10 +0400 Subject: [PATCH] cookie-banner: clean up StorageDetector restore-on-stop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit localStorage and sessionStorage share Storage.prototype, so there is only one setItem to wrap and one to restore. The previous code kept a never-assigned originalSessionSetItem field and a dead second if branch that restored from a field already nulled out a few lines above. Collapse the two fields into a single originalSetItem and drop the dead branch. No behavioural change. Signed-off-by: Émile Ré --- .../src/detectors/storage-detector.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/cookie-banner/src/detectors/storage-detector.ts b/packages/cookie-banner/src/detectors/storage-detector.ts index 6a6f98c0c..06da6732c 100644 --- a/packages/cookie-banner/src/detectors/storage-detector.ts +++ b/packages/cookie-banner/src/detectors/storage-detector.ts @@ -37,8 +37,7 @@ export class StorageDetector implements Detector { private readonly reported: Set = new Set(); private readonly pending: Map = new Map(); private timer: ReturnType | null = null; - private originalLocalSetItem: typeof Storage.prototype.setItem | null = null; - private originalSessionSetItem: typeof Storage.prototype.setItem | null = null; + private originalSetItem: typeof Storage.prototype.setItem | null = null; private originalIDBOpen: typeof IDBFactory.prototype.open | null = null; constructor(baseUrl: URL, bannerId: string) { @@ -61,13 +60,9 @@ export class StorageDetector implements Detector { this.flush(); } - if (this.originalLocalSetItem) { - Storage.prototype.setItem = this.originalLocalSetItem; - this.originalLocalSetItem = null; - } - if (this.originalSessionSetItem) { - Storage.prototype.setItem = this.originalLocalSetItem ?? this.originalSessionSetItem!; - this.originalSessionSetItem = null; + if (this.originalSetItem) { + Storage.prototype.setItem = this.originalSetItem; + this.originalSetItem = null; } if (this.originalIDBOpen) { IDBFactory.prototype.open = this.originalIDBOpen; @@ -77,7 +72,7 @@ export class StorageDetector implements Detector { private wrapStorage(): void { const originalSetItem = Storage.prototype.setItem; - this.originalLocalSetItem = originalSetItem; + this.originalSetItem = originalSetItem; const self = this;