Skip to content

WestMidlands | SDC NOV 2025| Sara Tahir | Sprint 1| Hashtag Slowing Down my Browser#99

Open
SaraTahir28 wants to merge 3 commits intoCodeYourFuture:mainfrom
SaraTahir28:Legacy/prep
Open

WestMidlands | SDC NOV 2025| Sara Tahir | Sprint 1| Hashtag Slowing Down my Browser#99
SaraTahir28 wants to merge 3 commits intoCodeYourFuture:mainfrom
SaraTahir28:Legacy/prep

Conversation

@SaraTahir28
Copy link

Learners, PR Template

Self checklist

  • 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

Changelist

Briefly explain your PR.
This PR fixes an issue where navigating to a hashtag page triggered multiple repeated API requests, causing unnecessary network load and slowing down the browser. The root cause was that the hashtag view re‑rendered with the same hashtag, and the fetch function was being called on every render.

A Playwright test from the prep section is included to ensure this regression never returns.

Questions

No Questions

@SaraTahir28 SaraTahir28 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jan 30, 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.

//Only fetch data if the hashtag has changed since the last render.
// This prevents infinite loops caused by re-renders or route updates.
if (state.currentHashtag !== formattedHashtag) {
state.currentHashtag = hashtag; // Store the new hashtag BEFORE fetching so the next render sees the update.
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.

This makes sense, I have changed the code so now we only update state.currentHashtag when the hashtag actually changes, and the UI doesn’t re‑render until the fetch comes back and updates state.hashtagBlooms.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see the change here?

@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
…based wait using the first [data-bloom] element,

Also Updated hashtagView to only update state.currentHashtag and trigger a fetch when the formatted hashtag changes.
@SaraTahir28 SaraTahir28 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 4, 2026
@illicitonion illicitonion removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 4, 2026
Copy link
Author

@SaraTahir28 SaraTahir28 left a comment

Choose a reason for hiding this comment

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

Hi I have tagged you where I changed the function. :)

apiService.getBloomsByHashtag(hashtag); // Retrieve all blooms associated with this hashtag from the API.
state.currentHashtag = formattedHashtag;
apiService.getBloomsByHashtag(formattedHashtag);
}
Copy link
Author

Choose a reason for hiding this comment

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

@illicitonion I have changged the function here in this commit.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm... I still see state.currentHashtag = formattedHashtag; on line 22 - was the point not to remove that line?

Copy link
Author

Choose a reason for hiding this comment

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

From what I understood from your first comment is that I updated state.currentHashtag immediately but state.hashtagBlooms still contained the old blooms so there was a possibility of UI showing mismatched data.
I replace it with updating state.currentHashtag when the hashtag actually changes.
The fix was just to store the formatted hashtag so the comparison works properly and the UI only updates when the data actually changes.

if I removed this line state.currentHashtag = formattedHashtag state.currentHashtag would never get updated

Copy link
Member

Choose a reason for hiding this comment

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

getBloomsByHashtag already updates state.currentHashtag when it gets results. And currentHashtag is currently read in views/hashtag.mjs for deciding what hashtag heading to show.

If we just let getBloomsByHashtag do the update, we make sure currentHashtag and hashtagBlooms are always in sync. If you manually update currentHashtag, then someone triggers a re-render, we'll show the new hashtag but the old blooms.

@SaraTahir28 SaraTahir28 added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants