-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
Description
Describe the bug
In the source code, state.value is returned every time after execute() is executed. However, if execute() is called multiple consecutive times, the .then() of the non-last calls should obtain the resolved data of the current execution.
Here's a concrete bug example:
// Reactive object to store results
const dicts = reactive({})
// Mock async function: returns different data with different delays based on code
const getDict = async (code) => {
if (code === 1) {
await promiseTimeout(100) // Fastest: resolves after 100ms
return { value: 'a', label: 'A' }
} else if (code === 2) {
await promiseTimeout(2000) // Slowest: resolves after 2000ms
return { value: 'b', label: 'B' }
} else {
await promiseTimeout(1000) // Medium: resolves after 1000ms
return { value: 'c', label: 'C' }
}
}
const { isLoading, executeImmediate } = useAsyncState(getDict, undefined,{ immediate: false })
// 1st execution: should resolve to { value: 'a', ... }
executeImmediate(1).then((v) => {
// ACTUAL: v is undefined (throws error when accessing v.value)
// EXPECTED: v should be { value: 'a', label: 'A' }
dicts[v.value] = v
})
// 2nd execution: should resolve to { value: 'b', ... }
executeImmediate(2).then((v) => {
// ACTUAL: v is { value: 'c', label: 'C' } (overwritten by 3rd execution)
// EXPECTED: v should be { value: 'b', label: 'B' }
dicts[v.value] = v
})
// 3rd execution: should resolve to { value: 'c', ... }
executeImmediate(3).then((v) => {
// ACTUAL: v is { value: 'c', label: 'C' } (only this one works)
// EXPECTED: v should be { value: 'c', label: 'C' }
dicts[v.value] = v
})Reproduction
System Info
System:
OS: Linux 6.14 Ubuntu 25.04 25.04 (Plucky Puffin)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
Memory: 4.90 GB / 14.78 GB
Container: Yes
Shell: 5.2.37 - /bin/bash
Binaries:
Node: 22.17.1 - /run/user/1000/fnm_multishells/317555_1761111904305/bin/node
npm: 10.9.2 - /run/user/1000/fnm_multishells/317555_1761111904305/bin/npm
Browsers:
Firefox: 144.0
Firefox Developer Edition: 144.0
npmPackages:
@vueuse/core: ^14.0.0 => 14.0.0
vue: ^3.5.22 => 3.5.22Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a VueUse issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.