Skip to content

Sheffield | 25-SDC-Nov | Sheida Shabankari | Sprint 1 |Hashtag slowing down browser#103

Open
sheida-shab wants to merge 4 commits intoCodeYourFuture:mainfrom
sheida-shab:Feat-fixBug-Hashtag-slowingDownBrowser
Open

Sheffield | 25-SDC-Nov | Sheida Shabankari | Sprint 1 |Hashtag slowing down browser#103
sheida-shab wants to merge 4 commits intoCodeYourFuture:mainfrom
sheida-shab:Feat-fixBug-Hashtag-slowingDownBrowser

Conversation

@sheida-shab
Copy link

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Summary

This PR fixes a bug where clicking on a hashtag caused the page to repeatedly refresh and flash blank.

Cause

The hashtagView was calling apiService.getBloomsByHashtag multiple times due to re-renders.
Because the hashtag value was not normalized or tracked correctly, the view kept triggering new API requests, resulting in an infinite loop.

Fix

The hashtag is now normalized (always prefixed with #) and stored in state.currentHashtag.
The API request is only made when the hashtag actually changes, preventing repeated calls and re-renders.

Tests

A new Playwright test was added to ensure the hashtag endpoint is called only once and does not enter an infinite request loop.

@sheida-shab sheida-shab added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Legacy-Code The name of the module. labels Feb 3, 2026
Copy link
Member

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, and well done for adding a test for the bug! I left a couple of comments to think about.

// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for fixed periods of time is a recipe for flakiness in tests - prefer to wait e.g. for the title of the page to be updated, or for some blooms to be displayed, or something similar.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced the fixed timeout with a wait for the API response to ensure the test only continues once the hashtag data is loaded. This avoids flakiness and ensures the test reliably reflects the UI state.


const normalizedHashtag = hashtag.startsWith("#") ? hashtag : `#${hashtag}`;
if (state.currentHashtag !== normalizedHashtag) {
state.currentHashtag = normalizedHashtag;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting choice - isn't there a problem here that we may show the title for the new hashtag but the content for the new hashtag, if we render again before the API request finishes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback — I understand the concern about showing the title for a new hashtag while the content might be from a previous hashtag if the API response hasn't returned yet.
To handle this, the code now checks that the hashtag in state is still current before using the API response, so old data is ignored and the view remains consistent.

@illicitonion illicitonion added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Feb 4, 2026
@sheida-shab sheida-shab added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Legacy-Code The name of the module. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed.

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants