Skip to content

Stringify attributes not combining the class definitions from the parent passthrough and the child #136

@TheJaredWilcurt

Description

@TheJaredWilcurt
<template>
  <TheParent>
    <ThirdPartyChild :class="'mx-2'">
      Text
    </ThirdPartyChild>
  </TheParent>
</template>
<template>
  <div>
    <component
      :is="isLink ? 'a' : 'button'"
      class="my-button"
      v-bind="$attrs"
    >
      <slot></slot>
    </component>
  </div>
</template>
// inherit attributes is false for this component, they are passed to the v-bind

wrapper.html() gives

<div class="the-parent">
  <button class="mx-2 my-button">
    Text
  </button>
</div>

However, when passed through V3SS it gives

<div class="the-parent">
  <button class="mx-2">
    Text
  </button>
</div>

Because of stringifyAttributes. I think the solution for this would be to loop over more of the virtual DOM to find both the V-DOM node that has the mx-2 and the one with the my-button? Then like, find a way to combine those? I'm not sure. This may be too much of an edge case to jump through all those hoops. For now I'm just going to document it here and add class to the default list of attributesNotToStringify. Since I can't really think of a good case where you'd care to see the object version over the final rendered version (class="{ 'p1': true }" vs class="p1").

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions