The Infinite Spinner — JavaScript Bug Hunt

Inspired by the most-screenshotted bug in any app: the spinner that never stops. The loading flag is cleared on success — and only on success.

  • Language: JavaScript
  • Layer: Frontend
  • Difficulty: Easy
  • Concepts: State, Error Handling
  • Modelled on: Every SPA
  • Visible tests: errors stop the spinner; success stores the data
  • Reward: 50 XP for a complete fix

Briefing

Inspired by the most-screenshotted bug in any app: the spinner that never stops. The loading flag is cleared on success — and only on success. One failed request and the UI spins until a refresh.

loading.js folds request lifecycle events.

Bug report

BUG-SPINNER · Reported by: support (screenshot supply is infinite)

reduce(state, event) — events: start / success / error:

  • start -> loading true, error null
  • success -> loading false, data set
  • error -> loading FALSE, error message set

Observed: the error branch forgets the flag; failed dashboards spin forever.

Logs

[ui] request failed; isLoading still true 45 minutes later

The code as shipped

src/ui/loading.js (editable)

// Request lifecycle reducer.
exports.reduce = function (state, event) {
  if (event.type === "start") {
    return { loading: true, data: state.data, error: null };
  }
  if (event.type === "success") {
    return { loading: false, data: event.data, error: null };
  }
  if (event.type === "error") {
    return { loading: state.loading, data: state.data, error: event.message };
  }
  return state;
};

Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.