From d6dcdfba11154a0d51bf7fa4ca11ca68a7f11801 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Wed, 27 May 2026 19:28:38 -0400 Subject: [PATCH] Community browser: don't trash the welcome modal's pre-warmed cache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous "auto-refresh on Browse click" commit unconditionally called invalidateFeedCache() before opening the modal. That set _feedCache.events = null and forced a 6-second re-fetch on every Browse click — wiping the cache the welcome modal had populated seconds earlier. Symptom: cold reload → welcome loads instantly → exit → Browse shows "Loading..." for ~6s with nothing rendered, while changing the type filter (which only re-filters the cache) appears to "work" once the fetch finally lands. Smarter behaviour: - Add a `force` option to fetchFeedAndReactions that bypasses its 5-minute cache check. Use this from the Browse buttons. - Don't blow away the cache. Open the modal, switch to the New tab, which renders cached cards immediately via the existing `if (_feedCache.events && _feedCache.events.length) rerender()` path in loadFeedTab. Then trigger a force refresh only if the cache is staleish (>30s old). So: welcome just-loaded cache (age=2-5s) → Browse opens instantly with those cards, no extra fetch. Older cache (age=1m, 4m, etc.) → Browse renders cached cards instantly AND kicks off a background refresh whose progress streams in via notifyFeedProgress. The explicit Refresh button in the modal is still available for on-demand forced pulls. Co-Authored-By: Claude Opus 4.7 --- src/index.html | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/index.html b/src/index.html index f29a242..d3fcaef 100644 --- a/src/index.html +++ b/src/index.html @@ -16302,12 +16302,16 @@ _zapCache.fetchedForAuthors.clear(); } - async function fetchFeedAndReactions() { + async function fetchFeedAndReactions(opts) { const relays = splitRelayList(state.community.relays); const relayKey = relays.join(','); const age = Date.now() - _feedCache.fetchedAt; if (_feedCache.loading) return; - if (_feedCache.events && age < 5 * 60 * 1000 && _feedCache.relayKey === relayKey) return; + // `force: true` bypasses the 5-minute cache. Used by the Browse button + // to refresh in the background while the existing cached cards stay + // on screen, so the user sees content immediately. + const force = !!(opts && opts.force); + if (!force && _feedCache.events && age < 5 * 60 * 1000 && _feedCache.relayKey === relayKey) return; _feedCache.loading = true; _feedCache.relayKey = relayKey; _feedCache.reactions = {}; @@ -22061,12 +22065,17 @@ btn.classList.toggle('active', btn.dataset.type === 'any'); }); } - // Auto-refresh on open. fetchFeedAndReactions otherwise honours a - // 5-minute cache and the user would see stale results (including - // their own design they just published). - invalidateFeedCache(); $('nostrModal').classList.add('open'); switchModalTab('New'); + // The welcome modal pre-warms `_feedCache.events` on cold load, so + // opening Browse should hit that cache and render cards instantly. + // Only trigger a forced refresh if the cache is genuinely staleish + // (>30s old) — otherwise the welcome's just-loaded data gets + // wiped by fetchFeedAndReactions clearing reactions/profiles + // mid-fetch. Use the explicit Refresh button in the modal for an + // on-demand fresh pull. + const cacheAge = Date.now() - (_feedCache.fetchedAt || 0); + if (cacheAge > 30000) fetchFeedAndReactions({ force: true }); }); $('designerBrowseCommunityBtn').addEventListener('click', () => { for (const t of ['New', 'Popular', 'Mine']) { @@ -22076,9 +22085,10 @@ btn.classList.toggle('active', btn.dataset.type === 'disc-design'); }); } - invalidateFeedCache(); $('nostrModal').classList.add('open'); switchModalTab('New'); + const cacheAge = Date.now() - (_feedCache.fetchedAt || 0); + if (cacheAge > 30000) fetchFeedAndReactions({ force: true }); }); $('welcomeSearchBtn').addEventListener('click', runWelcomeSearch); $('welcomeSkipBtn').addEventListener('click', dismissWelcomeModal);