NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.65k stars 4.8k forks source link

Taro request 添加了异步拦截器之后, abort 丢失 #16897

Open rotate-life opened 4 days ago

rotate-life commented 4 days ago

相关平台

微信小程序

小程序基础库: 3.2.4 使用框架: React

复现步骤

function interceptor(chain: Taro.Chain) {
  const { requestParams } = chain
  let p: Promise<void>
  const res = new Promise<void>((resolve, reject) => {
    const timeout: ReturnType<typeof setTimeout> = setTimeout(() => {
      p = chain.proceed(requestParams)
      p
        .then((r: any) => {
          resolve(r)
        })
        .catch((err) => {
          reject(err)
        })
    }, 3000)
  })
  // @ts-ignore
  if (!isUndefined(p) && isFunction(p.abort)) res.abort = p.abort
  return res
}

const requestTask = Taro.request()

requestTask.abort()

期望结果

正常返回abort并且可以正常使用

实际结果

TypeError: requestTask.abort is not a function

环境信息

👽 Taro v3.6.17

  Taro CLI 3.6.17 environment info:
    System:
      OS: macOS 13.4.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 16.20.1 - /usr/local/bin/node
      Yarn: 1.22.19 - /usr/local/bin/yarn
      npm: 8.19.4 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.17 => 3.6.17 
      @tarojs/components: 3.6.17 => 3.6.17 
      @tarojs/helper: 3.6.17 => 3.6.17 
      @tarojs/plugin-framework-react: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-alipay: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-h5: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-jd: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-qq: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-swan: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-tt: 3.6.17 => 3.6.17 
      @tarojs/plugin-platform-weapp: 3.6.17 => 3.6.17 
      @tarojs/react: 3.6.17 => 3.6.17 
      @tarojs/runtime: 3.6.17 => 3.6.17 
      @tarojs/shared: 3.6.17 => 3.6.17 
      @tarojs/taro: 3.6.17 => 3.6.17 
      @tarojs/taro-loader: 3.6.17 => 3.6.17 
      @tarojs/webpack5-runner: 3.6.17 => 3.6.17 
      babel-preset-taro: 3.6.17 => 3.6.17 
      eslint-config-taro: 3.6.17 => 3.6.17 
      react: ^18.0.0 => 18.2.0 

补充信息

场景:每次发起请求前,检验token,在过期时,尝试更新一次token