什么可能导致本机反应缓慢? [英] What could be causing this slow fetch in react native?

查看:39
本文介绍了什么可能导致本机反应缓慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下代码中,第一条 console.log 消息几乎立即打印出来.然后一切都挂了(我最初假设它正在等待返回响应的正文).响应的正文只有大约 26K,等待的时间似乎是无限的,除非我摇晃手机并与调试菜单交互.一旦我与调试菜单交互,承诺就会解决,一切都按预期进行.我与调试菜单的交互可以很简单,比如隐藏检查器、显示检查器,只需采取一些措施来启动承诺解决方案,一切都很好.

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.

可能在 https://github.com/facebook/react-native/issues/6679

推荐答案

这是一个已知错误,即在启用远程调试时解析响应可能会严重滞后.禁用远程调试应该会大大加快速度.

It is a known bug that parsing responses can lag badly when remote debugging is enabled. Disabling remote debugging should speed this up a lot.

您可以阅读问题了解详情和其他解决方法.

You can read the issue for details and other workarounds.

这篇关于什么可能导致本机反应缓慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