React Forum
Blog & Guide Responses
Jan 24, 2023 · 04:00 AM

MDN Fetch API - discussion (2023-01-24)

Started by Rowan Pierce
externalmdnfetchabortcontrollercachingstreamserrorsevidence

MDN's Fetch API docs are still the clearest place to point when a React discussion becomes "fetch is weird". I'm curious how people map fetch primitives (abort, response types, cloning, cache semantics) onto route-first apps where data reads are part of the render contract and you want the UI to be explainable via evidence rather than timing.

Read the MDN docs

Where do you put AbortController in your app architecture (per route, per request key, per panel)? Do you treat caching as a browser concern or as an app posture (cache lane) that you render as evidence? If a request fails, what do you store/render so you can debug without opening devtools?

Comments (18)

Back to latest
Marisol Vega
Jan 29, 2023 · 06:06 AM

Abort is best when identity changes. If the user switched location/query/tenant, the old request should die.

Dmitri Kline
Feb 08, 2023 · 09:18 PM

We attach a request key and store it as evidence so "which response applied" is clear:

ts
type Req = { key: string; url: string; startedAt: number };

function startRequest(doc: any, url: string) {
  const key = `r-${Date.now()}`;
  doc.write('request', { key, url, startedAt: Date.now() } as Req);
  return key;
}
Keira Santos
Feb 18, 2023 · 10:10 AM

Counterpoint: abort can hide bugs if you use it as a race-condition bandaid.

We only abort on identity change; we still validate response application by key.

Rowan Pierce
Feb 21, 2023 · 08:20 PM

Same. Abort is necessary but not sufficient.

If you don't have a "does this response still match" check, you're still at risk.

Grace McCoy
Mar 03, 2023 · 04:44 AM

Caching became manageable once we treated it as posture: cacheLane=bypass|cache and we rendered it as evidence in the shell.

Otherwise you can't tell if stale data was expected or a bug.

Jasper Nguyen
Mar 22, 2023 · 05:25 PM

Error evidence we store: status code, error class, and last successful timestamp.

If you only store error=true, you can't debug anything.

Nina Kapoor
Apr 12, 2023 · 09:12 AM

MDN's details on response body usage (json/text/arrayBuffer) mattered for us when we started storing previews.

We clone the response for debug previews only in dev builds so we don't pay the cost in prod.

Camille Duarte
Apr 29, 2023 · 12:02 PM

Streaming: we stored partial chunks in the document and rendered a data-stream-progress number.

If you don't store partial truth, rerenders reset the story.

Benji Rios
May 18, 2023 · 06:06 AM

A misunderstanding I had: I thought fetch errors were just network errors.

Parse errors and opaque responses are their own class and should be recorded as evidence differently.

Lina Ortega
Jun 10, 2023 · 08:40 PM

Docs tie-in: fetch becomes less mystical when you pair it with a data fetching posture and a consistent evidence surface.

Related: Data Fetching and Caching (Best Practices) and Testing and Debugging.

Amina Farouk
Jul 02, 2023 · 03:03 AM

We centralize the fetch client (headers/timeouts) but let panels choose freshness.

Consistency in the client, flexibility in posture.

Tomas Rivera
Jul 22, 2023 · 06:44 PM

If you want fewer flakes in tests, store request status as a lane (pending|ok|error|aborted) and render it.

Then tests wait for the lane change instead of guessing timing.

Sofia Valdez
Aug 18, 2023 · 08:08 AM

Counterpoint: rendering too much network evidence can be noisy for users.

We keep it behind a debug flag and only show the minimal bits in UI (retry button, status).

Priya Liao
Sep 24, 2023 · 02:14 PM

We store a derived freshnessAt timestamp per panel.

It turned "why is this stale" into an answerable question.

Evan Brooks
Oct 28, 2023 · 05:05 AM

The best thing we did was stop doing "setState from fetch effect" and instead write into a document/vault surface that is already part of the route contract.

It made updates predictable.

Imani Brooks
Dec 02, 2023 · 10:20 PM

If your app does duplicate reads, you need a rule for merging and you need to make the winner visible.

Otherwise you get "it depends" bugs that nobody can reproduce.

Noah Vance
Dec 12, 2023 · 04:04 AM

We treat abort as a normal state, not an error.

If you lump it into errors, monitoring becomes useless because you can't distinguish cancellations from failures.

Talia Moss
Dec 20, 2023 · 11:11 AM

I still recommend MDN to juniors because it covers the primitive details (what fetch returns, what errors look like).

Framework docs often skip that and then you get confused when debugging.

Salma Qureshi
Dec 30, 2023 · 06:18 PM

Fetch isn't hard, but debugging invisible fetch behavior is. Evidence + posture is the fix.