Skip to content

[Discussion] 2.0 'replace' option deprecation #2777

@rpkilby

Description

@rpkilby

I noticed 'replace' has been deprecated. Definitely agree that components should have only one root element, however we have other reasons for using replace.

Behavior questions:

  • What is the behavior moving forward? Currently the default value is true. Will this assumption be baked in?

  • How will this interact with the restricted elements in the dom? eg, those outlined in template parsing. Specifically, given this component template:

    <!-- my-component -->
    <div class="foo"><slot></slot></div>

    And this parent template:

    <table>
      <tr><th class="bar" is="my-component">stuff</th></tr>
    </table>

    What happens to the th element? Wouldn't replacing it with the div lead to invalid html? We use replace false to get around this, resulting in:

    <table>
      <tr><th class="bar" is="my-component"><div class="foo">stuff</div></th></tr>
    </table>

Our usage:

  • From a preference standpoint, I'd like to point you to this comment here 😉. It's definitely a stylistic preference and could live without. I also find it easier to grep the dom for my-component vs some div.

  • More important to us, replace is necessary for our data table mixin. We can easily insert sorting behavior to any column by just adding is="sort-controls" and a sort key.

    <!-- sort-controls component -->
    <div class="sort-controls no-wrap" v-on:click="pushSort(sortKey)">
        <slot></slot>
        <!-- Other details -->
        ...
    </div>
    
    <!-- example usage -->
    <table class="table table-bordered table-striped table-hover">
        <tr>
            <th class="col-xs-2">Link</th>
            <th class="col-xs-5" is="sort-controls" key="name">Company</th>
            <th class="col-xs-5" is="sort-controls" key="employeeCount">Employees</th>
        </tr>
    
        <tr v-for="company in companies">
            ...
        </tr>
    </table>

    It's a terse solution that breaks when replace: true, as the parent th is lost.

Regardless of our specific usage, how do you extend restricted elements when replace: true?

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