[object Object]

← back to Naturalwallcoverings

hydrate saved sort BEFORE first grid load (was applied only on late select wire, missing initial fetch)

6b2e780b0a601748229d9c3b08a8efc4774b20cd · 2026-05-25 21:23:14 -0700 · Steve

Files touched

Diff

commit 6b2e780b0a601748229d9c3b08a8efc4774b20cd
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon May 25 21:23:14 2026 -0700

    hydrate saved sort BEFORE first grid load (was applied only on late select wire, missing initial fetch)
---
 public/index.html | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/public/index.html b/public/index.html
index befd875..02ab325 100644
--- a/public/index.html
+++ b/public/index.html
@@ -497,12 +497,17 @@ const state = { q:'', facet:'all', sort:'newest', view:'grid', page:1, pages:1,
 // Touch device = no hover. Drives tap-to-reveal card behavior.
 const TOUCH = window.matchMedia('(hover: none)').matches;
 const HOSTKEY = location.hostname.replace(/\./g, '_');
-// DW STANDARD: hydrate saved view BEFORE the first grid load.
+// DW STANDARD: hydrate saved view + sort BEFORE the first grid load so the
+// initial /api/products fetch already carries the saved sort param. The
+// late-mounted sortSelect wire (~bottom of file) also reads this same key,
+// but the select element doesn't exist when loadGridPage() first fires.
 (function(){
   try {
     const savedView = localStorage.getItem(HOSTKEY + '_view');
     if (savedView === 'list' || savedView === 'grid') state.view = savedView;
     document.documentElement.dataset.view = state.view;
+    const savedSort = localStorage.getItem(HOSTKEY + '_sort');
+    if (savedSort) state.sort = savedSort;
   } catch(e){}
 })();
 const LABELS = {"all":"All"};

← e001196 retag aesthetic from PG: 516 rows updated  ·  back to Naturalwallcoverings  ·  /api/facets: count FILTERED list (honor q + aesthetic) inste b6cf30f →