Skip to content

Stale data passed to promiseFn when using watchFn #180

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

Closed
salolivares opened this issue Oct 16, 2019 · 2 comments · Fixed by #181
Closed

Stale data passed to promiseFn when using watchFn #180

salolivares opened this issue Oct 16, 2019 · 2 comments · Fixed by #181

Comments

@salolivares
Copy link
Contributor

Potentially related #4

Issue
When watching for a variable change using watchFn, the react async hook properly re-runs promiseFn but with old props passed in.

Expected
promiseFn should have received the new props on re-run.

Example
See https://codesandbox.io/s/jovial-grothendieck-3xth2
In the example above the first render console.logs the following:

in function  grapefruit 
in promise grapefruit 
in function  grapefruit 
Rerun promise? 
false

All is good! But once we change the fruit, we get the following:

in function  lime 
Rerun promise? 
true
in promise grapefruit  <---- should have been lime
in function  lime 
Rerun promise? 
false

And if we run it again:

in function  coconut 
Rerun promise? 
true
in promise lime    <---- should have been coconut
in function  coconut 
Rerun promise? 
false

Am I missing something with the way hooks work or overlooking something simple? Any help will be appreciated!

@ghengeveld
Copy link
Member

Thanks for reporting! This sure looks like a bug with watchFn. I tried replacing it with watch, which works as expected. So if you can make do withwatch (i.e. you have a primitive to watch on), you can use that as a workaround.

Do you want to take a stab at fixing this and open a PR? That would be greatly appreciated.

@salolivares
Copy link
Contributor Author

I'll take a stab at it! I won't have time this week, but will try to get around it next week. I'll keep ya updated.

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

Successfully merging a pull request may close this issue.

2 participants