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

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

Closed
nolanlawson opened this issue Jun 16, 2022 · 3 comments · Fixed by #2888
Closed

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

nolanlawson opened this issue Jun 16, 2022 · 3 comments · Fixed by #2888
Labels

Comments

@nolanlawson
Copy link
Collaborator

nolanlawson commented Jun 16, 2022

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 });
    }
}
@nolanlawson
Copy link
Collaborator Author

WI: W-11308172

@caridy
Copy link
Contributor

caridy commented Jun 16, 2022

Yeah, more rules to limit what can be statically inserted. Luckily, that's well specified, let's just add more rules.

@nolanlawson
Copy link
Collaborator Author

Yeah we could potentially do some kind of workaround for static <td>s (e.g. wrapping them in another element before parsing), but I wonder if it's worth it. It might actually be a perf regression due to creating an extra element just to throw it away. Adding a rule is simpler.

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

Successfully merging a pull request may close this issue.

2 participants