Skip to content

Static fragments of <td></td> result in runtime error #2887

@nolanlawson

Description

@nolanlawson

Description

I noticed that the static optimization (#2781) broke the js-framework-benchmark. It throws an error when trying to append elements.

The problem is that the compiled template ends up with this code:

const $fragment2 = parseFragment`<td class="col-md-6${0}"${2}></td>`;

And eventually it tries to parse this html into a fragment using this function:

function createFragment(html: string): Node | null {
return document.createRange().createContextualFragment(html).firstChild;
}

But since the <td> is standalone, this function returns null:

Screen Shot 2022-06-16 at 9 16 24 AM

Minimal repro:

<template>
    <button onclick={add}>Create row</button>
    <table>
        <tbody>
            <template for:each={rows} for:item="row">
                <tr key={row.id}>
                    <td></td>
                </tr>
            </template>
        </tbody>
    </table>
</template>
import { LightningElement, track } from 'lwc';

export default class extends LightningElement {
    @track rows = [];

    add() {
        this.rows.push({ id: 1 });
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions