-
Notifications
You must be signed in to change notification settings - Fork 25
Fix/is loading/multi render behaviour weirdness #99
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
base: main
Are you sure you want to change the base?
Fix/is loading/multi render behaviour weirdness #99
Conversation
|
With this change could the first render logic be removed from the isLoading function? |
2b7e0ba to
fd44eb6
Compare
|
Converting to draft whilst pr #102 is open |
6dd2d78 to
bbfb724
Compare
Testing for id changing after rendernote: there is potentially an issue where the initial return will return the data from the previous id. see #105 |
code-forger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution, I think there is one logic regression. if you could make some unit tests to prove this is a regression, then fix it, that would be great.
I've also asked for a slight reinforcing of the unit tests, possibly even in some that you did not author. Since you are changing rather complex logic, laying down more tests will help the package consumers be confident that this change has no logic regressions.
packages/fetchye/src/queryHelpers.js
Outdated
| // if defer is true | ||
| if (options.defer) { | ||
| // isLoading should be false | ||
| return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the caller passes in three quick renders:
- defer: true
- defer: false
- defer: true
then isLoading will now go false despite the fact there may still be a call in flight.
This check might need to be
if (options.defer && numOfRenders === 1) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the code c75cceb
I've moved the defer to only stop the function from returning true if fetchye will fetch, rather than an early false return if defer is enabled.
| expect(isLoading({ | ||
| loading: false, data: undefined, numOfRenders: 1, options: { forceInitialFetch: true }, | ||
| loading: false, | ||
| numOfRenders: 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your function no-longer receives this parameter, please remove it from the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in this commit e45edff
| it('should return false defer is true', () => { | ||
| expect(isLoading({ | ||
| loading: false, data: undefined, options: { defer: true }, error: undefined, refs: {}, | ||
| })).toEqual(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see some more expects per test:
This tests proves that for the above set of inputs, you get false, but does not prove that should return false if defer is true, since you have not checked other combinations of inputs.
So in this same it block, having many combinations of isLoading, data, options, error, and refs, showing that for any combination, when defer: true => false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(same for other tests in this file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've refactored the tests a little to make use of more describe blocks: cb0ffc1
I've added a should return false and should return true describe blocks with each case in it() this way any failures will highlight the case where it failed, I put them all into 2 "true" or "false" with multiple expects, but when it failed it was tricky to figure out which one was the failing case
| } from '../src/queryHelpers'; | ||
|
|
||
| describe('isLoading', () => { | ||
| it('should return false defer is true', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| it('should return false defer is true', () => { | |
| it('should return false if defer is true', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added in this commit e45edff






Description
There is a small edge case where when a call is waiting for another call to finish - think A2 needs data from A1.
on the first render
A2 options.defer = true; isLoading == false as a result;
A1 options.defer = false && data = undefined; isLoading == true as a result;
After A1 data has been fetched, A2 options.defer = false.
However because it isn't the first render isLoading == false, and the loading state is only set to true during the runAsync function call.
To remedy this I've added an extra check that is the same as the check in the useEffect which will be checking
(!options.defer && !data && !isLoading && !error)if all of these statements are true then we can assume that therunAsyncfunction will be triggered in the useEffect.Motivation and Context
potentially solves issue #81
Also potentially solves an issue found by a team in American express.
How Has This Been Tested?
Manual testing was completed following the reproduction steps as outlined on issue #81, as well as manual testing on the branch where the issue was found.
Currently available fetchye package. repository

Fetchye package using a build produced from this branch. repository

Types of Changes
Checklist:
What is the Impact to Developers Using Fetchye?