From d051f6f2c1141bc8008c5bf1376d1fd00036f920 Mon Sep 17 00:00:00 2001 From: RAX7 Date: Tue, 2 May 2023 06:32:12 +0700 Subject: [PATCH] fix(useFetch): `combineCallbacks` does not merge options (#3015) --- packages/core/useFetch/index.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/core/useFetch/index.ts b/packages/core/useFetch/index.ts index f0e5e6cf3c4..4bb7addd306 100644 --- a/packages/core/useFetch/index.ts +++ b/packages/core/useFetch/index.ts @@ -230,18 +230,20 @@ function combineCallbacks(combination: Combination, ...callbacks: (((ct // use last callback return async (ctx: T) => { const callback = callbacks[callbacks.length - 1] - if (callback !== undefined) - await callback(ctx) + if (callback) + return { ...ctx, ...(await callback(ctx)) } + return ctx } } else { // chaining and combine result return async (ctx: T) => { - await callbacks.reduce((prevCallback, callback) => prevCallback.then(async () => { + for (const callback of callbacks) { if (callback) ctx = { ...ctx, ...(await callback(ctx)) } - }), Promise.resolve()) + } + return ctx } }