fix(cache): remove previous data or error on new run #66
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.
Description
If there is now data, remove the error from the previous run.
If there is now an error, remove the data from the previous run.
Motivation and Context
Sometimes there might be network issues (ex: traveling into a tunnel so the network disconnects) and a retry is desirable. As an example, a manual retry could be:
Currently, if there was an error the first load attempt
error
has a value (anddata
does not). However, on the second attempt if the request does go through anddata
now has a valueerror
still has a value, persisted from the first attempt.We can add an automatic retry to hit another scenario:
If the first attempt is successful and
data
has a value (anderror
does not), but on the second attempt there is an error thenerror
now has a value butdata
still has a value, persisted from the first attempt.Additionally, with both entries having values it is difficult which of
data
orerror
are more recent. This is probably not too much of a concern for idempotent calls (e.g.GET
) but this may cause challenges for mutating/non-idempotent calls (e.g.POST
).How Has This Been Tested?
Tests, keeping with their context, have been added. When generating snapshots Jest noted that it could not find Prettier, likely after the eslint configuration update; I installed Prettier locally to generate the inline snapshots but another PR will be needed to avoid this in the future.
Types of Changes
Checklist:
What is the Impact to Developers Using Fetchye?
Some developers might be, perhaps unknowingly, relying on the current behavior. Generally though I see the current behavior as a bug especially due to the challenge of knowing which of
data
orerror
are most recent. If a component wishes to use the last availabledata
before errors were encountered their best course of action is probably adding their logic needed usinguseState
anduseEffect
, e.g.:or, if response status is important
or
depending on their specific circumstances