response.json() hangs when chrome debugging
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
cc @martinbigio we were talking about this
Do sourcemaps in redbox work for you on Android when you're connected to the debugger?
Now that you mention it, nope, sourcemaps in redbox are not working when connected to the debugger.
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.
@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
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.
Takes more than opening the menu, you have to choose something from it, like hide/show inspector. I'm not using a simulator.
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.
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);
});
I can confirm just tapping anywhere on the screen does work around this problem.
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
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.
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.
So this may have been introduced on 0.22, so not 0.23 launch blocker though we should fix asap.
This is due to our incomplete XHR2 implementation. Check this code that was added with cbc0e21926594cbe650db34c466b934fda5c13ef.
Please consult the spec before fixing stuff.
Should this be fixed in 0.24? The problem persists for me with 0.24
No, this is in 0.25-rc
Is it fixed in v0.25.0-rc? Because it persists there as well...
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
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.
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:
But the one I get from my project has sections:
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);
// }