-
-
Couldn't load subscription status.
- Fork 17
London | 25-SDC-July | Andrei Filippov | Sprint 1 | Bug Report: Hashtag slowing down my browser #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You demonstrated strong debugging skills, wrote clean defensive code, and followed best practices by adding a test. Fantastic work!
| // Check that hashtag starts with hash to make right comparison with state | ||
| const hashtagWithHash = hashtag.startsWith("#") ? hashtag : `#${hashtag}`; | ||
| if (state.currentHashtag !== hashtagWithHash) { | ||
| apiService.getBloomsByHashtag(hashtag); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've correctly identified the root cause - the function was calling the API every time without checking if it already had the data. Your solution to check state.currentHashtag !== hashtagWithHash before making the API call is exactly right! This prevents the infinite loop that was causing the browser to flash.
Nice attention to detail on the edge case check! You noticed that hashtags might come in with or without the # prefix, and you normalized it to ensure the comparison works correctly. This shows you're thinking about real-world usage scenarios.
| import { test, expect } from "@playwright/test"; | ||
|
|
||
| test("should not make infinite hashtag endpoint requests", async ({ page }) => { | ||
| // ===== ARRANGE | ||
| const requests = []; | ||
| page.on("request", (request) => { | ||
| if ( | ||
| request.url().includes(":3000/hashtag/do") && | ||
| request.resourceType() === "fetch" | ||
| ) { | ||
| requests.push(request); | ||
| } | ||
| }); | ||
| // ====== ACT | ||
| // 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); | ||
|
|
||
| // ====== ASSERT | ||
| // Then the number of requests should be 1 | ||
| expect(requests.length).toEqual(1); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent addition of a regression test!
Self checklist
Changelist
Fixed issue with the hashtag view. To do this I needed to understand the application flow and make some tests to verify the fix.
Questions
Should playwright tests start in a new window called "Chromium"?