From: Evan You Date: Thu, 8 Apr 2021 15:09:40 +0000 (-0400) Subject: wip: tweak warning dedupe logic X-Git-Tag: v3.1.0-beta.1~59^2~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7957a7440d1567595e6d9b10eae0eb4a9d9242a;p=thirdparty%2Fvuejs%2Fcore.git wip: tweak warning dedupe logic --- diff --git a/packages/runtime-core/src/compat/deprecations.ts b/packages/runtime-core/src/compat/deprecations.ts index e416a7f4b4..b34cd71608 100644 --- a/packages/runtime-core/src/compat/deprecations.ts +++ b/packages/runtime-core/src/compat/deprecations.ts @@ -1,4 +1,8 @@ -import { isRuntimeOnly } from '../component' +import { + formatComponentName, + getCurrentInstance, + isRuntimeOnly +} from '../component' import { warn } from '../warning' import { getCompatConfig } from './compatConfig' @@ -301,7 +305,8 @@ const deprecationData: Record = { } } -const hasWarned: Record = {} +const instanceWarned: Record = Object.create(null) +const warnCount: Record = Object.create(null) /** * @internal @@ -321,13 +326,28 @@ export function warnDeprecation(key: DeprecationTypes, ...args: any[]) { return } - // avoid spamming the same message const dupKey = key + args.join('') - if (hasWarned[dupKey]) { + const instance = getCurrentInstance() + const compName = instance && formatComponentName(instance, instance.type) + + // skip if the same warning is emitted for the same component type + if (compName !== `Anonymous`) { + const componentDupKey = dupKey + compName + if (componentDupKey in instanceWarned) { + return + } + instanceWarned[componentDupKey] = true + } + + // same warning, but different component. skip the long message and just + // log the key and count. + if (dupKey in warnCount) { + warn(`(deprecation ${key}) (${++warnCount[dupKey] + 1})`) return } - hasWarned[dupKey] = true + warnCount[dupKey] = 0 + const { message, link } = deprecationData[key] warn( `(deprecation ${key}) ${