Skip to content

Commit

Permalink
Change Morph plugin to use createElement(template).content rather tha…
Browse files Browse the repository at this point in the history
…n createRange().createContextualFragment() as the later does not support table <tr> or <td> tags (#3020)
  • Loading branch information
samwillis authored Jul 11, 2022
1 parent 069aa2b commit a317121
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/morph/src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export function dom(el) {
}

export function createElement(html) {
return document.createRange().createContextualFragment(html).firstElementChild
const template = document.createElement('template')
template.innerHTML = html
return template.content.firstElementChild
}

export function textOrComment(el) {
Expand Down
13 changes: 13 additions & 0 deletions tests/cypress/integration/plugins/morph.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,16 @@ test('can morph multiple nodes',
get('p:nth-of-type(2)').should(haveText('2'))
},
)

test('can morph table tr',
[html`
<table>
<tr><td>1</td></tr>
</table>
`],
({ get }, reload, window, document) => {
let tr = document.querySelector('tr')
window.Alpine.morph(tr, '<tr><td>2</td></tr>')
get('td').should(haveText('2'))
},
)

0 comments on commit a317121

Please sign in to comment.