Skip to content

Commit b8ba13a

Browse files
pikaxyyx990803
authored andcommitted
reusing the same function
1 parent 3354646 commit b8ba13a

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

packages/runtime-core/src/hydration.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ export function createHydrationFunctions(
231231
// on component's rendered output to determine the end of the fragment
232232
// instead, we do a lookahead to find the end anchor node.
233233
nextNode = isFragmentStart
234-
? locateClosingAsyncAnchor(node)
234+
? locateClosingAnchor(node, '[', ']')
235235
: // #4293 #6152 if teleport start look ahead for teleport end.
236236
isComment(node) && node.data === 'teleport start'
237-
? locateClosingTeleportAnchor(node)
237+
? locateClosingAnchor(node, 'teleport start', 'teleport end')
238238
: nextSibling(node)
239239

240240
// #3787
@@ -527,7 +527,7 @@ export function createHydrationFunctions(
527527

528528
if (isFragment) {
529529
// remove excessive fragment nodes
530-
const end = locateClosingAsyncAnchor(node)
530+
const end = locateClosingAnchor(node, '[', ']')
531531
while (true) {
532532
const next = nextSibling(node)
533533
if (next && next !== end) {
@@ -555,31 +555,18 @@ export function createHydrationFunctions(
555555
return next
556556
}
557557

558-
const locateClosingAsyncAnchor = (node: Node | null): Node | null => {
559-
let match = 0
560-
while (node) {
561-
node = nextSibling(node)
562-
if (node && isComment(node)) {
563-
if (node.data === '[') match++
564-
if (node.data === ']') {
565-
if (match === 0) {
566-
return nextSibling(node)
567-
} else {
568-
match--
569-
}
570-
}
571-
}
572-
}
573-
return node
574-
}
575-
576-
const locateClosingTeleportAnchor = (node: Node | null): Node | null => {
558+
// looks ahead for a start and closing comment node
559+
const locateClosingAnchor = (
560+
node: Node | null,
561+
startData: string,
562+
endData: string
563+
): Node | null => {
577564
let match = 0
578565
while (node) {
579566
node = nextSibling(node)
580567
if (node && isComment(node)) {
581-
if (node.data === 'teleport start') match++
582-
if (node.data === 'teleport end') {
568+
if (node.data === startData) match++
569+
if (node.data === endData) {
583570
if (match === 0) {
584571
return nextSibling(node)
585572
} else {

0 commit comments

Comments
 (0)