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

(H5) 不支持fetch的浏览器调用request时无法返回结果 #7161

Closed
vdfor opened this issue Jul 25, 2020 · 0 comments · Fixed by #7162
Closed

(H5) 不支持fetch的浏览器调用request时无法返回结果 #7161

vdfor opened this issue Jul 25, 2020 · 0 comments · Fixed by #7162
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Milestone

Comments

@vdfor
Copy link
Contributor

vdfor commented Jul 25, 2020

相关平台

H5

复现仓库

https://github.com/vdfor/taro-issues-demo/tree/master/h5-fetch-polyfill
浏览器版本: HTC Browser 6
使用框架: React

复现步骤

直接通过最小话仓库运行 yarn run dev:h5 , 查看控制台。

或者

  1. taro init taro-demo
  2. 修改index.html,将window.fetch强制为fetch(模拟浏览器为不支持fetch)
  3. 随意写个request请求,如
async componentDidMount () {
    try {
      await request({
        url: 'https://cnodejs.org/api/v1/topic/5433d5e4e737cbe96dcef312'
      })
    } catch (error) {
      console.error('error => ', error)
    }
  }

批注 2020-07-25 170907

期望结果

不支持fetch的浏览器也可以使用通过polyfill来使用request

实际结果

不支持fetch的浏览器无法使用request

环境信息

Taro CLI 3.0.5 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 12.18.3 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.4 - C:\Users\vdfor\AppData\Roaming\npm\yarn.CMD
      npm: 6.14.6 - C:\Program Files\nodejs\npm.CMD

补充信息

在 taro-h5/src/api/request/index.js (80行) 的 response.headers —— 在支持fetch的浏览器其为Map对象,在不支持fetch的浏览器上,通过unfetch/polyfill兼容,其值为普通对象,不可使用 forEach 进行遍历。

@taro-bot2 taro-bot2 bot added F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x labels Jul 25, 2020
@vdfor vdfor changed the title 不支持fetch的浏览器调用request时无法返回结果 (H5) 不支持fetch的浏览器调用request时无法返回结果 Jul 25, 2020
@Chen-jj Chen-jj added this to the 3.0.6 milestone Jul 28, 2020
@Chen-jj Chen-jj linked a pull request Jul 28, 2020 that will close this issue
20 tasks
@Chen-jj Chen-jj closed this as completed Jul 28, 2020
@ZakaryCode ZakaryCode added this to Done in H5 Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Archived in project
H5
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants