Subscribe on changes!

Compile function return comments (even if explicitly set "no comments" option)

avatar
Mar 8th 2021

Version

3.0.7

Reproduction link

https://jsfiddle.net/akgpf058/

Steps to reproduce

Vue.compile(`<h2>Todos:</h2><!-- COMMENT HERE -->`, {comments: false});

See result where comment nodes are in place (even with comments: false option):

(function anonymous(
) {
const _Vue = Vue
const { createVNode: _createVNode, createCommentVNode: _createCommentVNode } = _Vue

const _hoisted_1 = /*#__PURE__*/_createVNode("h2", null, "Todos:", -1 /* HOISTED */)

return function render(_ctx, _cache) {
  with (_ctx) {
    const { createVNode: _createVNode, createCommentVNode: _createCommentVNode, Fragment: _Fragment, openBlock: _openBlock, createBlock: _createBlock } = _Vue

    return (_openBlock(), _createBlock(_Fragment, null, [
      _hoisted_1,
      _createCommentVNode(" COMMENT HERE ")
    ], 2112 /* STABLE_FRAGMENT, DEV_ROOT_FRAGMENT */))
  }
}
})

What is expected?

Returned result without comment nodes being rendered.

What is actually happening?

Comment nodes are in place: _createCommentVNode(" COMMENT HERE ")


I would appreciate any feedback on how to precompile template without comment nodes, my understanding that Vue has option to remove comment nodes from template, but I can be misreading source code, let me know if there any other way to make Vue.compile trim comments (there are should be one, I guess?).

avatar
Jul 15th 2021

According to docs:

By default, Vue will remove HTML comments inside templates in production. Setting this option to true will force Vue to preserve comments even in production. Comments are always preserved during development.

This is intended behavior unless the comments are present in production.

Or is there any particular reason you want comments removed during development?

avatar
Jul 15th 2021

Yes, there is a reason. I'm running dev version of Vue because I want to see any issues while, you know, developing. But, result I need is complied template for, you know, production, so I got this issue when I can't have it without comments, which I would say frustrating.

From other point, I found work around by resetting global variable before compiling, which is working like a charm, and setting it back after.

чт, 15 лип. 2021, 22:53 користувач Evan You @.***> пише:

According to docs https://v3.vuejs.org/api/application-config.html#compileroptions-comments :

By default, Vue will remove HTML comments inside templates in production. Setting this option to true will force Vue to preserve comments even in production. Comments are always preserved during development.

This is intended behavior unless the comments are present in production.

Or is there any particular reason you want comments removed during development?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vuejs/vue-next/issues/3392#issuecomment-880971027, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGJKBZAISKHOARZ44LTPDGTTX44ERANCNFSM4Y2KR72Q .