vuejs / core-vapor

Vue Vapor is a variant of Vue that offers rendering without the Virtual DOM.

Home Page:https://vapor-repl.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: v-once directive not working as expected with SFC Playground after code modifications

lulu0119 opened this issue · comments

commented

I've encountered an issue with the implementation of the v-once directive in vue-vapor, specifically in the SFC Playground. The problem arises when modifying the source code, even with trivial changes like adding spaces, leading to v-once not functioning as intended.

In vue core, nodes (including those marked with v-once) undergo further transformations during the compilation process, leading to seen.has(node) correctly returning false during subsequent checks. This allows the directive to be reapplied appropriately based on the updated node state.

vue-vapor does not introduce additional modifications such as codegenNode to these nodes post-processing. Thus, once a node is in seen, subsequent checks (seen.has(node)) will incorrectly identify it as unchanged, even if the source code has been edited.

Affected Code Snippet:

const seen = new WeakSet()

export const transformOnce: NodeTransform = (node, context) => {
  if (node.type === NodeTypes.ELEMENT && findDir(node, 'once', true)) {
    if (seen.has(node) || context.inVOnce /* || context.inSSR */) {
      return
    }
    seen.add(node)
    context.inVOnce = true
  }
}