Skip to content

Commit 464cfe6

Browse files
committed
fix: ensure useAsyncDataWrapper returns a Promise for non-Promise results
1 parent b76d792 commit 464cfe6

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/index.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ export function useAsyncDataWrapper<T extends Record<string, any>>(
101101
// Call useAsyncData with the generated key and function
102102
const asyncDataResult = useAsyncData(
103103
dataKeyRef.value,
104-
() => originalFunction(...unref(argsRef)),
104+
() => {
105+
const result = originalFunction(...unref(argsRef));
106+
// Ensure we return a Promise
107+
return result instanceof Promise ? result : Promise.resolve(result);
108+
},
105109
{
106110
// Re-execute when arguments change
107111
watch: [argsRef],
@@ -113,10 +117,18 @@ export function useAsyncDataWrapper<T extends Record<string, any>>(
113117
return asyncDataResult;
114118
} else {
115119
// For functions without arguments
116-
const asyncDataResult = useAsyncData(key, () => originalFunction(), {
117-
// Spread additional options
118-
...options,
119-
});
120+
const asyncDataResult = useAsyncData(
121+
key,
122+
() => {
123+
const result = originalFunction();
124+
// Ensure we return a Promise
125+
return result instanceof Promise ? result : Promise.resolve(result);
126+
},
127+
{
128+
// Spread additional options
129+
...options,
130+
},
131+
);
120132

121133
return asyncDataResult;
122134
}

0 commit comments

Comments
 (0)