Skip to content

fix(useAxios): ignore the result of a superseded request - #5576

Open
lazerg wants to merge 1 commit into
vueuse:mainfrom
lazerg:fix/useaxios-stale-request-5575
Open

fix(useAxios): ignore the result of a superseded request#5576
lazerg wants to merge 1 commit into
vueuse:mainfrom
lazerg:fix/useaxios-stale-request-5575

Conversation

@lazerg

@lazerg lazerg commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

execute() only guarded its .then with isAborted, and any newer execute() call resets that ref to false, so a superseded request could still write its response into data/response and call onSuccess after the newer request had already settled. The .catch branch had no staleness check at all, so a late rejection overwrote error too.

Both branches now compare currentExecuteCounter against executeCounter, the guard the .finally right below already uses. onError still fires for a superseded request, since the abort behaviour covered by the existing tests depends on it.

Fixes #5575

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 9, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vueuse/components

pnpm add https://pkg.pr.new/@vueuse/components@5576
npm i https://pkg.pr.new/@vueuse/components@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/core

pnpm add https://pkg.pr.new/@vueuse/core@5576
npm i https://pkg.pr.new/@vueuse/core@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/electron

pnpm add https://pkg.pr.new/@vueuse/electron@5576
npm i https://pkg.pr.new/@vueuse/electron@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/firebase

pnpm add https://pkg.pr.new/@vueuse/firebase@5576
npm i https://pkg.pr.new/@vueuse/firebase@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/integrations

pnpm add https://pkg.pr.new/@vueuse/integrations@5576
npm i https://pkg.pr.new/@vueuse/integrations@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/math

pnpm add https://pkg.pr.new/@vueuse/math@5576
npm i https://pkg.pr.new/@vueuse/math@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/metadata

pnpm add https://pkg.pr.new/@vueuse/metadata@5576
npm i https://pkg.pr.new/@vueuse/metadata@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/nuxt

pnpm add https://pkg.pr.new/@vueuse/nuxt@5576
npm i https://pkg.pr.new/@vueuse/nuxt@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/router

pnpm add https://pkg.pr.new/@vueuse/router@5576
npm i https://pkg.pr.new/@vueuse/router@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/rxjs

pnpm add https://pkg.pr.new/@vueuse/rxjs@5576
npm i https://pkg.pr.new/@vueuse/rxjs@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/shared

pnpm add https://pkg.pr.new/@vueuse/shared@5576
npm i https://pkg.pr.new/@vueuse/shared@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

@vueuse/skills

pnpm add https://pkg.pr.new/@vueuse/skills@5576
npm i https://pkg.pr.new/@vueuse/skills@5576
yarn add https://pkg.pr.new/@vueuse/[email protected]

commit: 864a86f

@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.03%. Comparing base (e9fe32c) to head (864a86f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5576      +/-   ##
==========================================
+ Coverage   68.01%   68.03%   +0.01%     
==========================================
  Files         349      349              
  Lines        8282     8283       +1     
  Branches     2549     2550       +1     
==========================================
+ Hits         5633     5635       +2     
+ Misses       2164     2163       -1     
  Partials      485      485              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MILLERMARRU MILLERMARRU left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traced this through and it holds up. Confirmed the finally block already uses currentExecuteCounter === executeCounter as the staleness guard, so extending the same check to .then/.catch is consistent with the existing convention rather than introducing a new one.

I pulled the counter logic out into a standalone script to stress a couple of orderings that aren't obvious from reading alone (stale resolves after fresh, stale rejects after fresh, and both settling in the same microtask batch). All three land on the fresh result with no leakage from the stale one:

Case 1 (stale resolves after fresh): { data: 'data-fresh', onSuccessCalls: [ 'fresh' ] }
Case 2 (stale rejects after fresh): { data: 'data-fresh', errorVal: null, onErrorCalls: [ 'stale' ] }
Case 3 (same-tick race): { data: 'data-fresh0', onSuccessCalls: [ 'fresh0' ] }

Worth calling out since it's easy to second-guess: leaving onError unguarded (case 2 above, onErrorCalls still contains 'stale') is correct, not an oversight. The existing should be loading on re-execute test asserts onError fires twice for two superseded default-abortPrevious calls, so guarding it the same way as data/onSuccess would break that test. Good that the PR body calls this out explicitly rather than leaving it to be rediscovered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useAxios: stale request can overwrite fresher data / fire onSuccess and onError after being superseded

2 participants