Skip to content

bug(data): useMutation treats 204/empty successful responses as failures #3755

Description

@Tomeshwari-02

Summary

useMutation always calls
esponse.json() after any
esponse.ok result in packages/data/src/hooks/useMutation.ts. Successful mutation endpoints often return 204 No Content or another empty body, so the hook throws a JSON parse error even though the HTTP request succeeded.

Reproduction

  1. Use useMutation('/resource/1', 'DELETE') against an endpoint that returns 204 No Content.
  2. Call mutate(undefined).
  3. The fetch succeeds, but �wait response.json() rejects because there is no body.

Expected behavior

A successful empty response should be treated as a successful mutation. The hook could return
ull/undefined, avoid setting an error, and still increment mutationCount.

Actual behavior

The mutation is reported as failed with a parse error, even though the server returned a successful status.

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