Skip to content

Haunted not clearing innerHTML before first render #444

Open
@micahjon

Description

@micahjon

I'm working on upgrading BeFunky to the latest version of Lit and Haunted.

We currently don't use shadow DOM for components, and I noticed that when useShadowDOM: false is set, Haunted doesn't clear the initial content in the custom element before rendering. Initial content is really helpful for progressive enhancement, avoiding layout shift when the component JS loads and renders, e.g.

<custom-element>
  <span class="loading-placeholder">Loading...<span>
</custom-element>

This was fine in Lit 1.*, but in Lit 2.*, the render() function doesn't clear the container's contents.

From the Lit upgrade guide: https://lit.dev/docs/releases/upgrade/#lit-html

render() no longer clears the container it's rendered to on first render. It now appends to the container by default.

I'm guessing we'll need to set component.innerHTML = '' before the first render manually when useShadowDOM: false is set.


Bug replicated in Codepen: https://codepen.io/pranksinatra/pen/XWqrpBj

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions