refactorjs/ofetch

Request abortion does not work

Opened this issue · 0 comments

Hi! I am using this module transitively through https://github.com/nuxt-alt/http and request cancellation using an AbortController is not working since version 1.0.15.

This is because the signal is getting overriden by the one this lib uses to implement timeouts from what it looks like:

// index.mjs:268
dispatchRequest_fn = async function(config) {
  const controller = new AbortController();
  const timeoutSignal = config.timeout ? setTimeout(() => controller.abort(), config.timeout) : void 0;
  const $ofetch = this.getFetch();
  let response;
  config = config.timeout ? { ...config, signal: controller.signal } : config;
  config = __privateMethod(this, _addXSRFHeader, addXSRFHeader_fn).call(this, config);
  ...
}

My code:

const abortController = new AbortController()
abortController.abort()
await $http.$get("/", { signal: abortController.signal })

In version 1.0.14 this is getting cancelled as expected, starting from version 1.0.15 it is not.

Thanks for looking.