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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error from different key is returned #789

Closed
nico-hyperjump opened this issue Nov 24, 2020 · 1 comment · Fixed by #794
Closed

Error from different key is returned #789

nico-hyperjump opened this issue Nov 24, 2020 · 1 comment · Fixed by #794
Labels
bug Something isn't working

Comments

@nico-hyperjump
Copy link

Bug report

Description / Observed Behavior

What kind of issues did you encounter with SWR?

When a request takes long to load, useSWR returns the error from the previous request, even though the keys are different.

Expected Behavior

How did you expect SWR to behave here?

useSWR should not return error from a different key.

Repro Steps / Code Example

  1. Use Chrome
  2. Install URL Throttle chrome extension to simulate slow network for a certain URL.
  3. Enable the extension and add this url: https://pokeapi.co/api/v2/pokemon/ditto with 10000 ms delay. Toggle on the Enabled switch.
  4. Open the sample in this Codesandbox: https://codesandbox.io/s/async-sound-9n2xm?file=/src/App.js
  5. First type in the input text: fafafa, or any non-pokemon text.
  6. The text: Error searching fafafa: fafafa not found will appear.
  7. Next, enter in the input text: ditto.
  8. Since we add 10-second delay to the url to search for ditto, the request will take 10 seconds to finish. So I expect the text Searching ditto will appear, but instead the text: Error searching ditto: dfadfa not found appears. It seems useSWR returns the error from the previous key, fafafa.
  9. After 10 seconds, the error text disappears as expected and the response is displayed.

Since the key changes, useSWR should not return error from previous request imo.

Additional Context

SWR version: 0.3.9

@shuding shuding added the bug Something isn't working label Nov 25, 2020
@shuding
Copy link
Member

shuding commented Nov 25, 2020

Thanks for the detailed repro!

promer94 added a commit to promer94/swr that referenced this issue Dec 1, 2020
promer94 added a commit to promer94/swr that referenced this issue Dec 9, 2020
This was referenced Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants