marcoroth / turbo-morph

Morph action for Turbo Streams
MIT License
96 stars 1 forks source link

Fix morph() to morph instead of replace #1

Closed ghost closed 2 years ago

ghost commented 2 years ago

What?

morph() replaces instead of morphs.

Why?

Due to templateContent() returning a DocumentFragment and morphdom not working right with a DocumentFragment. It replaces instead of diffing and morphing like it should.

How?

Pass in a ternary for the new element that if childrenOnly is true passes this.templateContent, else passes this.templateElement.innerHTML. This keeps childrenOnly working as it has no problem with a DocumentFragment but does not work with this.templateElement.innerHTML. And for regular morphs they diff and morph correctly with this.templateElement.innerHTML where templateElement() gets the the template element and innerHTML for the html.

This had come up in the CableReady repo: #58 #67

marcoroth commented 2 years ago

Fixed via #2, thanks @connorwbey!