[object Object]

← back to Apartmentwallpaper

fix(theme2): gate toggle visibility to theme2 only; persist storage only on valid ?theme= param

0dc58a00366349ff94ea0afba5f2694b11cf7ce7 · 2026-06-01 11:05:18 -0700 · SteveStudio2

Codex (claude-codex debate round 1) confirmed two theme2 bugs:
- toggle CSS matched any [data-page-theme], so ?theme=1 left it permanently
  visible, contradicting the hidden-until-theme2 intent
- if(fromUrl) persisted on any theme= param, letting an unrelated link with
  a garbage value rewrite the stored choice via the saved-fallback path

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Files touched

Diff

commit 0dc58a00366349ff94ea0afba5f2694b11cf7ce7
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date:   Mon Jun 1 11:05:18 2026 -0700

    fix(theme2): gate toggle visibility to theme2 only; persist storage only on valid ?theme= param
    
    Codex (claude-codex debate round 1) confirmed two theme2 bugs:
    - toggle CSS matched any [data-page-theme], so ?theme=1 left it permanently
      visible, contradicting the hidden-until-theme2 intent
    - if(fromUrl) persisted on any theme= param, letting an unrelated link with
      a garbage value rewrite the stored choice via the saved-fallback path
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
 public/index.html | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/public/index.html b/public/index.html
index 2ac5994..9dd84d3 100644
--- a/public/index.html
+++ b/public/index.html
@@ -244,14 +244,16 @@ textarea:focus-visible,
 (function(){
   var qs = new URLSearchParams(location.search);
   var fromUrl = qs.get('theme');
+  var urlTheme = (fromUrl === '2' || fromUrl === 'theme2') ? 'theme2'
+               : (fromUrl === '1' || fromUrl === 'theme1') ? 'theme1'
+               : null;
   var saved = null; try { saved = localStorage.getItem('wallco-page-theme'); } catch(e){}
-  var theme = null;
-  if (fromUrl === '2' || fromUrl === 'theme2') theme = 'theme2';
-  else if (fromUrl === '1' || fromUrl === 'theme1') theme = 'theme1';
-  else if (saved === 'theme2' || saved === 'theme1') theme = saved;
+  var theme = urlTheme || ((saved === 'theme2' || saved === 'theme1') ? saved : null);
   if (theme) {
     document.documentElement.setAttribute('data-page-theme', theme);
-    if (fromUrl) { try { localStorage.setItem('wallco-page-theme', theme); } catch(e){} }
+    // Persist only when the URL explicitly carried a VALID theme, so an
+    // unrelated link with ?theme=garbage can't silently rewrite the stored choice.
+    if (urlTheme) { try { localStorage.setItem('wallco-page-theme', urlTheme); } catch(e){} }
   }
 })();
 </script>
@@ -267,7 +269,7 @@ textarea:focus-visible,
     background:#fafafa !important; border:1px solid #e5e5e5 !important; box-shadow:none !important;
   }
   #page-theme-toggle{ display:none; }
-  [data-page-theme] #page-theme-toggle{ display:inline-flex; }
+  [data-page-theme="theme2"] #page-theme-toggle{ display:inline-flex; }
   #page-theme-toggle{
     position:fixed; top:96px; right:14px; z-index:90;
     gap:0; align-items:center;

← dc74f6b add noopener,noreferrer to sister-site window.open popup  ·  back to Apartmentwallpaper  ·  add afternic unlock/repoint script + passing unit tests (8/8 c86de10 →