Meituan-Dianping/mpvue · error

Avoid mutating an injected value directly since the changes

Error message

Avoid mutating an injected value directly since the changes will be overwritten whenever the provided component re-renders. injection being mutated: "${key}"

What it means

Fires from a reactive getter callback installed by defineReactive on injected keys during initInjections. Each inject binding on the component instance is made reactive specifically so that any assignment to it (e.g. this.myInjected = x) triggers this warning: injected values are read-only conduits from an ancestor's provide, and because the injection is re-resolved from the provider whenever it re-renders, local mutations are silently discarded.

Source

Thrown at src/core/instance/inject.js:25

export function initProvide (vm: Component) {
  const provide = vm.$options.provide
  if (provide) {
    vm._provided = typeof provide === 'function'
      ? provide.call(vm)
      : provide
  }
}

export function initInjections (vm: Component) {
  const result = resolveInject(vm.$options.inject, vm)
  if (result) {
    observerState.shouldConvert = false
    Object.keys(result).forEach(key => {
      /* istanbul ignore else */
      if (process.env.NODE_ENV !== 'production') {
        defineReactive(vm, key, result[key], () => {
          warn(
            `Avoid mutating an injected value directly since the changes will be ` +
            `overwritten whenever the provided component re-renders. ` +
            `injection being mutated: "${key}"`,
            vm
          )
        })
      } else {
        defineReactive(vm, key, result[key])
      }
    })
    observerState.shouldConvert = true
  }
}

export function resolveInject (inject: any, vm: Component): ?Object {
  if (inject) {
    // inject is :any because flow is not smart enough to figure out cached
    const result = Object.create(null)

View on GitHub (pinned to 6c5d78ee04)

Solutions

  1. Move the mutated value into local data initialized from the injection: data() { return { local: this.myInjected } }
  2. Declare a computed property that wraps the injected value and derives changed state from it
  3. If two-way flow is needed, inject a mutable object or a setter method from the provider and mutate that object's properties instead of the binding itself
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at src/core/instance/inject.js:25 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Meituan-Dianping/mpvue@6c5d78ee04 (2026-09-02). Data as JSON: /api/errors/b90c6114a87188d4. Report an issue: GitHub.