americanexpress / fetchye

✨ If you know how to use Fetch, you know how to use Fetchye [fetch-yae]. Simple React Hooks, Centralized Cache, Infinitely Extensible.
Apache License 2.0
43 stars 22 forks source link

fix(FetchyeProvider): correct stale data bug #47

Closed code-forger closed 3 years ago

code-forger commented 3 years ago

This PR implements the same fix as PR46 but for FetchyeProvider

Description

Ensure the effect in the default selector properly causes a re-render when the key changes.

Motivation and Context

Without this change, when 'returning' to data that is already loaded in the cache, the data returned by 'useFetchye' ends up 'one render behind'. This fix ensures that a change in the key results in an additional render to keep the value up to date.

How Has This Been Tested?

A Unit test has been created that would fail for the old code, which passes for the new code Using fetchye as part of a One App module, I have recreated this issue using a list of data where selecting an item causes a call to useFetchye in a separate module. Without this fix, when navigating back to a previously visited item, the second module ends up one click behind. With this fix the second module always shows the correct item. No existing unit tests failed.

Types of Changes

Checklist:

What is the Impact to Developers Using Fetchye?

There should be no impact to developers as there is no change to an api.

codesandbox-ci[bot] commented 3 years ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit f5423ce8e2487275d5c16906512a7098d01cd93b:

Sandbox Source
quick-install Configuration
fetchye-provider-install Configuration
fetchye-redux-provider-install Configuration
nextjs-fetchye-ssr Configuration