From 888dbf2f469fab5bc113b09bb833f59f9521ff0a Mon Sep 17 00:00:00 2001 From: vbin Date: Tue, 11 Nov 2025 15:39:11 +0800 Subject: [PATCH] fix: prevent Maximum call stack size exceeded in asyncSerialArray --- src/util.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/util.ts b/src/util.ts index 372d30c..b0794cc 100644 --- a/src/util.ts +++ b/src/util.ts @@ -15,7 +15,7 @@ const formatRegExp = /%[sdj%]/g; declare var ASYNC_VALIDATOR_NO_WARNING; -export let warning: (type: string, errors: SyncErrorType[]) => void = () => {}; +export let warning: (type: string, errors: SyncErrorType[]) => void = () => { }; // don't print warning message when in production env or node runtime if ( @@ -155,7 +155,11 @@ function asyncSerialArray( const original = index; index = index + 1; if (original < arrLength) { - func(arr[original], next); + func(arr[original], function (errors) { + queueMicrotask(() => { + next(errors); + }) + }); } else { callback([]); } @@ -229,8 +233,8 @@ export function asyncMap( callback(results); return results.length ? reject( - new AsyncValidationError(results, convertFieldsError(results)), - ) + new AsyncValidationError(results, convertFieldsError(results)), + ) : resolve(source); } };