Skip to content

compiler-core: :key expression not prefixed when element has v-memo without v-for (ReferenceError at runtime) #14920

@adnesvetaev

Description

@adnesvetaev

Version

3.5.35

Reproduction link

play.vuejs.org/

Steps to reproduce

Open the playground link; it throws on load.
The trigger is v-memo + dynamic :key on a plain element without v-for, where the key references a prop

What is expected?

:key expression is prefixed like any other (__props.updateKey / _ctx.updateKey), as in ≤3.5.12

What is actually happening?

transformExpression skips the :key expression whenever the element has v-memo (the !(memo && arg.content === 'key') check added in 99009ee / PR #12014), assuming transformFor processed it eagerly — but that only happens when v-for is also present.

Plain elements fall through → unprefixed key → ReferenceError at runtime


This happened after vue version update.

We hit this in a component library's scroll-container component. It renders custom scrollbars, so its reactive scroll state changes on every scroll frame; to keep large slotted content (e.g. a table body with thousands of cells) from re-rendering on each frame, the content wrapper uses v-memo="[updateKey]" with :key="updateKey" on the same element — "freeze this subtree, and when the parent bumps updateKey (data reload, layout change), rebuild it from scratch instead of diffing."

This compiled and ran correctly up to compiler 3.5.12; from 3.5.13 the generated render function references the key as a bare identifier and every page using the component throws ReferenceError on first render.

Current workaround: v-bind="{ key: updateKey }" instead of :key="updateKey", which bypasses the skipped code path and produces a correctly prefixed expression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    🔨 p3-minor-bugPriority 3: this fixes a bug, but is an edge case that only affects very specific usage.has workaroundA workaround has been found to avoid the problemscope: compiler

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions