Skip to content

Commit 59425b0

Browse files
committed
chore: revert teleport changes
1 parent fa01278 commit 59425b0

File tree

1 file changed

+48
-49
lines changed

1 file changed

+48
-49
lines changed

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

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -139,60 +139,59 @@ export class TeleportFragment extends VaporFragment {
139139
insert((this.nodes = children), this.mountContainer!, this.mountAnchor!)
140140
}
141141

142-
private mount(parent: ParentNode, anchor: Node | null): void {
143-
if (this.$transition) {
144-
this.$transition = applyTransitionHooks(this.nodes, this.$transition)
142+
private handlePropsUpdate(): void {
143+
// not mounted yet
144+
if (!this.parent || isHydrating) return
145+
146+
const mount = (parent: ParentNode, anchor: Node | null) => {
147+
if (this.$transition) {
148+
applyTransitionHooks(this.nodes, this.$transition)
149+
}
150+
insert(
151+
this.nodes,
152+
(this.mountContainer = parent),
153+
(this.mountAnchor = anchor),
154+
)
145155
}
146156

147-
insert(
148-
this.nodes,
149-
(this.mountContainer = parent),
150-
(this.mountAnchor = anchor),
151-
)
152-
}
157+
const mountToTarget = () => {
158+
const target = (this.target = resolveTeleportTarget(
159+
this.resolvedProps!,
160+
querySelector,
161+
))
162+
if (target) {
163+
if (
164+
// initial mount into target
165+
!this.targetAnchor ||
166+
// target changed
167+
this.targetAnchor.parentNode !== target
168+
) {
169+
insert((this.targetStart = createTextNode('')), target)
170+
insert((this.targetAnchor = createTextNode('')), target)
171+
}
153172

154-
private mountToTarget = (): void => {
155-
const target = (this.target = resolveTeleportTarget(
156-
this.resolvedProps!,
157-
querySelector,
158-
))
159-
if (target) {
160-
if (
161-
// initial mount into target
162-
!this.targetAnchor ||
163-
// target changed
164-
this.targetAnchor.parentNode !== target
165-
) {
166-
insert((this.targetStart = createTextNode('')), target)
167-
insert((this.targetAnchor = createTextNode('')), target)
168-
}
173+
// track CE teleport targets
174+
if (this.parentComponent && this.parentComponent.isCE) {
175+
;(
176+
this.parentComponent.ce!._teleportTargets ||
177+
(this.parentComponent.ce!._teleportTargets = new Set())
178+
).add(target)
179+
}
169180

170-
// track CE teleport targets
171-
if (this.parentComponent && this.parentComponent.isCE) {
172-
;(
173-
this.parentComponent.ce!._teleportTargets ||
174-
(this.parentComponent.ce!._teleportTargets = new Set())
175-
).add(target)
181+
mount(target, this.targetAnchor!)
182+
updateCssVars(this)
183+
} else if (__DEV__) {
184+
warn(
185+
`Invalid Teleport target on ${this.targetAnchor ? 'update' : 'mount'}:`,
186+
target,
187+
`(${typeof target})`,
188+
)
176189
}
177-
178-
this.mount(target, this.targetAnchor!)
179-
updateCssVars(this)
180-
} else if (__DEV__) {
181-
warn(
182-
`Invalid Teleport target on ${this.targetAnchor ? 'update' : 'mount'}:`,
183-
target,
184-
`(${typeof target})`,
185-
)
186190
}
187-
}
188-
189-
private handlePropsUpdate(): void {
190-
// not mounted yet
191-
if (!this.parent || isHydrating) return
192191

193192
// mount into main container
194193
if (this.isDisabled) {
195-
this.mount(this.parent, this.anchor!)
194+
mount(this.parent, this.anchor!)
196195
updateCssVars(this)
197196
}
198197
// mount into target container
@@ -203,9 +202,9 @@ export class TeleportFragment extends VaporFragment {
203202
// typically due to an early insertion caused by setInsertionState.
204203
!this.parent!.isConnected
205204
) {
206-
queuePostFlushCb(this.mountToTarget)
205+
queuePostFlushCb(mountToTarget)
207206
} else {
208-
this.mountToTarget()
207+
mountToTarget()
209208
}
210209
}
211210
}
@@ -261,7 +260,7 @@ export class TeleportFragment extends VaporFragment {
261260
this.initChildren()
262261
}
263262

264-
private mountChildren(target: Node): void {
263+
private mount(target: Node): void {
265264
target.appendChild((this.targetStart = createTextNode('')))
266265
target.appendChild(
267266
(this.mountAnchor = this.targetAnchor = createTextNode('')),
@@ -320,7 +319,7 @@ export class TeleportFragment extends VaporFragment {
320319
// always be null, we need to manually add targetAnchor to ensure
321320
// Teleport it can properly unmount or move
322321
if (!this.targetAnchor) {
323-
this.mountChildren(target)
322+
this.mount(target)
324323
} else {
325324
this.initChildren()
326325
}

0 commit comments

Comments
 (0)