FIX extremely frequent getPinboardsByIds
GraphQL calls
#152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'suseEffect
hook works, where it does reference checking not deep object/array equality, as such thegetPinboardsByIds
refetch was being triggered (in thatuseEffect
block) when ever theactivePinboardIds
array reference was being updated (which was happening very frequently) even though the values we not changing - the solution we found online was toJSON.stringify
to make the value stable, however we found that spreading theactivePinboardIds
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).