Skip to content

Commit

Permalink
Fix x-teleport by removing clone x-ignore (#4469)
Browse files Browse the repository at this point in the history
* Fix x-teleport by removing clone x-ignore

* Add test
  • Loading branch information
joshhanley authored Dec 6, 2024
1 parent 60cbc24 commit 6902a05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 0 additions & 2 deletions packages/alpinejs/src/directives/x-teleport.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ directive('teleport', (el, { modifiers, expression }, { cleanup }) => {

skipDuringClone(() => {
initTree(clone)

clone._x_ignore = true
})()
})

Expand Down
23 changes: 23 additions & 0 deletions tests/cypress/integration/directives/x-teleport.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,26 @@ test('$id honors x-id outside teleport',
get('#b h1').should(haveText('foo-1'))
},
)

test('conditionally added elements get initialised inside teleport',
[html`
<div x-data="{ show: false }" id="a">
<button @click="show = true">Show Teleport Content</button>
<template x-teleport="#b">
<div>
<template x-if="show" >
<p x-text="'Teleport content initialised'">Teleport content waiting</p>
</template>
</div>
</template>
</div>
<div id="b"></div>
`],
({ get }) => {
get('#b p').should('not.exist')
get('button').click()
get('#b p').should('exist').and('have.text', 'Teleport content initialised')
},
)

0 comments on commit 6902a05

Please sign in to comment.