Skip to content
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

FIX extremely frequent getPinboardsByIds GraphQL calls #152

Merged
merged 1 commit into from
Aug 12, 2022

Conversation

twrichards
Copy link
Collaborator

@twrichards twrichards commented Aug 10, 2022

Co-Authored-By: @andrew-nowak

When experimenting/working on #150 , @andrew-nowak astutely noticed a very high amount of AJAX requests in the Network tab of developer tools, specifically getPinboardsByIds GraphQL calls. We tracked this down to an oversight in our understanding of how the dependency list on React's useEffect hook works, where it does reference checking not deep object/array equality, as such the getPinboardsByIds refetch was being triggered (in that useEffect block) when ever the activePinboardIds array reference was being updated (which was happening very frequently) even though the values we not changing - the solution we found online was to JSON.stringify to make the value stable, however we found that spreading the activePinboardIds array into the dependency list had the same effect and was more elegant (and probably cheaper too).

Whilst there we also noticed a possible cause of unnecessary re-renders (although probably unrelated to this issue), which we've hopefully addressed by the change detection we've added before setting state relating to stuff detected in the DOM of the host application (e.g. the preselected pinboard ID put there by composer).

…seEffect oversight, combined with frequent re-renders)

Co-Authored-By: Andrew Nowak <andrew.nowak@guardian.co.uk>
@twrichards twrichards marked this pull request as ready for review August 11, 2022 09:02
@twrichards twrichards requested a review from a team August 11, 2022 09:14
@twrichards twrichards merged commit 48e7acc into main Aug 12, 2022
@twrichards twrichards deleted the FIX-runaway-getPinboardsByIds branch August 12, 2022 10:25
@prout-bot
Copy link
Collaborator

Seen on PROD (merged by @twrichards 3 minutes and 14 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants