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

Potential race condition with deferFn run functions. #329

Open
rstire364 opened this issue Mar 8, 2022 · 0 comments
Open

Potential race condition with deferFn run functions. #329

rstire364 opened this issue Mar 8, 2022 · 0 comments

Comments

@rstire364
Copy link

Demonstration: https://stackblitz.com/edit/react-2rszhm?file=src/App.js

We make use of context a great deal in our applications. Our intent was to use the deferFn, provide the entire state, and call the provided run function as necessary. This is working flawlessly when the run is called by a user action like a button press. However when programmatically calling the run function, like in a componentDidMount or useEffect(() => {}, []) the counter is incremented twice, the network request is fired, but the state never updates.

My assumption is theres a bit of race condition related to the counter initialization and the handleResolve call.

Yes, it also works when using the promiseFn, but this call is conditional. I'm certain we can rearchitect the DOM structure to circumvent this issue, but thought I'd bring it up.

Thanks for the package, big fans.

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