{"record":{"id":"9d4d52a64df42229","repo":"Meituan-Dianping/mpvue","slug":"avoid-mutating-an-injected-value-directly-since-th","errorCode":null,"errorMessage":"Avoid mutating an injected value directly since the changes will be overwritten whenever the provided component re-renders. injection being mutated: \"${key}\"","messagePattern":"Avoid mutating an injected value directly since the changes will be overwritten whenever the provided component re-renders\\. injection being mutated: \"(.+?)\"","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/weex-vue-framework/factory.js","lineNumber":3364,"sourceCode":"\nfunction initProvide (vm) {\n  var provide = vm.$options.provide;\n  if (provide) {\n    vm._provided = typeof provide === 'function'\n      ? provide.call(vm)\n      : provide;\n  }\n}\n\nfunction initInjections (vm) {\n  var result = resolveInject(vm.$options.inject, vm);\n  if (result) {\n    observerState.shouldConvert = false;\n    Object.keys(result).forEach(function (key) {\n      /* istanbul ignore else */\n      if (process.env.NODE_ENV !== 'production') {\n        defineReactive$$1(vm, key, result[key], function () {\n          warn(\n            \"Avoid mutating an injected value directly since the changes will be \" +\n            \"overwritten whenever the provided component re-renders. \" +\n            \"injection being mutated: \\\"\" + key + \"\\\"\",\n            vm\n          );\n        });\n      } else {\n        defineReactive$$1(vm, key, result[key]);\n      }\n    });\n    observerState.shouldConvert = true;\n  }\n}\n\nfunction resolveInject (inject, vm) {\n  if (inject) {\n    // inject is :any because flow is not smart enough to figure out cached\n    var result = Object.create(null);","sourceCodeStart":3346,"sourceCodeEnd":3382,"githubUrl":"https://github.com/Meituan-Dianping/mpvue/blob/6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b/packages/weex-vue-framework/factory.js#L3346-L3382","documentation":"When a component `inject`s a reactive value from an ancestor's `provide`, Vue makes the injected property reactive with a custom setter that warns on direct mutation. Because the provider re-renders and re-provides the value, any local mutation would be silently overwritten, so Vue forbids it.","triggerScenarios":"`this.injectedKey = newValue` (or `Vue.set`/assignment via the reactive setter) on a property declared in the `inject` option or returned from a functional `provide` whose value comes from `inject`, in a development build.","commonSituations":"Using inject/inject like a global store and writing to it from a child; form components mutating injected config; migration of code that previously used `$parent` access directly.","solutions":["Stop mutating the injected value; treat it as read-only coming from the provider.","Copy the injected value into local `data` if the child needs its own editable copy.","Move the shared state into a proper store (Vuex) or have children emit events / call methods on the provider to change it.","If you only need a non-reactive constant, provide a frozen/plain object so no reactive setter is installed."],"exampleFix":"// before\nthis.theme = 'dark'; // injected\n// after\ndata() { return { localTheme: this.theme } }","handlingStrategy":"type-guard","validationCode":"function canInject(key, vm) {\n  let s = vm.$parent;\n  while (s) { if (s._provided && key in s._provided) return true; s = s.$parent; }\n  return false;\n}","typeGuard":"function isInjectedReadonly(vm, key) {\n  const desc = Object.getOwnPropertyDescriptor(vm, key);\n  return !!desc && typeof desc.set === 'function';\n}","tryCatchPattern":null,"preventionTips":["Never write to injected values; snapshot into data if editing is needed.","Provide defaults via the inject option object syntax.","Use Vuex/composition for genuinely writable shared state."],"tags":["vue","inject","provide","reactivity","dev-warning"],"backgroundTag":"injected-value-mutation","analyzedSha":"6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b","analyzedAt":"2026-09-02T05:17:40.946Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}