Skip to content

createJsonMutation mapData always return null on React Native #554

@ArtemBozhenko

Description

@ArtemBozhenko

createJsonMutation have a responce.body check

async function isEmptyResponse(response: Response): Promise<boolean> {
  if (!response.body) {
    return true;
  }

  const headerAsEmpty = response.headers.get('Content-Length') === '0';
  if (headerAsEmpty) {
    return true;
  }

  // Clone response to read it
  // because response can be read only once
  const clonnedResponse = response.clone();
  const bodyAsText = await clonnedResponse.text();
  if (bodyAsText.length === 0) {
    return true;
  }

  return false;
}

In React Native, response.body is always null / undefined (because there is no ReadableStream), even when the response actually has a body and a valid Content-Length.

As a result, this condition:

if (!response.body) {
  return true;
}

makes isEmptyResponse always return true on React Native

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