Skip to content

Commit b0d82c8

Browse files
committed
chore: remove replace function
1 parent 7474479 commit b0d82c8

File tree

3 files changed

+5
-26
lines changed

3 files changed

+5
-26
lines changed

packages/runtime-core/src/hydration.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ export function createHydrationFunctions(
6262
parentNode,
6363
remove,
6464
insert,
65-
createComment,
66-
replace
65+
createComment
6766
}
6867
} = rendererInternals
6968

@@ -622,7 +621,10 @@ export function createHydrationFunctions(
622621
parentComponent: ComponentInternalInstance | null
623622
): Node => {
624623
// replace node
625-
replace(newNode, oldNode)
624+
const parentNode = oldNode.parentNode
625+
if (parentNode) {
626+
parentNode.replaceChild(newNode, oldNode)
627+
}
626628

627629
// update vnode
628630
let parent = parentComponent

packages/runtime-core/src/renderer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ export interface RendererOptions<
105105
): void
106106
insert(el: HostNode, parent: HostElement, anchor?: HostNode | null): void
107107
remove(el: HostNode): void
108-
replace(newChild: HostNode, oldChild: HostNode): void
109108
createElement(
110109
type: string,
111110
isSVG?: boolean,

packages/runtime-test/src/nodeOps.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -188,28 +188,6 @@ function remove(child: TestNode, logOp = true) {
188188
}
189189
}
190190

191-
function replace(newChild: TestNode, oldChild: TestNode, logOp = true) {
192-
const parent = oldChild.parentNode
193-
if (parent) {
194-
if (logOp) {
195-
logNodeOp({
196-
type: NodeOpTypes.REMOVE,
197-
targetNode: oldChild,
198-
parentNode: parent
199-
})
200-
}
201-
const i = parent.children.indexOf(oldChild)
202-
if (i > -1) {
203-
parent.children.splice(i, 1, newChild)
204-
} else {
205-
console.error('target: ', oldChild)
206-
console.error('parent: ', parent)
207-
throw Error('target is not a childNode of parent')
208-
}
209-
oldChild.parentNode = null
210-
}
211-
}
212-
213191
function setElementText(el: TestElement, text: string) {
214192
logNodeOp({
215193
type: NodeOpTypes.SET_ELEMENT_TEXT,

0 commit comments

Comments
 (0)