react-native icon indicating copy to clipboard operation
react-native copied to clipboard

response.json() hangs when chrome debugging

Open NgoKnows opened this issue 10 years ago • 122 comments

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

NgoKnows avatar Mar 27 '16 02:03 NgoKnows

cc @martinbigio we were talking about this

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

satya164 avatar Mar 28 '16 02:03 satya164

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

NgoKnows avatar Mar 28 '16 06:03 NgoKnows

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.

mark0978 avatar Mar 28 '16 12:03 mark0978

@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

martinbigio avatar Mar 28 '16 13:03 martinbigio

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.

steveluscher avatar Mar 28 '16 15:03 steveluscher

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

mark0978 avatar Mar 28 '16 15:03 mark0978

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.

mj1618 avatar Mar 28 '16 15:03 mj1618

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);
    });

sbekrin avatar Mar 29 '16 10:03 sbekrin

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

mark0978 avatar Mar 29 '16 12:03 mark0978

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

martinbigio avatar Mar 30 '16 14:03 martinbigio

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.

mark0978 avatar Mar 30 '16 17:03 mark0978

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.

thorbenandresen avatar Mar 30 '16 20:03 thorbenandresen

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

martinbigio avatar Mar 30 '16 21:03 martinbigio

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

Please consult the spec before fixing stuff.

davidaurelio avatar Mar 31 '16 08:03 davidaurelio

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

thorbenandresen avatar Apr 19 '16 13:04 thorbenandresen

No, this is in 0.25-rc

bestander avatar Apr 19 '16 13:04 bestander

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

thorbenandresen avatar Apr 19 '16 14:04 thorbenandresen

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

bestander avatar Apr 19 '16 14:04 bestander

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.

thorbenandresen avatar Apr 19 '16 14:04 thorbenandresen

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);
// }

jrichardlai avatar Apr 23 '16 00:04 jrichardlai