Re: [whatwg/fetch] WIP: Add a mechanism to fetch to track progress (PR #1843)

jakearchibald left a comment (whatwg/fetch#1843)

In WHATNOT, we discussed how to opt into the CORS preflight needed to monitor uploads. The ideas:

## Option 1: Adding the monitor is the opt-in

```js
const response = await fetch('/upload', {
  method: 'POST',
  body: file,
  monitor(m) {
    // …
  },
});
```

The request will do a preflight, because `monitor` exists. The downside is the preflight is only needed to track upload, yet here you trigger it even if you're tracking only other things.

## Option 2: Two monitors

```js
const response = await fetch('/upload', {
  method: 'POST',
  body: file,
  requestMonitor(m) {
    // …
  },
  responseMonitor(m) {
    // …
  }
});
```

One of the monitors handles request stuff, the other handles response stuff. Including `requestMonitor` gets to a preflight.

The downside is, if you're passing those monitors to other bits of code, now you have to pass two around.

The upside is it's explicit.

## Option 3: Boolean opt-in

```js
const response = await fetch('/upload', {
  method: 'POST',
  body: file,
  monitor(m) {
    // …
  },
  monitorUploads: true,
});
```

`monitorUploads` triggers the preflight. Without it, you don't get upload events on the monitor.

This keeps a single monitor object, but maybe developers will get confused about why they're not getting upload events, and not realise there's an additional opt-in.

---

Now I've written them out, I think I prefer option 2.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/pull/1843#issuecomment-7188859424
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/pull/1843/c7188859424@github.com>

Received on Thursday, 26 November 2026 10:05:00 UTC