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

response.json() hangs when chrome debugging #6679

Closed
NgoKnows opened this issue Mar 27, 2016 · 122 comments
Closed

response.json() hangs when chrome debugging #6679

NgoKnows opened this issue Mar 27, 2016 · 122 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@NgoKnows
Copy link

When using fetch to make a get to an external api, and if debugging in chrome is active, then it never reaches the second "then" until there is an interaction with the UI, such as a tap on the screen, but if debugging is turned off then this problem goes away.

fetch(requestURL)
    .then((res) => res.json())
    .then((resData) => {
        this.setState({
            suggestions: resData.Similar.Results
        });
    })
    .done()

Using React Native 0.22
Only occurs on Android (both Genymotion and on device (5.0))
Using a Mac

@satya164
Copy link
Contributor

cc @martinbigio we were talking about this

Do sourcemaps in redbox work for you on Android when you're connected to the debugger?

@NgoKnows
Copy link
Author

Now that you mention it, nope, sourcemaps in redbox are not working when connected to the debugger.

@mark0978
Copy link

Got the same problem on linux with the v0.22 as well. Interacting with the debug menu breaks the logjam.

For me, sourcemaps stop working after a while and I start seeing the transpiled code. That is happening when this error is occurring. But the problem also happens after a reboot before the sourcemaps stop working.

From Stackoverflow: http://stackoverflow.com/questions/36262456/what-could-be-causing-this-slow-fetch-in-react-native

