StatsHub Docs

Outliers

Players whose recent numbers sit furthest from their own baseline — and the hand-rolled fetch whose race condition is worth reading about.

/outliers · src/composed/outliers

Ranks players by distance from their own recent baseline, so the board surfaces form that has moved rather than form that is merely good.

What it used to be

Worth knowing, because the shape recurs. The query was a hand-rolled fetchOutliers: setLoading(true), an await fetch, setOutliers, setError, finally setLoading(false) — fired from a useEffect behind a 500 ms setTimeout, keyed off a JSON.stringify of every filter and a useRef holding the previous value of it.

Four pieces of state tracked what SWR already tracks, and a race was one slow response away: two in-flight requests resolved in arrival order, not request order, so a slow page 1 could overwrite a fast page 2.

What it is now

A derived key. The URL is the input, useDebounced delays the search box rather than the request, and SWR owns loading, error and dedup. Ordering stops being a thing anyone has to think about, because the key that arrived late is not the key being rendered.

The lesson generalises: if you are holding a useRef of the previous filters to decide whether to fetch, you have written a cache key by hand. Make it a key.

On this page