{"record":{"id":"fd0265c8ef570a45","repo":"Meituan-Dianping/mpvue","slug":"v-once-can-only-be-used-inside-v-for-that-is-keyed-fd0265","errorCode":null,"errorMessage":"v-once can only be used inside v-for that is keyed. ","messagePattern":"v-once can only be used inside v-for that is keyed\\. ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/codegen/index.js","lineNumber":111,"sourceCode":"}\n\n// v-once\nfunction genOnce (el: ASTElement, state: CodegenState): string {\n  el.onceProcessed = true\n  if (el.if && !el.ifProcessed) {\n    return genIf(el, state)\n  } else if (el.staticInFor) {\n    let key = ''\n    let parent = el.parent\n    while (parent) {\n      if (parent.for) {\n        key = parent.key\n        break\n      }\n      parent = parent.parent\n    }\n    if (!key) {\n      process.env.NODE_ENV !== 'production' && state.warn(\n        `v-once can only be used inside v-for that is keyed. `\n      )\n      return genElement(el, state)\n    }\n    return `_o(${genElement(el, state)},${state.onceId++}${key ? `,${key}` : ``})`\n  } else {\n    return genStatic(el, state)\n  }\n}\n\nexport function genIf (\n  el: any,\n  state: CodegenState,\n  altGen?: Function,\n  altEmpty?: string\n): string {\n  el.ifProcessed = true // avoid recursion\n  return genIfConditions(el.ifConditions.slice(), state, altGen, altEmpty)","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/Meituan-Dianping/mpvue/blob/6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b/src/compiler/codegen/index.js#L93-L129","documentation":"Dev-only codegen warning from genOnce: v-once was applied to a node inside a v-for that has no key on any ancestor v-for. The _o() once-cache marker needs the enclosing for's key to key cached static nodes; without it the compiler warns and emits the node as a normal (non-once) element.","triggerScenarios":"Thrown at src/compiler/codegen/index.js:111 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add a unique :key to the v-for containing the v-once element","Remove v-once from that node if per-item re-render is intended"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6c5d78ee04f58c6d782c456dfcf0fe63c0b7f89b","analyzedAt":"2026-09-02T05:17:40.946Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}