latestRequest()
Ignore outdated search responses.
Try the example
Load Design, then immediately load Engineering. Design is deliberately slower. Only the most recently requested team can appear, even when the earlier request finishes later.
Older results will never replace your latest selection.
Choose a team.
Add it to your project
- Copy the HTML. Place the markup inside the component where this behavior belongs. The preview’s visual classes are website styles; use your own design system.
- Connect the behavior. Copy the JavaScript tab and call its exported
mount(element)after your component’s elements exist. Replace simulated delays and data operations with your own application code. - Clean up. Call the returned cleanup when the component unmounts. It aborts the example’s listeners and releases the helper’s timers, observers or state.
API and lifecycle
Wrap task(signal, ...args), then call run(...args) for each new query. Each run aborts the previous signal and uses a generation check so an older result cannot become the newest successful result.
- Interface
task(signal,...args); run, cancel, destroy- Lifecycle
- run() resolves with success and value, error and error, or stale. Render only a successful current result. cancel() and destroy() invalidate pending work and abort the current signal.
Accessibility and safety
Implementation notes
Initialize after the DOM is available. Keep native controls and keyboard interactions intact; release listeners and timers on unmount.
Aborting a client request does not reverse a server-side action. Use this for replaceable reads and keep error and loading feedback accessible.
What to check
Start a slow request followed by a fast one, including a task that ignores AbortSignal. Confirm the slow result never replaces the latest result.