From b7de90e41819973665aec5a533bfc5f1d6df846e Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 6 Sep 2026 06:53:39 -0700 Subject: [PATCH 1/2] fix(site): keep a refusal a browser would not store MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit readPreference fell back to the in-memory answer only when localStorage threw. A browser can let the read succeed and refuse the write — Safari's private mode and a full quota both do — and there the stored value came back null, so an explicit "Do not allow" was read as no answer at all: the banner stayed up and, outside a prior-consent country, the tag loaded anyway. The answer given on this page now governs it whenever storage has none of its own, however storage failed to keep it. Claude-Session: https://claude.ai/code/session_013MqwrF5NA179khDtEQdib5 --- site/src/components/Analytics.astro | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/site/src/components/Analytics.astro b/site/src/components/Analytics.astro index 58038bb07..0cda1127d 100644 --- a/site/src/components/Analytics.astro +++ b/site/src/components/Analytics.astro @@ -78,12 +78,17 @@ const enabled = Boolean(measurementId) && import.meta.env.PROD; function readPreference() { try { var stored = window.localStorage.getItem(STORAGE_KEY); - return stored === "granted" || stored === "denied" ? stored : null; + if (stored === "granted" || stored === "denied") return stored; } catch (_) { // A locked-down browser throws on access rather than returning - // null. The in-memory answer still governs this page. - return memoryPreference; + // null. } + // Storage had no answer, or would not give one. Either way the + // choice made on this page still governs it: a browser can let the + // read succeed and refuse the write — Safari's private mode and a + // full quota both do — and reading back null there would discard an + // explicit refusal and start measuring anyway. + return memoryPreference; } function writePreference(preference) { From 24ed258486b19d06b48b8c8dc8d43c9a5606834f Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Sun, 6 Sep 2026 06:58:20 -0700 Subject: [PATCH 2/2] fix(site): make a withdrawal reach the tabs already open This file has claimed since it was written that the preference is mirrored across tabs. Nothing did that. The storage listener lived inside subscribe, whose only caller is the privacy page's control, and that subscriber redraws its own status text rather than re-applying the preference. So a reader with a documentation page open who went to /privacy and denied kept being measured in the tab they left behind, until it happened to reload. Applying the preference on the storage event is what makes the claim true. Claude-Session: https://claude.ai/code/session_013MqwrF5NA179khDtEQdib5 --- site/src/components/Analytics.astro | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/site/src/components/Analytics.astro b/site/src/components/Analytics.astro index 0cda1127d..2cb022526 100644 --- a/site/src/components/Analytics.astro +++ b/site/src/components/Analytics.astro @@ -340,6 +340,17 @@ const enabled = Boolean(measurementId) && import.meta.env.PROD; }, }; + // Mirrored across tabs, which this file has claimed from the start and + // nothing did. The listener above reaches only subscribers, and the + // only subscriber is the privacy page's control, which redraws its own + // text. So a reader with a docs page open who went to /privacy and + // denied kept being measured in the tab they left behind until it + // happened to reload. Applying the preference here is what makes the + // claim true. + window.addEventListener("storage", function (event) { + if (event.key === STORAGE_KEY || event.key === null) apply(); + }); + function ready(run) { if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", run, { once: true });