Skip to content

Commit c7f80ee

Browse files
committed
fix: avoid pushing main container into _teleportTargets when disabled
1 parent 238619c commit c7f80ee

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

packages/runtime-core/src/components/Teleport.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,6 @@ export const TeleportImpl = {
119119
// Teleport *always* has Array children. This is enforced in both the
120120
// compiler and vnode children normalization.
121121
if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
122-
if (parentComponent && parentComponent.isCE) {
123-
const _teleportTargets = parentComponent.ce!._teleportTargets
124-
if (!_teleportTargets) {
125-
parentComponent.ce!._teleportTargets = [container]
126-
} else {
127-
_teleportTargets.push(container)
128-
}
129-
}
130122
mountChildren(
131123
children as VNodeArrayChildren,
132124
container,
@@ -150,6 +142,15 @@ export const TeleportImpl = {
150142
} else if (namespace !== 'mathml' && isTargetMathML(target)) {
151143
namespace = 'mathml'
152144
}
145+
146+
// track CE teleport targets
147+
if (parentComponent && parentComponent.isCE) {
148+
;(
149+
parentComponent.ce!._teleportTargets ||
150+
(parentComponent.ce!._teleportTargets = [])
151+
).push(target)
152+
}
153+
153154
if (!disabled) {
154155
mount(target, targetAnchor)
155156
updateCssVars(n2, false)

packages/runtime-dom/__tests__/customElement.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,45 @@ describe('defineCustomElement', () => {
13191319
app.unmount()
13201320
})
13211321

1322+
test('render two Teleports w/ shadowRoot false (with disabled)', async () => {
1323+
const target1 = document.createElement('div')
1324+
const target2 = document.createElement('span')
1325+
const Child = defineCustomElement(
1326+
{
1327+
render() {
1328+
return [
1329+
// with disabled: true
1330+
h(Teleport, { to: target1, disabled: true }, [
1331+
renderSlot(this.$slots, 'header'),
1332+
]),
1333+
h(Teleport, { to: target2 }, [renderSlot(this.$slots, 'body')]),
1334+
]
1335+
},
1336+
},
1337+
{ shadowRoot: false },
1338+
)
1339+
customElements.define('my-el-two-teleport-child-0', Child)
1340+
1341+
const App = {
1342+
render() {
1343+
return h('my-el-two-teleport-child-0', null, {
1344+
default: () => [
1345+
h('div', { slot: 'header' }, 'header'),
1346+
h('span', { slot: 'body' }, 'body'),
1347+
],
1348+
})
1349+
},
1350+
}
1351+
const app = createApp(App)
1352+
app.mount(container)
1353+
await nextTick()
1354+
expect(target1.outerHTML).toBe(`<div></div>`)
1355+
expect(target2.outerHTML).toBe(
1356+
`<span><span slot="body">body</span></span>`,
1357+
)
1358+
app.unmount()
1359+
})
1360+
13221361
test('toggle nested custom element with shadowRoot: false', async () => {
13231362
customElements.define(
13241363
'my-el-child-shadow-false',

0 commit comments

Comments
 (0)