Skip to content

Unexpected change in behaviour beween React 17 and 18 #219

Open
@obweger

Description

Team,

I have a setup where I'm processing data in a sequence / nesting of Sweet State containers, where the result (i.e., state) of one container is passed into the next container as a prop. In terms of data processing, this "sequence" is more of a directed graph, looking like e.g. this:

image

... meaning that the output of Alpha is used both in Beta, where it causes an update to Gamma and ultimately Delta, and also in Delta directly.

In React 17, as well as with defaults.batchUpdates = false, this works "synchronously" (for the lack of a better word), meaning that when Alpha updates, Delta updates only once, with the updated Alpha value and the updated Gamma value.

In React 18, the same setup causes Alpha to update twice, first with the updated Alpha value and the old Gamma value, and then with both values updated.

See this reproduced here: https://codesandbox.io/p/devbox/sweet-state-batching-issue-2kpdyx?file=%2Fsrc%2FApp.tsx%3A14%2C34. Open the console, and hit "Update". (The problem doesn't seem to happen on initial render.)

Mille grazie!

Activity

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

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