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

Warn if optimistic state is updated outside of a transition #27454

Merged

Commits on Oct 4, 2023

  1. Warn if optimistic state is updated outside of a transition

    If optimistic state is updated, and there's no startTransition on the
    stack, there are two likely scenarios.
    
    One possibility is that the optimistic update is triggered by a regular
    event handler (e.g. `onSubmit`) instead of an action. This is a mistake
    and we will warn.
    
    The other possibility is the optimistic update is inside an async
    action, but after an `await`. In this case, we can make it "just work"
    by associating the optimistic update with the pending async action.
    
    Technically it's possible that the optimistic update is unrelated to
    the pending action, but we don't have a way of knowing this for sure
    because browsers currently do not provide a way to track async scope.
    (The AsyncContext proposal, if it lands, will solve this in the future.)
    However, this is no different than the problem of unrelated transitions
    being grouped together — it's not wrong per se, but it's not ideal.
    
    Once AsyncContext starts landing in browsers, we will provide better
    warnings in development for these cases.
    acdlite committed Oct 4, 2023
    Configuration menu
    Copy the full SHA
    d4c4b14 View commit details
    Browse the repository at this point in the history