From cee86f05308d50d30823187be43a641d1a4aa18e Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Tue, 16 Jun 2026 23:10:42 +0100 Subject: [PATCH] wrapping the existing `apiService.getBloomsByHashtag(hashtag)` call in an `if` guard --- front-end/views/hashtag.mjs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/front-end/views/hashtag.mjs b/front-end/views/hashtag.mjs index 7b7e9969..65d451eb 100644 --- a/front-end/views/hashtag.mjs +++ b/front-end/views/hashtag.mjs @@ -17,7 +17,15 @@ import {createHeading} from "../components/heading.mjs"; function hashtagView(hashtag) { destroy(); - apiService.getBloomsByHashtag(hashtag); + // Normalise to the same shape the API stores in state (e.g. "do" -> "#do") + const normalisedTag = `#${hashtag.startsWith("#") ? hashtag.substring(1) : hashtag}`; + + // Only fetch if this hashtag isn't already loaded. Without this guard, + // every render fetches -> updates state -> fires "state-change" -> re-renders, + // an infinite loop that flashes the page blank and hangs the browser. + if (state.currentHashtag !== normalisedTag) { + apiService.getBloomsByHashtag(hashtag); + } renderOne( state.isLoggedIn,