Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Regression] [0.57] Fetching images on iOS fails with an empty fetch body and warning that "Received data was not a string, or was not a recognized encoding." #21092

Closed
3 tasks done
tallpants opened this issue Sep 13, 2018 · 2 comments
Labels
Bug Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. 🌐Networking Related to a networking API. Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.

Comments

@tallpants
Copy link

Environment

  React Native Environment Info:
    System:
      OS: macOS High Sierra 10.13.6
      CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
      Memory: 417.92 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 8.11.4 - /usr/local/bin/node
      Yarn: 1.9.4 - /usr/local/bin/yarn
      npm: 6.4.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
      Android SDK:
        Build Tools: 23.0.1, 25.0.2, 26.0.0, 26.0.2, 26.0.3, 27.0.3, 28.0.0
        API Levels: 23, 25, 26, 27, 28
    IDEs:
      Android Studio: 3.1 AI-173.4819257
      Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.5.0 => 16.5.0
      react-native: 0.57.0 => 0.57.0

Description

Trying to fetch an image on iOS errors out with "Received data was not a string, or was not a recognized encoding." The body of the fetch response is empty:

screen shot 2018-09-08 at 12 26 20 am

Output from debug console for iOS:

screen shot 2018-09-08 at 12 27 09 am

This works absolutely fine on Android.
Output from debug console on Android:

screen shot 2018-09-08 at 12 31 42 am

This is definitely a regression since this worked absolutely on fine on iOS on the 0.55 release (the same version that's currently used by Expo as of 13th September 2018 -- 0.55.4 to be precise). Blobs should be fetch-able since 0.54: (https://github.com/facebook/react-native/releases/tag/v0.54.0)

Reproducible Demo

react-native init a new app, and paste this in App.js:

import React from 'react'
import { Text, View } from 'react-native'

export default class App extends React.Component {
  async componentDidMount() {
    const x = await fetch('https://placekitten.com/g/1000/1000')
    console.log(x)
  }

  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
        <Text>Hello, React Native!</Text>
      </View>
    )
  }
}

Also tried with this direct file URL: https://i.imgur.com/w45SLoD.jpg

@react-native-bot react-native-bot added 🌐Networking Related to a networking API. Platform: iOS iOS applications. Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. labels Sep 13, 2018
@Gregoirevda
Copy link
Contributor

I saw that fetch (whatwg-fetch) calls let xhr = new XMLHttpRequest() and xhr.responseType is "". Which is transformed to "text" by default. IOS code will, based on responseType handle the response as text and not blob.

Changing xhr variable at runtime (debugger on fetch and go inside function call) to xhr.responseType = 'blob' solves the issue.

I don't know if this is related to whatwg-fetch or ios code

facebook-github-bot pushed a commit that referenced this issue Dec 11, 2018
…22063)

Summary:
This is a problem that is discussed in issue #21092

Related issues: #21851 #19717

Found the code to eventually fix this issue [here](https://github.com/github/fetch/blob/899b155746630c32d83ee29a38642da16b314ecb/fetch.js#L486)

- [x] Fetching an image locally and check if the blob is there, as well as its size > 0.

___
Help reviewers and the release process by writing your own release notes. See below for an example.

[GENERAL] [ENHANCEMENT] [whatwg-fetch] - set blob as default XMLHttpRequest header response type if supported
Pull Request resolved: #22063

Differential Revision: D13408797

Pulled By: cpojer

fbshipit-source-id: 9822d5a7e24bacd72838f3fc9a61b1a97b44484b
lnikkila pushed a commit to Boulevard/react-native that referenced this issue Jan 21, 2019
…acebook#22063)

Summary:
This is a problem that is discussed in issue facebook#21092

Related issues: facebook#21851 facebook#19717

Found the code to eventually fix this issue [here](https://github.com/github/fetch/blob/899b155746630c32d83ee29a38642da16b314ecb/fetch.js#L486)

- [x] Fetching an image locally and check if the blob is there, as well as its size > 0.

___
Help reviewers and the release process by writing your own release notes. See below for an example.

[GENERAL] [ENHANCEMENT] [whatwg-fetch] - set blob as default XMLHttpRequest header response type if supported
Pull Request resolved: facebook#22063

Differential Revision: D13408797

Pulled By: cpojer

fbshipit-source-id: 9822d5a7e24bacd72838f3fc9a61b1a97b44484b
@minimaluminium
Copy link

@Gregoirevda Oh god, you just saved my day. I was using fetch(), rn-fetch-blob with no luck for an entire day. Thanks a lot.

@hramos hramos removed the Bug Report label Feb 6, 2019
facebook-github-bot pushed a commit that referenced this issue May 7, 2019
Summary:
Our Blob implementation was very problematic because it didn't release its underlying resource when the JS instance was dealocated. The main issue is that the fetch polyfill uses blobs by default if the module is available, which causes large memory leaks.

This fixes it by using the new jsi infra to attach a `jsi::HostObject` (`BlobCollector`)  to `Blob` instances. This way when the `Blob` is collected, the `BlobCollector` also gets collected. Using the `jsi::HostObject` dtor we can schedule the cleanup of native resources. This is definitely not the ideal solution but otherwise it would require rewriting the whole module using TurboModules + jsi.

Fixes #23801, #20352, #21092

[General] [Fixed] - [Blob] Release underlying resources when JS instance in GC'ed
Pull Request resolved: #24405

Differential Revision: D15237418

Pulled By: cpojer

fbshipit-source-id: 00a94a54b0b172fbc62324364b753d192ac7016a
facebook-github-bot pushed a commit that referenced this issue May 8, 2019
Summary:
Our Blob implementation was very problematic because it didn't release its underlying resource when the JS instance was dealocated. The main issue is that the fetch polyfill uses blobs by default if the module is available, which causes large memory leaks.

This fixes it by using the new jsi infra to attach a `jsi::HostObject` (`BlobCollector`)  to `Blob` instances. This way when the `Blob` is collected, the `BlobCollector` also gets collected. Using the `jsi::HostObject` dtor we can schedule the cleanup of native resources. This is definitely not the ideal solution but otherwise it would require rewriting the whole module using TurboModules + jsi.

Fixes #23801, #20352, #21092

[General] [Fixed] - [Blob] Release underlying resources when JS instance in GC'ed
Pull Request resolved: #24745

Reviewed By: fkgozali

Differential Revision: D15248848

Pulled By: hramos

fbshipit-source-id: 1da835cc935dfbf4e7bb6fbf2aea29bfdc9bd6fa
@facebook facebook locked as resolved and limited conversation to collaborators May 9, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label May 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Impact: Regression Describes a behavior that used to work on a prior release, but stopped working recently. 🌐Networking Related to a networking API. Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

6 participants