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

Multiple fetch request starts to not resolve or reject promise #10

Closed
cpojer opened this issue Feb 12, 2019 · 11 comments · Fixed by #15
Closed

Multiple fetch request starts to not resolve or reject promise #10

cpojer opened this issue Feb 12, 2019 · 11 comments · Fixed by #15
Assignees
Labels
bug Something isn't working iOS released

Comments

@cpojer
Copy link

cpojer commented Feb 12, 2019

See facebook/react-native#21862

@hiennguyen92
Copy link

any update? I met this issue and didn't know how to solve it

@matt-oakes
Copy link
Collaborator

Hi @hiennguyen92. We've just migrated this issue and I'm planning to look into it and, the others, soon. Feel free to subscribe to this issue and you will be notified when a fix is available.

@matt-oakes
Copy link
Collaborator

I have reproduced the error using this minimal testcase:

import React, {Component} from 'react';
import {Button, View} from 'react-native';
import NetInfo from '@react-native-community/netinfo';

export default class App extends Component {
  _onPress() {
    const fullUrl = 'https://google.com';
    for (let i = 0; i < 10; i++) {
      console.log(i);
      NetInfo.isConnected.fetch().then(isConnected => {
        console.log('NetInfo.isConnected.fetch-success', isConnected);
        fetch(fullUrl)
          .then(response => {
            console.log('fetch-success', response);
          })
          .catch(error => console.log('fetch-error', error));
      }).catch(error => console.log('NetInfo.isConnected.fetch-error', error));
    }
  }

  render() {
    return (
      <View style={{flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: "white"}}>
        <Button onPress={this._onPress} title="Reproduce 🕷" />
      </View>
    );
  }
}

The error lies in the Objective C code. I will look into a fix for it.

@kriskate
Copy link

Encountered the same issue.
As a fix for calling multiple fetch requests (downloading almost 1000 images), I have used es-promise-pool with a concurrency of 5.

@matt-oakes
Copy link
Collaborator

@kriskate Thanks for posting a workaround. A proper fix for this will be coming in the next release, hopefully, this week 👍

kriskate added a commit to kriskate/pocket-dota that referenced this issue Feb 18, 2019
react-native-community-bot pushed a commit that referenced this issue Feb 21, 2019
## [1.2.1](v1.2.0...v1.2.1) (2019-02-21)

### Bug Fixes

* **iOS:** Ensure all calls to isConnected.fetch resolve ([#15](#15)) ([afa0825](afa0825)), closes [#10](#10)
@react-native-community-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 1.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@matt-oakes
Copy link
Collaborator

What the bot said ⬆️

@dereknelson
Copy link

@matt-oakes thanks for the fix!! With this being moved out of react native core, will this fix land in the rn core version of NetInfo? or will we have to install/use this NetInfo instead?

@matt-oakes
Copy link
Collaborator

@dereknelson You will need to switch to this version of the library. The instructions are in the README and there have been no breaking changes since the core version aside from removing the long deprecated methods.

@dereknelson
Copy link

dereknelson commented Feb 21, 2019

@matt-oakes gotcha, I'm using expo which uses a forked version of the react-native repo so I wasn't sure how I could get this fix in there. Thanks!

Edit - expo is planning on adopting this package in their SDK: expo/expo#3552

@matt-oakes
Copy link
Collaborator

@dereknelson Thanks for finding that link to the Expo issue! I guess you'll need to wait for that to be included and for a new version to be released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working iOS released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants