replaceChildren before rendering template #4491
Unanswered
BregtDeLange
asked this question in
Q&A
Replies: 1 comment
-
Calling
render() {
if (!this.hasUpdated) {
this.replaceChildren();
}
// regular render stuff
} Though ShadowDOM with |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a LitElement with a render() method. The component gets data from a backend, but this can take a while. I don't use the ShadowDOM. Currently, I render the custom element with a bunch of server side render children/elements to display skeleton loading. I want to replace the content of my custom element when the component received the data and the render() method can run.
I thought of using this.replaceChildren in my render() method right before returning the template.
But that fails.
Uncaught (in promise) Error: This `ChildPart` has no `parentNode` and therefore cannot accept a value. This likely means the element containing the part was manipulated in an unsupported way outside of Lit's control such that the part's marker nodes were ejected from DOM. For example, setting the element's `innerHTML` or `textContent` can do this.
I understand this is necessary. However, I searched the Issues here and found that someone recommended to use this.replaceChildren() (but that is in the context of lit-html and not an actual LitHtml inherited class.
#4178 (comment)
Not sure what I best do in this case? I just want to empty my server side generated HTML with the HTML from the render() method after I received the data.
Beta Was this translation helpful? Give feedback.
All reactions