Subscribe on changes!

refs in v-memo on looped template tag are missing _ctx in transpiled code

avatar
Jan 19th 2022

Version

3.2.27

Reproduction link

sfc.vuejs.org/

Steps to reproduce

Putting a v-memo on a template that has a for loop is discouraged by the linter but totally possible (and extremely useful in my case). However, this code:

<template>
  <template v-for="l of list" :key="l" v-memo="[someVal]">
    <div>
      {{ l }}
    </div>
  </template>
</template>

transpiles to this:

function render(_ctx, _cache, $props, $setup, $data, $options) {
  return (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, (l, __, ___, _cached) => {
    const _memo = ([someVal])
    if (_cached && _cached.key === l && _isMemoSame(_cached, _memo)) return _cached
    const _item = (_openBlock(), _createElementBlock("div", { key: l }, _toDisplayString(l), 1 /* TEXT */))
    _item.memo = _memo
    return _item
  }, _cache, 0), 128 /* KEYED_FRAGMENT */))
}

As you can see, the value in memo is missing the _ctx

What is expected?

A _ctx for all memo values

What is actually happening?

no ctx


Funny enough a workaround for this is to manually put a _ctx in front of the values in the template. However, this only works as long as the internals of the template transpiler stay the same