Skip to content

bug(data): concurrent useMutation calls can overwrite newer results with stale data #3756

Description

@Tomeshwari-02

Summary

useMutation in packages/data/src/hooks/useMutation.ts does not track request order. If mutate() is called twice and the first request resolves after the second, the older response can overwrite the newer data state.

Reproduction

  1. Create a component using useMutation('/save', 'POST').
  2. Call mutate({ value: 'old' }), then quickly call mutate({ value: 'new' }).
  3. Make the
    ew request resolve first and the old request resolve last.

Expected behavior

The hook should either document that concurrent mutations are unsupported or guard state updates so the latest mutation result remains visible.

Actual behavior

The older response can call setData(result) after the newer response and leave the UI showing stale mutation data.

Metadata

Metadata

Assignees

Labels

assignedIssue claimed by a contributor.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions