[object Object]

← back to Wallco Ai

/hot-or-not: fix window.history shadow + backtick-in-comment

48475ee440cd49a4880a9cff718752c4d1fd03c1 · 2026-05-11 23:45:15 -0700 · SteveStudio2

Steve's mobile login surfaced two bugs.

BUG 1 — 'history.unshift is not a function'
  My JS declared 'var history = []' which got shadowed by the
  built-in window.history (the browser History API). Tapping HOT/NOT
  threw on every action — votes still posted (streak updated) but
  the recent-picks strip never populated and the next-card load
  was skipped because the error halted execution.

  Fix: renamed to 'picks' throughout the /hot-or-not script.

BUG 2 — backticks inside a JS comment closed the template literal
  My first replacement put '`picks` not `history`' in a /* comment */
  which contained backticks. Since the entire /hot-or-not response
  is wrapped in a template literal at server.js top level, those
  backticks prematurely closed the string and Node threw
  'SyntaxError: missing ) after argument list' at startup.

  Fix: removed the backticks from the comment.

REAL MOBILE RETEST (iPhone 14 viewport via Playwright trusted input):
  /swipe 5 drags (R/L/U/R/R) → 5 distinct cards, streak 🔥 3
  /hot-or-not 5 taps        → 5 distinct cards, history strip 5 items
  /poll 3 votes              → leaderboard updates, 20 cards
  /design/13 ≡ → modal opens, COLOR shows 14 dots, ★5 star → 'avg ★5 from 2'
  Total: 10 gestures, 9 unique card IDs touched.

Files touched

Diff

commit 48475ee440cd49a4880a9cff718752c4d1fd03c1
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date:   Mon May 11 23:45:15 2026 -0700

    /hot-or-not: fix window.history shadow + backtick-in-comment
    
    Steve's mobile login surfaced two bugs.
    
    BUG 1 — 'history.unshift is not a function'
      My JS declared 'var history = []' which got shadowed by the
      built-in window.history (the browser History API). Tapping HOT/NOT
      threw on every action — votes still posted (streak updated) but
      the recent-picks strip never populated and the next-card load
      was skipped because the error halted execution.
    
      Fix: renamed to 'picks' throughout the /hot-or-not script.
    
    BUG 2 — backticks inside a JS comment closed the template literal
      My first replacement put '`picks` not `history`' in a /* comment */
      which contained backticks. Since the entire /hot-or-not response
      is wrapped in a template literal at server.js top level, those
      backticks prematurely closed the string and Node threw
      'SyntaxError: missing ) after argument list' at startup.
    
      Fix: removed the backticks from the comment.
    
    REAL MOBILE RETEST (iPhone 14 viewport via Playwright trusted input):
      /swipe 5 drags (R/L/U/R/R) → 5 distinct cards, streak 🔥 3
      /hot-or-not 5 taps        → 5 distinct cards, history strip 5 items
      /poll 3 votes              → leaderboard updates, 20 cards
      /design/13 ≡ → modal opens, COLOR shows 14 dots, ★5 star → 'avg ★5 from 2'
      Total: 10 gestures, 9 unique card IDs touched.
---
 server.js | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/server.js b/server.js
index d78d87a..21094ce 100644
--- a/server.js
+++ b/server.js
@@ -6410,7 +6410,7 @@ ${FOOTER}
   .hist-card.skip img { border-color:#888 }
 </style>
 <script>
-var seen = [], history = [];
+var seen = [], picks = [];  /* named picks because window.history shadows a global */
 var streak = parseInt(localStorage.getItem('wc-streak') || '0', 10);
 var todayKey = 'wc-day-' + new Date().toISOString().slice(0,10);
 var todayCount = parseInt(localStorage.getItem(todayKey) || '0', 10);
@@ -6444,9 +6444,9 @@ async function act(action){
   }
   todayCount++; localStorage.setItem(todayKey, String(todayCount));
   renderStreak();
-  history.unshift({id: id, action: action, title: card.dataset.title, image_url: card.dataset.image});
-  history = history.slice(0, 6);
-  document.getElementById('hon-history').innerHTML = history.map(function(h){
+  picks.unshift({id: id, action: action, title: card.dataset.title, image_url: card.dataset.image});
+  picks = picks.slice(0, 6);
+  document.getElementById('hon-history').innerHTML = picks.map(function(h){
     return '<a class="hist-card '+h.action+'" href="/design/'+h.id+'" title="'+h.title+'"><img src="'+h.image_url+'" alt="'+h.title+'"></a>';
   }).join('');
   setTimeout(load, 280);

← d92efea wallco.ai · context toggle on /design/:id (residential/comme  ·  back to Wallco Ai  ·  feat(/wallco-ai): drop Big Red widget into home page footer cfe10a2 →