Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

In flight Cache hits in oneFetchye (or the underlying makeServerFetchye) don't return a shared promise #93

Open
code-forger opened this issue Apr 15, 2024 · 0 comments

Comments

@code-forger
Copy link
Member

code-forger commented Apr 15, 2024

馃悶 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant