🐞 Bug Report
Describe the bug
If two requests are made to the same data, if the second request is made while the first request is still "in flight" it will return both "error" and "data" as undefined instead of the promise to the inflight request.
This is because during a second call to the same data, while the first call is 'in flight':
This block will be skipped, because we do have a cacheSelector via oneFetchye:
https://github.com/americanexpress/fetchye/blob/main/packages/fetchye/src/makeServerFetchye.js#L42
This block will be skipped, because the request is loading:
https://github.com/americanexpress/fetchye/blob/main/packages/fetchye/src/makeServerFetchye.js#L54
The function will then "syncronously" return the data, error, and run fields:
https://github.com/americanexpress/fetchye/blob/main/packages/fetchye/src/makeServerFetchye.js#L64
However data and error will be undefined because the original request is still in flight.
To Reproduce
Define two sequenced functions (in psuedo code):
const getUserPlaylists = (dispatch) => {
const { data: token } = await dispatch(oneFetchye(".../logIn"));
const { data: playlists } = await dispatch(oneFetchye(".../readUserPlaylists"));
return playlists;
}
const getUserPreferences = (dispatch) => {
const { data: token } = await dispatch(oneFetchye(".../logIn"));
const { data: preferences } = await dispatch(oneFetchye(".../readUserPreferences"));
return preferences;
}
Then race them:
return Promise.all([dispatch(getUserPlaylists), dispatch(getUserPreferences)]);
Note: This bug is also present if you are calling for the same data from multiple one-app modules.
Whichever call to logIn happens second will "synchronously" receive undefined as the token.
Expected behavior
Both calls to get the token properly return a promise to the data from the single call made
🐞 Bug Report
Describe the bug
If two requests are made to the same data, if the second request is made while the first request is still "in flight" it will return both "error" and "data" as undefined instead of the promise to the inflight request.
This is because during a second call to the same data, while the first call is 'in flight':
This block will be skipped, because we do have a cacheSelector via
oneFetchye:https://github.com/americanexpress/fetchye/blob/main/packages/fetchye/src/makeServerFetchye.js#L42
This block will be skipped, because the request is
loading:https://github.com/americanexpress/fetchye/blob/main/packages/fetchye/src/makeServerFetchye.js#L54
The function will then "syncronously" return the
data,error, andrunfields:https://github.com/americanexpress/fetchye/blob/main/packages/fetchye/src/makeServerFetchye.js#L64
However
dataanderrorwill be undefined because the original request is still in flight.To Reproduce
Define two sequenced functions (in psuedo code):
Then race them:
Note: This bug is also present if you are calling for the same data from multiple one-app modules.
Whichever call to
logInhappens second will "synchronously" receiveundefinedas thetoken.Expected behavior
Both calls to get the token properly return a promise to the data from the single call made