From 7fb02342dd58a2a1424dbdcdabf412d4bb2eb67b Mon Sep 17 00:00:00 2001 From: Craig D'Silva Date: Thu, 4 Jun 2026 13:13:44 +0100 Subject: [PATCH] Fix infinite loop when selecting a hashtag --- front-end/tests/hashtag.spec.mjs | 19 +++++++++++++++++++ front-end/views/hashtag.mjs | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 front-end/tests/hashtag.spec.mjs diff --git a/front-end/tests/hashtag.spec.mjs b/front-end/tests/hashtag.spec.mjs new file mode 100644 index 00000000..466d77d0 --- /dev/null +++ b/front-end/tests/hashtag.spec.mjs @@ -0,0 +1,19 @@ +import { test, expect } from "@playwright/test"; + +test("should not make infinite hashtag endpoint requests", async ({ page }) => { + const requests = []; + page.on("request", (request) => { + if ( + request.url().includes(":3000/hashtag/do") && + request.resourceType() === "fetch" + ) { + requests.push(request); + } + }); + + await page.goto("/#/hashtag/do"); + + await page.waitForTimeout(200); + + expect(requests.length).toEqual(1); +}); diff --git a/front-end/views/hashtag.mjs b/front-end/views/hashtag.mjs index 7b7e9969..d85c7063 100644 --- a/front-end/views/hashtag.mjs +++ b/front-end/views/hashtag.mjs @@ -17,7 +17,9 @@ import {createHeading} from "../components/heading.mjs"; function hashtagView(hashtag) { destroy(); + if (hashtag !== state.currentHashtag) { apiService.getBloomsByHashtag(hashtag); +} renderOne( state.isLoggedIn,