Skip to content

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

Closed
@Fuzzyma

Description

@Fuzzyma

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞 bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions