Skip to content

Commit

Permalink
chore: include component info in recursive update warning
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 21, 2021
1 parent 1b8f14e commit 66b6b42
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,11 @@ function baseCreateRenderer(
}
}
}, __DEV__ ? createDevEffectOptions(instance) : prodEffectOptions)

if (__DEV__) {
// @ts-ignore
instance.update.ownerInstance = instance
}
}

const updateComponentPreRender = (
Expand Down
26 changes: 20 additions & 6 deletions packages/runtime-core/src/scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ErrorCodes, callWithErrorHandling } from './errorHandling'
import { isArray } from '@vue/shared'
import { ComponentPublicInstance } from './componentPublicInstance'
import { ComponentInternalInstance, getComponentName } from './component'
import { warn } from './warning'

export interface SchedulerJob {
(): void
Expand All @@ -22,6 +24,7 @@ export interface SchedulerJob {
* stabilizes (#1727).
*/
allowRecurse?: boolean
ownerInstance?: ComponentInternalInstance
}

export type SchedulerCb = Function & { id?: number }
Expand Down Expand Up @@ -164,8 +167,11 @@ export function flushPreFlushCbs(
preFlushIndex < activePreFlushCbs.length;
preFlushIndex++
) {
if (__DEV__) {
if (
__DEV__ &&
checkRecursiveUpdates(seen!, activePreFlushCbs[preFlushIndex])
) {
continue
}
activePreFlushCbs[preFlushIndex]()
}
Expand Down Expand Up @@ -200,8 +206,11 @@ export function flushPostFlushCbs(seen?: CountMap) {
postFlushIndex < activePostFlushCbs.length;
postFlushIndex++
) {
if (__DEV__) {
if (
__DEV__ &&
checkRecursiveUpdates(seen!, activePostFlushCbs[postFlushIndex])
) {
continue
}
activePostFlushCbs[postFlushIndex]()
}
Expand Down Expand Up @@ -235,8 +244,8 @@ function flushJobs(seen?: CountMap) {
for (flushIndex = 0; flushIndex < queue.length; flushIndex++) {
const job = queue[flushIndex]
if (job) {
if (__DEV__) {
checkRecursiveUpdates(seen!, job)
if (__DEV__ && checkRecursiveUpdates(seen!, job)) {
continue
}
callWithErrorHandling(job, null, ErrorCodes.SCHEDULER)
}
Expand All @@ -263,13 +272,18 @@ function checkRecursiveUpdates(seen: CountMap, fn: SchedulerJob | SchedulerCb) {
} else {
const count = seen.get(fn)!
if (count > RECURSION_LIMIT) {
throw new Error(
`Maximum recursive updates exceeded. ` +
const instance = (fn as SchedulerJob).ownerInstance
const componentName = instance && getComponentName(instance.type)
warn(
`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.`
)
return true
} else {
seen.set(fn, count + 1)
}
Expand Down

0 comments on commit 66b6b42

Please sign in to comment.