From f684cee551fc2d2470f518332597dd9072a7da90 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 18 Aug 2026 08:20:14 -0700 Subject: The restored shop remembers to go shopping: a session that wakes on the hat screen refetches its data instead of filtering a collection nobody loaded — the crash that bricked every tap on the phone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01JtaatFfAbx91Nh3xqKVqKz --- src/features/hats.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/features/hats.js b/src/features/hats.js index ed89a82..4f6e977 100644 --- a/src/features/hats.js +++ b/src/features/hats.js @@ -194,8 +194,12 @@ export function hatsFeature(ctx) { function openShop() { ui.hatShop = true; - ui.hatShopData = null; ui.hatConfirm = null; + loadShop(); + } + + function loadShop() { + ui.hatShopData = null; render(); const me = ctx.shownPubkey(); if (!me) { ui.hatShopData = { owned: [], equipped: null }; render(); return; } @@ -309,12 +313,12 @@ export function hatsFeature(ctx) { h('div', { class: 'card col', style: 'gap:12px' }, h('h3', { style: 'margin:0' }, '🎩 ' + t('hatShopTitle')), h('p', { class: 'small muted', style: 'margin:0' }, t('hatShopBlurb')), - d === null + d == null ? h('div', { style: 'text-align:center;padding:16px' }, h('span', { class: 'spinner' })) : h('div', { class: 'col', style: 'gap:2px' }, // the crown is not merchandise — it appears only in the // collection of the head that owns it, never as a listing - ...HATS.filter((hat) => hat.id !== 'crown' || (d.owned || []).includes('crown')) + ...HATS.filter((hat) => hat.id !== 'crown' || ((d && d.owned) || []).includes('crown')) .map((hat) => shopRow(hat, d, me))), d && d.offline ? h('div', { class: 'small faint', style: 'text-align:center' }, t('hatShopOffline')) : null), h('button', { class: 'btn-ghost btn-block', onClick: closeShop }, t('back'))); @@ -339,6 +343,11 @@ export function hatsFeature(ctx) { }, screenView() { if (ui.screen !== 'wallet' || !ui.hatShop) return null; + // A restored session brings the shop screen back WITHOUT its data + // (hatShop rides the nav snapshot; the fetch result doesn't) — refetch + // instead of rendering a collection nobody loaded. undefined = never + // fetched; null = fetch in flight. + if (ui.hatShopData === undefined) setTimeout(loadShop, 0); return shopScreen(); }, }; -- cgit v1.2.3