Skip to content

Potential race condition with deferFn run functions. #329

Description

@rstire364

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions