Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directives not working with SVG #5289

Closed
vandelpavel opened this issue Jan 19, 2022 · 2 comments · Fixed by #5919
Closed

Directives not working with SVG #5289

vandelpavel opened this issue Jan 19, 2022 · 2 comments · Fixed by #5919
Labels
🐞 bug Something isn't working scope: compiler

Comments

@vandelpavel
Copy link

Version

3.2.27

Reproduction link

jsfiddle.net/rvocfqwn/22/

Steps to reproduce

You must use an svg image and use a custom directive like in the fiddle. You can see that if the directive is on another element it works while on svg's will return an error.

What is expected?

Should works fine and log the element

What is actually happening?

Returns an error

@lidlanca
Copy link
Contributor

hoisting issue

<template>
  <b>{{msg}}</b>
  <svg  v-x>
    <path d="M2,3H5.5L12"/>
  </svg>
</template>

withDirectives called outside render function, and _directive_x is unscoped

const _hoisted_1 = _withDirectives(/*#__PURE__*/_createElementVNode("svg", null, [
  /*#__PURE__*/_createElementVNode("path", { d: "M2,3H5.5L12" })
], -1 /* HOISTED */), [
  [_directive_x]
])

render function

return (_ctx, _cache) => {
  const _directive_x = _resolveDirective("x")

  return (_openBlock(), _createElementBlock(_Fragment, null, [
    _createElementVNode("b", null, _toDisplayString(msg.value), 1 /* TEXT */),
    _hoisted_1
  ], 64 /* STABLE_FRAGMENT */))
}
}

@edison1105 edison1105 added 🐞 bug Something isn't working scope: compiler labels Jan 20, 2022
@edison1105
Copy link
Member

edison1105 commented Jan 21, 2022

caused by:

  • force block for custom dirs
  • svg and foreignObject also force block
  • svg + custom dirs also force block, but here we skip the logic
    if (
    codegenNode.isBlock &&
    node.tag !== 'svg' &&
    node.tag !== 'foreignObject'
    ) {
    return ConstantTypes.NOT_CONSTANT
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐞 bug Something isn't working scope: compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants