From 5ffb0f37e9f4e00d99c36b5d7774f825267462cd Mon Sep 17 00:00:00 2001 From: Panfilov Konstantin Date: Wed, 21 Oct 2026 20:50:25 +0300 Subject: [PATCH] =?UTF-8?q?fix(theme):=20=D0=B7=D0=B5=D1=80=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D1=82=D1=8C=20canonical=20cookie=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=BC=20boot=20(#13)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/theme-client.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/theme-client.php b/components/theme-client.php index 48ae94d..715ea10 100644 --- a/components/theme-client.php +++ b/components/theme-client.php @@ -11,7 +11,7 @@ $themeSurface = isset($themeSurface) && in_array($themeSurface, ['public', 'priv let shown = initial; const canonical = value => typeof value === 'string' && value.length <= 128 && /^v1:(light|dark):(manual|preland):[A-Za-z0-9_-]{16,64}(?![\s\S])/.test(value) ? value : null; const themeOf = value => value.split(':')[1]; - function read() { + function readCookie() { try { for (const part of document.cookie.split(';')) { const cookie = part.trim(); @@ -20,6 +20,11 @@ $themeSurface = isset($themeSurface) && in_array($themeSurface, ['public', 'priv if (value) return value; } } catch (_) {} + return null; + } + function read() { + const cookie = readCookie(); + if (cookie) return cookie; try { return canonical(window.localStorage.getItem(key)); } catch (_) { return null; } } function apply(theme) { @@ -66,5 +71,12 @@ $themeSurface = isset($themeSurface) && in_array($themeSurface, ['public', 'priv document.addEventListener('DOMContentLoaded', refresh); document.addEventListener('pjax:end', refresh); refresh(); + // Только первый boot зеркалит валидную cookie и уведомляет другие вкладки + // о server import. Read-only refresh/reinit не создают цикл storage events. + const bootCookie = readCookie(); + if (bootCookie) { + apply(themeOf(bootCookie)); + try { if (window.localStorage.getItem(key) !== bootCookie) window.localStorage.setItem(key, bootCookie); } catch (_) {} + } })(, );