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

isValidating change only triggers first hook in component tree to render #549

Closed
blackarctic opened this issue Jul 23, 2020 · 4 comments · Fixed by #569
Closed

isValidating change only triggers first hook in component tree to render #549

blackarctic opened this issue Jul 23, 2020 · 4 comments · Fixed by #569
Labels
bug Something isn't working

Comments

@blackarctic
Copy link
Contributor

isValidating change only triggers first hook in component tree to render

Description / Observed Behavior

It seems that if multiple components use useSWR(someKey), a change to isValidating only triggers the first of these components in the tree to rerender.

Expected Behavior / Repro Steps / Code Example

2020-07-22 23 22 25

In this example, I have 3 components that all use useSWR('/api/things'): ThingsList, ThingsListError, and ThingsRefreshButton, but ThingsRefreshButton comes first in the component tree and is the only one receiving the re-render when the value changes. The expected behavior here should be that if the value of isValidating changes, all these components should receive a re-render trigger.

Relevant code is provided below:

Screen Shot 2020-07-22 at 11 29 47 PM

Screen Shot 2020-07-22 at 11 29 58 PM

Screen Shot 2020-07-22 at 11 30 06 PM

Screen Shot 2020-07-22 at 11 30 16 PM

Screen Shot 2020-07-22 at 11 30 24 PM

Additional Context

SWR version: "0.2.3"

@blackarctic
Copy link
Contributor Author

Note that if ThingsList is moved up in the component tree, it is the only component that receives the re-render trigger:

2020-07-22 23 39 41

@shuding shuding added the bug Something isn't working label Jul 23, 2020
@blackarctic
Copy link
Contributor Author

Anyone have any idea what's going on here?

@huozhi
Copy link
Member

huozhi commented Jul 28, 2020

@blackarctic thanks for noticing this issue. current implementation of swr have isValidating in the state of each hook, so in the case they're not consistent and lead to the bug. ideally the isValidating state should bind with key, then return value could be recitified.

@blackarctic
Copy link
Contributor Author

@huozhi Thanks for the response. I would be happy to try to contribute here. I would just need a bit to get up to speed with what is happening in the codebase.

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.

3 participants