Skip to content

Sync updates shouldn't cancel pending async updates entirely #624

@aleclarson

Description

@aleclarson

Currently, when the queue is flushed, any pending async updates are cancelled.
To ensure that to props are never lost, the controller merges them into its merged object, which is iterated in the diff method.

Merging has the consequence of immediately starting the pending async updates, which I believe is rarely what the user wants. For example, let's say useTransition is running enter animations on its items along with the trail prop (creating a staggered effect). When useTransition is then passed an update, the trail prop is effectively ignored and all enter animations begin at the same time.

I think we can do better.

One idea is to attach a timestamp to every flush. Then we never need to cancel anything on flush. Instead, when a pending async update is ready to diff, it checks the timestamp of each animation it wants to update. If the animation has a greater timestamp, skip updating it. By never cancelling on flush, we ensure that end values are never lost. By attaching a timestamp, we ensure that newer updates take precedence over async updates.

Feedback wanted. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions