Fix stale closure in delayed autosave callback

intermediate
By FrontendAtlas Editorial · Updated Oct 22, 2026
A teammate tried to make autosave "predictable" by capturing the current draft when wiring a delayed callback. That feels reasonable until the user keeps typing: the callback keeps saving the old draft it closed over instead of the latest one. Fix the bug so delayed saves read fresh state at execution time.
Examples
const autosave = createDraftAutosave('hel');
let flush;
autosave.install(cb => { flush = cb; }, value => value);
autosave.setDraft('hello');
flush(); // 'hello'

const autosave = createDraftAutosave('a');
let flush;
autosave.install(cb => { flush = cb; }, value => value);
autosave.setDraft('ab');
flush(); // 'ab'
autosave.setDraft('abc');
flush(); // 'abc'

Public interview reports

These public, self-reported interview accounts informed this practice version. The exercise is modelled on reported rounds, not copied from them, and the reports are not verified official questions or endorsements.

  • Taro: Stripe frontend engineer interview, 2023 · Taro, October 2023

    One Stripe front end engineer account lists a round on bug finding within an unknown project. This debug exercise practises that shape in a small codebase; it is not the reported bug.

Reported in a public Stripe interview account. Stripe frontend interview questions