Skip to content

[Static optimization] Use template.innerHTML instead of createContextualFragment #2890

@nolanlawson

Description

@nolanlawson

As discussed here (#2781 (comment)), we are currently using createContextualFragment only for IE11 support.

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

We should switch to this:

const template = document.createElement('template')
export function createFragment(html: string): Node | null {
    template.innerHTML = html
    return template.content.firstChild
}

This will require disabling the static optimization in compat mode, though. This would allow us to also re-enable the optimization for nodes like <td> and <th>.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions