ZA | 25-SDC-JULY | Luke Manyamazi | Sprint 1 | Hashtag slowing down my browser#54
Conversation
illicitonion
left a comment
There was a problem hiding this comment.
Can you talk through what you think the root cause of this bug is and how this PR addresses that problem?
What symptoms do you think the user who reported the bug is seeing? How do they relate to what you're changing here?
|
Hi Daniel This is waht I think:
Fix: |
illicitonion
left a comment
There was a problem hiding this comment.
I'm still seeing issues on this page - if I load a hashtag page, and try to click on one of the links on the page or click logout, most of the time clicking doesn't do anything. It's like the browser is really busy doing something?
|
This change now updates hashtagView to fetch blooms only when the hashtag actually changes. It prevents duplicate API requests and ensures state.currentHashtag is correctly set. Looks good! |
| apiService.getBloomsByHashtag(hashtag); | ||
| const goodHashtag = hashtag.startsWith("#") ? hashtag : `#${hashtag}`; | ||
| if (state.currentHashtag !== goodHashtag) { | ||
| state.currentHashtag = goodHashtag; |
There was a problem hiding this comment.
Why do you set the state here? It gets set by apiService.getBloomsByHashtag - by setting it here, you're opening up a race condition that if we render the screen while the blooms are loading, we'll show the new hashtag but the old hashtag's blooms.
|
"Hi Daniel, good catch. I've refactored hashtagView to be async and now await the apiService call. This fixes the issues by: Eliminating the Race Condition: By awaiting the data before calling render, the heading and the blooms list now update simultaneously. Fixing Browser Lag: Removing the manual state update in the view prevents 'double-rendering' conflicts that were making the browser feel busy. Single Source of Truth: The view now waits for apiService to update the state fully before rendering. |
|
I think your previous fix was much more in line with what's expected here. With your latest change, if I open the network tab on the hashtag page I see lots and lots and lots of the same request, which is probably what's slowing down the browser. I don't think using async/await here stops there being lots and lots of requests? |
930b27c to
921f365
Compare
Learners, PR Template
Self checklist
Changelist
Questions
None