Skip to content

State updates in ReactMixin are not atomic #193

@metcalf

Description

@metcalf

Nuclear's current implementation calls reactor.observe separately for each entry in the response to a React component's getDataBindings. If multiple pieces of bound data change in a single dispatch, Nuclear will call setState on the component for each of them and React will dutifully render each time. This means that the exact behavior of your component is dependent on the order in which you define your data bindings (aside from being bad for performance).

The most proximate solution I can see is to call reactor.observe once with all of the keypaths from getDataBindings and call setState once with the complete set of data. This code would be hairy since it has to handle getters as well, but it's doable. I have some concern that it forces more recomputation than necessary but I suspect that's a lesser issue than forcing React to diff repeatedly.

Alternatively, it might make sense to provide a shouldComponentUpdate implementation that returns false for all but the last setState call. I suspect that's the most performant option but I think it would require deeper coupling between ReactMixin and Reactor.

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