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

fetch(${imageUrl}) throw RCTDeviceEventEmitter:emit error when fetch image without Debug JS Remotely #11764

Closed
peichao01 opened this issue Jan 7, 2017 · 6 comments
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@peichao01
Copy link

peichao01 commented Jan 7, 2017

Description

when fetch(imgUrl), throw an error(and can not relation to fetch API after read the Error message),
works fine in Debug JS Remotely

Reproduction

componentDidMount() {
  var avatarUrl = 'https://avatars1.githubusercontent.com/u/844740?v=3&s=88';
  fetch(avatarUrl);
}

Solution

Additional Information

  • React Native version: [0.39, 0.40]
  • Platform: [Android6, not test Android7, not test iOS]
  • Operating System: [MacOS]

image

@yinoneliraz
Copy link

Got the same error with componentWillReceiveProps.

  componentWillReceiveProps(nextProps){
    var temp;
    temp=this.state.profileInfo;
    temp.image='http://s3.amazonaws.com/cdn.roosterteeth.com/default/tb/user_profile_female.jpg';
    this.setState({
      profileInfo:temp,
    }, () => {
      console.log(this.props);
      console.log("Updated!!!");

      var api = 'https://graph.facebook.com/' + nextProps.owner_id +
        '/picture?type=normal&access_token=' + nextProps.credentials.token;
      fetch(api)
        .then((response) => {
          var temp;
          temp = this.state.profileInfo;
          temp.image = response.url;
          this.setState({
            profileInfo: temp,
          });
        })
        .done();
    });
  },

@eggytronixx
Copy link

eggytronixx commented May 4, 2017

I got the same issue. It only works in Debug JS Remotely using the fetch API. Idk if this is useful in your case, but I did the following. I created an AsyncImage Component to handle prefetching source, and using defaultSource in till Image prefetch completes.

class AsyncImage extends Component {

constructor(){
    super();

    this.state = {
        isLoadable: false
    };

}

componentWillMount(){

    const {source} = this.props;

    if(source && source.uri){

        this.fetchSource(source);

    }

}

async fetchSource(source){

    let res;

    try {

        await Image.prefetch(source.uri)

    } catch(e){

        return new Promise(resolve => this.setState({isLoadable: false}));

    }

    return new Promise(resolve => this.setState({isLoadable: true}));


}

render(){

    const {isLoadable} = this.state;
    const {round, size, defaultSource, source} = this.props;

    let imgStyles = {
        height: size,
        width: size,
        borderWidth: 0.5,
    }

    if (round){
        imgStyles.borderRadius = size / 2;
    }

    return <Image style={imgStyles} source={isLoadable ? source : defaultSource}/>

}
}

@arsenslyusarchuk
Copy link

Similar issue happens on Android (IOS works fine). Anybody resolved this?

@hbarylskyi
Copy link

Same issue while fetching images on react-native v0.44.1

@cbjs
Copy link

cbjs commented Sep 9, 2017

+1

@stale
Copy link

stale bot commented Nov 8, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Nov 8, 2017
@stale stale bot closed this as completed Nov 15, 2017
@facebook facebook locked and limited conversation to collaborators May 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

6 participants