From cff61a0227e8a5453290a74679ac8b1c0daf7922 Mon Sep 17 00:00:00 2001 From: shaden-pr Date: Sat, 4 Oct 2025 18:47:59 +0100 Subject: [PATCH 1/2] test(hashtag): add Playwright test to ensure only one fetch on navigation --- front-end/tests/hashtag.spec.mjs | 22 ++++++++++++++++++++++ 1 file changed, 22 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 0000000..303c47c --- /dev/null +++ b/front-end/tests/hashtag.spec.mjs @@ -0,0 +1,22 @@ +import { test, expect } from "@playwright/test"; + +test.describe("hashtag view", () => { + test("should only make one fetch request when navigating to a hashtag", async ({ page }) => { + let fetchCount = 0; + page.on("request", (request) => { + if ( + request.url().includes(":3000/hashtag/do") && + request.resourceType() === "fetch" + ) { + fetchCount++; + } + }); + // When I navigate to the hashtag + await page.goto("/#/hashtag/do"); + // And I wait a reasonable time for any additional requests + await page.waitForTimeout(200); + + // Then the number of fetch requests should be 1 + expect(fetchCount).toEqual(1); + }); +}); \ No newline at end of file From 8dc774a87e198b39ff47cf274e6b821251f5ee40 Mon Sep 17 00:00:00 2001 From: shaden-pr Date: Sat, 4 Oct 2025 18:50:23 +0100 Subject: [PATCH 2/2] fix(hashtag): avoid duplicate fetches by normalizing hashtag --- front-end/views/hashtag.mjs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/front-end/views/hashtag.mjs b/front-end/views/hashtag.mjs index 7b7e996..2275170 100644 --- a/front-end/views/hashtag.mjs +++ b/front-end/views/hashtag.mjs @@ -17,7 +17,10 @@ import {createHeading} from "../components/heading.mjs"; function hashtagView(hashtag) { destroy(); - apiService.getBloomsByHashtag(hashtag); + const normalized = hashtag.startsWith("#") ? hashtag : `#${hashtag}`; + if(normalized !== state.currentHashtag){ + apiService.getBloomsByHashtag(hashtag); + } renderOne( state.isLoggedIn,