From: Yang Mingshan Date: Tue, 10 Sep 2024 07:51:10 +0000 (+0800) Subject: refactor(scheduler): simplify checkRecursiveUpdates (#11856) X-Git-Tag: v3.5.4~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48613bb928fb9dbaec7824445f2647a0545e322b;p=thirdparty%2Fvuejs%2Fcore.git refactor(scheduler): simplify checkRecursiveUpdates (#11856) --- diff --git a/packages/runtime-core/src/scheduler.ts b/packages/runtime-core/src/scheduler.ts index 2250af4111..1eac06e5bf 100644 --- a/packages/runtime-core/src/scheduler.ts +++ b/packages/runtime-core/src/scheduler.ts @@ -267,27 +267,23 @@ function flushJobs(seen?: CountMap) { } function checkRecursiveUpdates(seen: CountMap, fn: SchedulerJob) { - if (!seen.has(fn)) { - seen.set(fn, 1) - } else { - const count = seen.get(fn)! - if (count > RECURSION_LIMIT) { - const instance = fn.i - const componentName = instance && getComponentName(instance.type) - handleError( - `Maximum recursive updates exceeded${ - componentName ? ` in component <${componentName}>` : `` - }. ` + - `This means you have a reactive effect that is mutating its own ` + - `dependencies and thus recursively triggering itself. Possible sources ` + - `include component template, render function, updated hook or ` + - `watcher source function.`, - null, - ErrorCodes.APP_ERROR_HANDLER, - ) - return true - } else { - seen.set(fn, count + 1) - } + const count = seen.get(fn) || 0 + if (count > RECURSION_LIMIT) { + const instance = fn.i + const componentName = instance && getComponentName(instance.type) + handleError( + `Maximum recursive updates exceeded${ + componentName ? ` in component <${componentName}>` : `` + }. ` + + `This means you have a reactive effect that is mutating its own ` + + `dependencies and thus recursively triggering itself. Possible sources ` + + `include component template, render function, updated hook or ` + + `watcher source function.`, + null, + ErrorCodes.APP_ERROR_HANDLER, + ) + return true } + seen.set(fn, count + 1) + return false }