Skip to content

Commit 6902a05

Browse files
authored
Fix x-teleport by removing clone x-ignore (#4469)
* Fix x-teleport by removing clone x-ignore * Add test
1 parent 60cbc24 commit 6902a05

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/alpinejs/src/directives/x-teleport.js

-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ directive('teleport', (el, { modifiers, expression }, { cleanup }) => {
5151

5252
skipDuringClone(() => {
5353
initTree(clone)
54-
55-
clone._x_ignore = true
5654
})()
5755
})
5856

tests/cypress/integration/directives/x-teleport.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,26 @@ test('$id honors x-id outside teleport',
204204
get('#b h1').should(haveText('foo-1'))
205205
},
206206
)
207+
208+
test('conditionally added elements get initialised inside teleport',
209+
[html`
210+
<div x-data="{ show: false }" id="a">
211+
<button @click="show = true">Show Teleport Content</button>
212+
213+
<template x-teleport="#b">
214+
<div>
215+
<template x-if="show" >
216+
<p x-text="'Teleport content initialised'">Teleport content waiting</p>
217+
</template>
218+
</div>
219+
</template>
220+
</div>
221+
222+
<div id="b"></div>
223+
`],
224+
({ get }) => {
225+
get('#b p').should('not.exist')
226+
get('button').click()
227+
get('#b p').should('exist').and('have.text', 'Teleport content initialised')
228+
},
229+
)

0 commit comments

Comments
 (0)