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

HTML Comments in template root are breaking components functionality with compiler option whitespace: "preserve" #2019

Open
bartoszrudzinski opened this issue Nov 24, 2022 · 1 comment

Comments

@bartoszrudzinski
Copy link

bartoszrudzinski commented Nov 24, 2022

Version

17.0.1

Reproduction link

https://github.com/bartoszrudzinski/vue-loader-bug

Steps to reproduce

Copy repository, type npm install and npm run serve to check.
To "test" it remove comments from TestComponent and TestComponentWithTransition components and check behaviour.

What is actually happening?

When using compilerOptions: { whitespace: "preserve" } vue-loader option HTML comments are breaking functionality of components:

  • "class" attribute is not being passed from parent to child properly when there is a comment in the child template root
  • transition components using slots are not being rendered at all

Those are two found by me. There can be more related issues.

What is expected?

Comments are not breaking functionality of components.


With HTML comments in the code:
image
image

Without HTML comments in the code:
image

@vzotov
Copy link

vzotov commented Mar 3, 2023

I've got the same issue. Ended up adding comments: false to vue-loader compilerOptions

module: {
  rules: [
    {
      test: /\.vue$/,
      use: [
        {
          loader: 'vue-loader',
          options: {
            compilerOptions: {
              comments: false
            }
          }
        }
      ]
    }
  ]
}

But I'm not sure if it is a loader's issue I found this in the vue source code https://github.com/vuejs/core/blob/2a9e9a40963a852238adc4c61b86d0c48e7131fa/packages/runtime-core/src/componentRenderUtils.ts#L122

    // attr merging
    // in dev mode, comments are preserved, and it's possible for a template
    // to have comments along side the root element which makes it a fragment

seems they added a condition for development environment but if you have comments in production you will have this problem

at least vue-loader should warn developers that root level comments are not welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants