Fix optimistic response for cached games #59
Merged
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.
Issue
At the
explore page
, the apollo cache is used to store the games and the optimistic response with the empty game is being pushed inside the cache overwriting the game fragment and producing a flash (with an empty game). This only happens here, as the other pages are not using the cache to store the games (index, game/[slug], ...).Proposed Solution
In order to fix it, the
optimisticGameResponse
is modified to read the game fragment from cache (by using the id) and an optimistic response is created based on it if available. Otherwise, it will continue creating an empty structure response with the id as it does not have a negative impact when the game is not cached. This way both cases (with cache and without) are covered.Hopefully now everything is working as expected.