In the following code, the first console.log message prints pretty much instantly. Then everything just hangs (I'm initially assumed it was waiting for the body of the response to be returned). The Body of the response is only about 26K, the time waiting seems to be indefinite UNLESS, I shake the phone and interact with the debug menu. * As soon as I interact with the debug menu, the promise resolves and everything moves along as expected.* My interactions with the debug menu can be simple, like hide inspector, show inspector, just takes something to kick the promise resolution into gear and everything is fine.

    fetch(SEARCH_URL, requestBody)
        .then((response) => {console.log(response); return response.json();})
        .then((responseData) => {
            debugger
            ...

Note:
Disconnecting from the debugger and running the code does not exhibit the slowness (and not being connected to the debugger ignores the debugger statements)

And yes, I have rebooted the computer.

@martinbigio
Copy link
Contributor

@steveluscher you were looking into setTimeout issues. Could this be related?

@cpojer, @skevy have we recently made any change to the Promise implementation?

cc @bestander, @vjeux

@steveluscher
Copy link
Contributor

I've been seeing ‘setTimeout never fires’ behavior intermittently as well, with timeouts > 0ms. The only clue that I had was that my Genymotion simulator clock and my system clock seem to drift apart over time. I didn't try opening the debug menu when stuck, nor have I noticed this on device yet (I haven't done anything on device in a while). That you've experienced the same behavior on device as you have in Genymotion makes me think it's not going to prove to be clock drift between the host running Chrome and the host running the app.

@mark0978
Copy link

Takes more than opening the menu, you have to choose something from it, like hide/show inspector. I'm not using a simulator.

@mj1618
Copy link

mj1618 commented Mar 28, 2016

I'm having the same issue on an S4 mini, except I can stop the behaviour by tapping the screen without opening the debug menu.

@sbekrin
Copy link

sbekrin commented Mar 29, 2016

Got same issue with response.text(), response.json() and response.arrayBuffer(), but response.blob() seems to work fine. Versions are:

react-native-cli: 0.2.0
react-native: 0.22.2
Android 5.1.1

Quick workaround is to add empty timeout execution:

fetch('http://example.com')
    .then(response => {
        setTimeout(() => null, 0);
        return response.text();
    })
    .then(response => {
        console.log(response);
    });

@mark0978
Copy link

I can confirm just tapping anywhere on the screen does work around this problem.

@martinbigio
Copy link
Contributor

Do we know when this regression started repro-ing? Do you guys mind sharing which version of react-native you're using? I want to make sure this is not a regression of the current RC.

cc @bestander

@mark0978
Copy link

It was in a version installed from npm on March 24. I don't know the version at the moment, but I can look it up tonight.

@thorbenandresen
Copy link

I have the same problem with 0.22 and iOS on my mac (installed 1 hour ago).

Tapping anywhere + the setTimeOut workaround does not work for me.

@martinbigio
Copy link
Contributor

So this may have been introduced on 0.22, so not 0.23 launch blocker though we should fix asap.

@davidaurelio
Copy link
Contributor

This is due to our incomplete XHR2 implementation. Check this code that was added with cbc0e21.

Please consult the spec before fixing stuff.

@ghost ghost closed this as completed in fcc89e9 Apr 11, 2016
ide pushed a commit that referenced this issue Apr 11, 2016
Summary:Fixes #6679

This adds support for the missing response types to XMLHttpRequest.
Don?t ship this yet. This is completely untested. yolo and stuff.
Closes #6870

Reviewed By: bestander

Differential Revision: D3153628

Pulled By: davidaurelio

fb-gh-sync-id: 76feae3377bc24b931548a9ac1af07943b1048ac
fbshipit-source-id: 76feae3377bc24b931548a9ac1af07943b1048ac
@thorbenandresen
Copy link

thorbenandresen commented Apr 19, 2016

Should this be fixed in 0.24? The problem persists for me with 0.24

@bestander
Copy link
Contributor

No, this is in 0.25-rc

@thorbenandresen
Copy link

Is it fixed in v0.25.0-rc? Because it persists there as well...

@bestander
Copy link
Contributor

Actually the commit is supposed to be in 0.24.1, it has been cherry-picked into the branch https://github.com/facebook/react-native/commits/0.24-stable.
If you still reproduce the bug then the fix does not work.
cc @davidaurelio

@thorbenandresen
Copy link

thorbenandresen commented Apr 19, 2016

yes - I still reproduce the error with 0.24.1 - Am I supposed to to do any changes to my code? I have not changed it since it broke around 0.22.

@jrichardlai
Copy link
Contributor

It seems something is off with the sourcemap, the one from my bundle has multiple sections but it seems that when we parse it we expect to be flat https://github.com/facebook/react-native/blob/master/Libraries/JavaScriptAppEngine/Initialization/SourceMap.js#L1086
The sourcemap I get using the explorer is flat:
screen shot 2016-04-22 at 4 16 38 pm
But the one I get from my project has sections:
screen shot 2016-04-22 at 4 12 07 pm
The promise is rejected, it seems that SourceMap does not handle sections, I updated it and got the Stacktrace in the red screen working fine after commenting in parseErrorStack, but this didn't fixed the freezing issue of the Chrome Debugger.

// if (frame.file.indexOf(sourceMap.file) !== -1 ||
//     frame.file.replace('.map', '.bundle').indexOf(
//       sourceMap.file
//     ) !== -1) {
  resolveSourceMaps(sourceMap, frame);
// }

@bestander bestander reopened this Apr 25, 2016
@davidaurelio
Copy link
Contributor

@jrichardlai oh yes, that’s a super old version of the source map library. Using what we have in node_modules should do the trick. PR welcome. Will look into the other issue now.

@ericsanjaya
Copy link

ericsanjaya commented May 6, 2016

i have same problem to, i use 0.25.1 and fetch problem not resolve for now. i think fetch is important part to use web service in mobile app and need to fix.
for now i just use version 0.19
my issue same with #7381

@florindobre
Copy link

Any update on this issue? Possible workarounds besides just tapping on the screen.

react-native-cli: 0.2.0
react-native: 0.25.1
Android: 5.1.1

@dattran92
Copy link

Looking for an update. I have upgraded to:

react-native-cli: 0.2.0
react-native: 0.26.0
The problem still occured.

@ccdwyer
Copy link

ccdwyer commented Jun 28, 2017

Having this issue as well. Very frustrating.

@danawoodman
Copy link

How does one debug React Native apps that fetch JSON? 😭 @lacker can you please re-open as this is again an issue

@cablegunmaster
Copy link

@danawoodman debug? Well make log lines everywhere to the console And see where iT reaches like for Every line a console.log("1"); And count up And see which logs arent found And you Got the issue where Its stuck. Use above workarounds to fix it. As there is No generaal fix for this issue.

@rishabhpoddar
Copy link

This error still exists RN 45.1

@danawoodman
Copy link

@cablegunmaster yes, what I am saying is that without a hack you cannot troubleshoot your apps since the debugger causes this issue to fail with fetch.

@jan-happy
Copy link

I was also pulling my hair over this. Glad I've found this issue!

@ghost
Copy link

ghost commented Jul 6, 2017

Didn't encounter this issue before, but once i upgrade from 0.44.0 to 0.46.0 today it pops up. The response.json() is just stuck, doesn't invoke then() nor catch(). Like some said, the fetch() was called from a helper function defined outside of a React component, but is called by a react component.

@raunaqss
Copy link

raunaqss commented Jul 6, 2017

Encounter this issue sometimes only through React Native versions 0.44, 0.45 & 0.46. What would I do without these updated issues on Github and user submitted work around? 👍

@mikelambert
Copy link
Contributor

Yay, this appears to be fixed in 0.47 by 6482538 !

@gautamamrit
Copy link

I too had faced same issue while debugging on ios Emulator with react-native version: "0.46.4". But as @mikelambert suggested, upgrading to version "^0.47.0-rc.5" solved this issue

@maxim-c
Copy link

maxim-c commented Jul 27, 2017

but it still hangs on android devices.

@chug2k
Copy link

chug2k commented Aug 21, 2017

i'm still seeing fetch on android devices being really slow. i'm on 0.49

@mark0978
Copy link

mark0978 commented Aug 21, 2017 via email

@chug2k
Copy link

chug2k commented Aug 21, 2017

of course, why didn't i think of that

@mark0978
Copy link

mark0978 commented Aug 21, 2017 via email

@mikelambert
Copy link
Contributor

Just a reminder @mark0978 and @chug2k , this is fixed in the latest version of RN 0.47.

@maxim-c
Copy link

maxim-c commented Aug 22, 2017

@mikelambert nah... Fixed only for ios, android still broken.

@cablegunmaster
Copy link

cablegunmaster commented Aug 23, 2017

@reactjs-bot @mikelambert I am still following this post as it seems for me just a stupid bug which should be squashed ages ago, but nobody has/takes the time to do so. #android

@Fahad-pnw
Copy link

wtf i spent 12 hours trying to adjust my code, wondering why it wont go within a .then statement of a promise only to find out its a freakin bug

@mark0978
Copy link

mark0978 commented Aug 26, 2017 via email

@JasonHenson
Copy link

you can always make your own pull request to address the issue

@mark0978
Copy link

mark0978 commented Aug 26, 2017 via email

@jstahlmann
Copy link

wtf i spent 12 hours trying to adjust my code, wondering why it wont go within a .then statement of a promise only to find out its a freakin bug

same here!

@hey99xx
Copy link

hey99xx commented Dec 28, 2017

@maxim-c @mikelambert , if this is only fixed for iOS, shouldn't this issue still be open for Android devs? Reading the entire issue, it seems prematurely closed by @lacker , am I wrong?

@cablegunmaster
Copy link

cablegunmaster commented Dec 29, 2017

Its not fixed on Android, just some nasty work arounds. ( tapping on the screen kind of )
Which you don't want the user to do in order to go further.

@amitassaraf
Copy link

This actually still happens on Android, and when using an emulator even tapping the screen doesn't help..

@facebook facebook locked as resolved and limited conversation to collaborators Jul 19, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
tungdo194 pushed a commit to tungdo194/rn-test that referenced this issue Apr 28, 2024
Summary:
Fixes facebook/react-native#6679
Closes facebook/react-native#8512

Differential Revision: D3503958

Pulled By: donyu

fbshipit-source-id: f2102c1051fb3fe1d55ecfa24bed19c8d25224e9
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests