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

Compiled template classes preserve whitespace #12113

Closed
royeden opened this issue Jun 3, 2021 · 4 comments · Fixed by #12195
Closed

Compiled template classes preserve whitespace #12113

royeden opened this issue Jun 3, 2021 · 4 comments · Fixed by #12195

Comments

@royeden
Copy link
Contributor

royeden commented Jun 3, 2021

Version

2.6.13

Reproduction link

https://codesandbox.io/s/dazzling-cache-q8y8o?file=/src/App.vue

Steps to reproduce

Add whitespace between classes, for example with the latest changes in prettier sorting classes into individual newlines, an they'll end up with whitespace on production builds.

Example:

Template.vue:

<template>
  <div
    class="
      flex
      items-center
      w-full
      px-5
      py-3
      text-sm
      transition-colors
      duration-300
      ease-in-out
      focus:outline-none
      text-opacity-80
    "
  >
    <slot></slot>
  </div>
</template>

<script>
export default {}
</script>

Will be compiled to this

("div", { staticClass:"\n    flex\n    items-center\n    w-full\n    px-5\n    py-3\n    text-sm\n    transition-colors\n    duration-300\n    ease-in-out\n    focus:outline-none\n    text-opacity-80\n  "}, /* rest of the code */)

This happens regardless of whitespace preservation options in the compiler

What is expected?

Expected class names to be trimmed of whitespace during production builds.

What is actually happening?

Whitespace isn't trimmed in class names after compilation of templates.

@posva
Copy link
Member

posva commented Jun 8, 2021

Note this would require a new option since it's different from whitespace as it's inside of an attribute value and spaces could be important for attributes other than class

Edit: or as mentioned in vuejs/core#4251, it could automatically apply to class and style

@18476757294
Copy link

不懂

royeden added a commit to royeden/vue that referenced this issue Jul 25, 2021
Template static classes used to preserve whitespace after compilation, resulting in builds that had
bigger file outputs with whitespace in component's staticClass attributes

fix vuejs#12113
@greg-owl
Copy link

Is this a feature request or a bug? Updating from Vue & the template compiler 2.5.16 to 2.6.14 has caused us a lot of issues with the vue/recommended lint setting... the removed white space has hosed a lot of views. Granted, we inherited some issues in our code base, but how is this not a breaking change?

royeden added a commit to royeden/vue that referenced this issue Aug 24, 2021
royeden added a commit to royeden/vue that referenced this issue Aug 24, 2021
… purged in static classes

There's no need to escape newlines in static classes, as they're now replaced with a single
whitespace character

fix vuejs#12113
royeden added a commit to royeden/vue that referenced this issue Aug 24, 2021
@royeden
Copy link
Contributor Author

royeden commented Aug 24, 2021

I think I've fixed this issue/implemented this feature here.
I'm also looking into a fix for this in Vue 3 😄

posva added a commit that referenced this issue Sep 8, 2021
* feat(compiler): template staticClass no longer preserves whitespace

Template static classes used to preserve whitespace after compilation, resulting in builds that had
bigger file outputs with whitespace in component's staticClass attributes

fix #12113

* refactor(refactor(web-compiler): removed ignore in regex): Removed ignore flag in regex

fix #12113

* test(ssr-string.spec.js): Removed newline character, as whitespace is purged in static classes

There's no need to escape newlines in static classes, as they're now replaced with a single
whitespace character

fix #12113

* test(directives/class.spec.js): Added whitespace to test

fix #12113

* Apply suggestions from code review

Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants