From: daiwei Date: Thu, 14 Aug 2025 13:12:15 +0000 (+0800) Subject: refactor: add txt runtime helper for getTextChild X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=807cd4ec9f75c5d1bfcfa2170369eaad00fc0b2f;p=thirdparty%2Fvuejs%2Fcore.git refactor: add txt runtime helper for getTextChild --- diff --git a/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap b/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap index f11bfbcc6f..ea0e2bbf6b 100644 --- a/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap @@ -1,12 +1,12 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`compile > bindings 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx, $props, $emit, $attrs, $slots) { const n0 = t0() - const x0 = _child(n0, -1) + const x0 = _txt(n0) _renderEffect(() => _setText(x0, "count is " + _toDisplayString(_ctx.count) + ".")) return n0 }" @@ -180,13 +180,13 @@ export function render(_ctx) { `; exports[`compile > dynamic root nodes and interpolation 1`] = ` -"import { child as _child, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, delegateEvents as _delegateEvents, template as _template } from 'vue'; +"import { txt as _txt, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, delegateEvents as _delegateEvents, template as _template } from 'vue'; const t0 = _template("", true) _delegateEvents("click") export function render(_ctx) { const n0 = t0() - const x0 = _child(n0, -1) + const x0 = _txt(n0) n0.$evtclick = e => _ctx.handleClick(e) _renderEffect(() => { const _count = _ctx.count @@ -198,12 +198,12 @@ export function render(_ctx) { `; exports[`compile > execution order > basic 1`] = ` -"import { child as _child, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; +"import { txt as _txt, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx) { const n0 = t0() - const x0 = _child(n0, -1) + const x0 = _txt(n0) _renderEffect(() => { _setProp(n0, "id", _ctx.foo) _setText(x0, _toDisplayString(_ctx.bar)) @@ -229,7 +229,7 @@ export function render(_ctx) { `; exports[`compile > execution order > with v-once 1`] = ` -"import { child as _child, next as _next, nthChild as _nthChild, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; +"import { child as _child, next as _next, nthChild as _nthChild, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; const t0 = _template("

", true) export function render(_ctx) { @@ -237,7 +237,7 @@ export function render(_ctx) { const n0 = _child(n3) const n1 = _next(n0) const n2 = _nthChild(n3, 3) - const x0 = _child(n0, -1) + const x0 = _txt(n0) _setText(x0, _toDisplayString(_ctx.foo)) _renderEffect(() => { _setText(n1, " " + _toDisplayString(_ctx.bar)) diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/expression.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/expression.spec.ts.snap index a206b19015..2d4da87c35 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/expression.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/expression.spec.ts.snap @@ -42,13 +42,13 @@ export function render(_ctx) { `; exports[`compiler: expression > empty interpolation 4`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; +"import { child as _child, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx) { const n1 = t0() const n0 = _child(n1) - const x1 = _child(n1, -1) + const x1 = _txt(n1) _renderEffect(() => { const _foo = _ctx.foo _setText(n0, _toDisplayString(_foo)) @@ -81,13 +81,13 @@ export function render(_ctx, $props, $emit, $attrs, $slots) { `; exports[`compiler: expression > update expression 1`] = ` -"import { child as _child, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; +"import { child as _child, txt as _txt, setProp as _setProp, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx) { const n1 = t0() const n0 = _child(n1) - const x1 = _child(n1, -1) + const x1 = _txt(n1) _renderEffect(() => { const _String = String const _foo = _ctx.foo diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformChildren.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformChildren.spec.ts.snap index 134f187731..c56b683323 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformChildren.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/transformChildren.spec.ts.snap @@ -18,7 +18,7 @@ export function render(_ctx) { `; exports[`compiler: children transform > children & sibling references 1`] = ` -"import { child as _child, next as _next, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; +"import { child as _child, next as _next, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; const t0 = _template("

", true) export function render(_ctx) { @@ -26,8 +26,8 @@ export function render(_ctx) { const n0 = _child(n3) const n1 = _next(n0) const n2 = _next(n1) - const x0 = _child(n0, -1) - const x2 = _child(n2, -1) + const x0 = _txt(n0) + const x2 = _txt(n2) _renderEffect(() => { _setText(x0, _toDisplayString(_ctx.first)) _setText(n1, " " + _toDisplayString(_ctx.second) + " " + _toDisplayString(_ctx.third) + " ") @@ -38,20 +38,20 @@ export function render(_ctx) { `; exports[`compiler: children transform > efficient find 1`] = ` -"import { child as _child, nthChild as _nthChild, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; +"import { child as _child, nthChild as _nthChild, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; const t0 = _template("
x
x
", true) export function render(_ctx) { const n1 = t0() const n0 = _nthChild(n1, 2) - const x0 = _child(n0, -1) + const x0 = _txt(n0) _renderEffect(() => _setText(x0, _toDisplayString(_ctx.msg))) return n1 }" `; exports[`compiler: children transform > efficient traversal 1`] = ` -"import { child as _child, next as _next, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; +"import { child as _child, next as _next, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; const t0 = _template("
x
", true) export function render(_ctx) { @@ -62,9 +62,9 @@ export function render(_ctx) { const n1 = _child(p1) const p2 = _next(p1) const n2 = _child(p2) - const x0 = _child(n0, -1) - const x1 = _child(n1, -1) - const x2 = _child(n2, -1) + const x0 = _txt(n0) + const x1 = _txt(n1) + const x2 = _txt(n2) _renderEffect(() => { const _msg = _ctx.msg _setText(x0, _toDisplayString(_msg)) diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snap index 09329d2e9c..f73bb18b9c 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snap @@ -1,13 +1,13 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`compiler: v-for > array de-structured value (with rest) 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx) { const n0 = _createFor(() => (_ctx.list), (_for_item0, _for_key0) => { const n2 = t0() - const x2 = _child(n2, -1) + const x2 = _txt(n2) _renderEffect(() => _setText(x2, _toDisplayString(_for_item0.value[0] + _for_item0.value.slice(1) + _for_key0.value))) return n2 }, ([id, ...other], index) => (id)) @@ -16,13 +16,13 @@ export function render(_ctx) { `; exports[`compiler: v-for > array de-structured value 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx) { const n0 = _createFor(() => (_ctx.list), (_for_item0, _for_key0) => { const n2 = t0() - const x2 = _child(n2, -1) + const x2 = _txt(n2) _renderEffect(() => _setText(x2, _toDisplayString(_for_item0.value[0] + _for_item0.value[1] + _for_key0.value))) return n2 }, ([id, other], index) => (id)) @@ -31,14 +31,14 @@ export function render(_ctx) { `; exports[`compiler: v-for > basic v-for 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, delegateEvents as _delegateEvents, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, delegateEvents as _delegateEvents, template as _template } from 'vue'; const t0 = _template("
", true) _delegateEvents("click") export function render(_ctx) { const n0 = _createFor(() => (_ctx.items), (_for_item0) => { const n2 = t0() - const x2 = _child(n2, -1) + const x2 = _txt(n2) n2.$evtclick = () => (_ctx.remove(_for_item0.value)) _renderEffect(() => _setText(x2, _toDisplayString(_for_item0.value))) return n2 @@ -48,13 +48,13 @@ export function render(_ctx) { `; exports[`compiler: v-for > key only binding pattern 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, createFor as _createFor, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, createFor as _createFor, template as _template } from 'vue'; const t0 = _template(" ", true) export function render(_ctx) { const n0 = _createFor(() => (_ctx.rows), (_for_item0) => { const n2 = t0() - const x2 = _child(n2, -1) + const x2 = _txt(n2) _setText(x2, _toDisplayString(_for_item0.value.id + _for_item0.value.id)) return n2 }, (row) => (row.id)) @@ -80,7 +80,7 @@ export function render(_ctx) { `; exports[`compiler: v-for > nested v-for 1`] = ` -"import { setInsertionState as _setInsertionState, child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; +"import { setInsertionState as _setInsertionState, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; const t0 = _template(" ") const t1 = _template("
", true) @@ -90,7 +90,7 @@ export function render(_ctx) { _setInsertionState(n5) const n2 = _createFor(() => (_for_item0.value), (_for_item1) => { const n4 = t0() - const x4 = _child(n4, -1) + const x4 = _txt(n4) _renderEffect(() => _setText(x4, _toDisplayString(_for_item1.value+_for_item0.value))) return n4 }, undefined, 1) @@ -101,13 +101,13 @@ export function render(_ctx) { `; exports[`compiler: v-for > object de-structured value (with rest) 1`] = ` -"import { getRestElement as _getRestElement, child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; +"import { getRestElement as _getRestElement, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx) { const n0 = _createFor(() => (_ctx.list), (_for_item0, _for_key0) => { const n2 = t0() - const x2 = _child(n2, -1) + const x2 = _txt(n2) _renderEffect(() => _setText(x2, _toDisplayString(_for_item0.value.id + _getRestElement(_for_item0.value, ["id"]) + _for_key0.value))) return n2 }, ({ id, ...other }, index) => (id)) @@ -116,13 +116,13 @@ export function render(_ctx) { `; exports[`compiler: v-for > object de-structured value 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; const t0 = _template(" ", true) export function render(_ctx) { const n0 = _createFor(() => (_ctx.items), (_for_item0) => { const n2 = t0() - const x2 = _child(n2, -1) + const x2 = _txt(n2) _renderEffect(() => _setText(x2, _toDisplayString(_for_item0.value.id) + _toDisplayString(_for_item0.value.value))) return n2 }, ({ id, value }) => (id)) @@ -131,13 +131,13 @@ export function render(_ctx) { `; exports[`compiler: v-for > object value, key and index 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx) { const n0 = _createFor(() => (_ctx.list), (_for_item0, _for_key0, _for_index0) => { const n2 = t0() - const x2 = _child(n2, -1) + const x2 = _txt(n2) _renderEffect(() => _setText(x2, _toDisplayString(_for_item0.value + _for_key0.value + _for_index0.value))) return n2 }, (value, key, index) => (key)) @@ -146,14 +146,14 @@ export function render(_ctx) { `; exports[`compiler: v-for > selector pattern 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, createFor as _createFor, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, createFor as _createFor, template as _template } from 'vue'; const t0 = _template(" ", true) export function render(_ctx) { let _selector0_0 const n0 = _createFor(() => (_ctx.rows), (_for_item0) => { const n2 = t0() - const x2 = _child(n2, -1) + const x2 = _txt(n2) _selector0_0(() => { _setText(x2, _toDisplayString(_ctx.selected === _for_item0.value.id ? 'danger' : '')) }) @@ -221,13 +221,13 @@ export function render(_ctx) { `; exports[`compiler: v-for > v-for aliases w/ complex expressions 1`] = ` -"import { getDefaultValue as _getDefaultValue, child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; +"import { getDefaultValue as _getDefaultValue, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx) { const n0 = _createFor(() => (_ctx.list), (_for_item0) => { const n2 = t0() - const x2 = _child(n2, -1) + const x2 = _txt(n2) _renderEffect(() => _setText(x2, _toDisplayString(_getDefaultValue(_for_item0.value.foo, _ctx.bar) + _ctx.bar + _ctx.baz + _getDefaultValue(_for_item0.value.baz[0], _ctx.quux) + _ctx.quux))) return n2 }) diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap index 272a28bc27..c60ae16be0 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap @@ -1,13 +1,13 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`compiler: v-if > basic v-if 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createIf as _createIf, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createIf as _createIf, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx) { const n0 = _createIf(() => (_ctx.ok), () => { const n2 = t0() - const x2 = _child(n2, -1) + const x2 = _txt(n2) _renderEffect(() => _setText(x2, _toDisplayString(_ctx.msg))) return n2 }) @@ -16,7 +16,7 @@ export function render(_ctx) { `; exports[`compiler: v-if > comment between branches 1`] = ` -"import { createIf as _createIf, child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; +"import { createIf as _createIf, txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; const t0 = _template("
") const t1 = _template("") const t2 = _template("

") @@ -38,7 +38,7 @@ export function render(_ctx) { return [n10, n11] })) const n13 = t5() - const x13 = _child(n13, -1) + const x13 = _txt(n13) _renderEffect(() => _setText(x13, _toDisplayString(_ctx.text))) return [n0, n13] }" @@ -62,7 +62,7 @@ export function render(_ctx) { `; exports[`compiler: v-if > template v-if 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createIf as _createIf, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createIf as _createIf, template as _template } from 'vue'; const t0 = _template("
") const t1 = _template("hello") const t2 = _template("

", true) @@ -72,7 +72,7 @@ export function render(_ctx) { const n2 = t0() const n3 = t1() const n4 = t2() - const x4 = _child(n4, -1) + const x4 = _txt(n4) _renderEffect(() => _setText(x4, _toDisplayString(_ctx.msg))) return [n2, n3, n4] }) diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vText.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vText.spec.ts.snap index 7792a03cb9..cf5d79a186 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vText.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vText.spec.ts.snap @@ -1,24 +1,24 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`v-text > should convert v-text to setText 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx, $props, $emit, $attrs, $slots) { const n0 = t0() - const x0 = _child(n0, -1) + const x0 = _txt(n0) _renderEffect(() => _setText(x0, _toDisplayString(_ctx.str))) return n0 }" `; exports[`v-text > should raise error and ignore children when v-text is present 1`] = ` -"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; +"import { txt as _txt, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue'; const t0 = _template("
", true) export function render(_ctx) { const n0 = t0() - const x0 = _child(n0, -1) + const x0 = _txt(n0) _renderEffect(() => _setText(x0, _toDisplayString(_ctx.test))) return n0 }" diff --git a/packages/compiler-vapor/src/generators/text.ts b/packages/compiler-vapor/src/generators/text.ts index 75faf3f57f..168943711c 100644 --- a/packages/compiler-vapor/src/generators/text.ts +++ b/packages/compiler-vapor/src/generators/text.ts @@ -70,6 +70,6 @@ export function genGetTextChild( return [ NEWLINE, - `const x${oper.parent} = ${context.helper('child')}(n${oper.parent}, -1)`, + `const x${oper.parent} = ${context.helper('txt')}(n${oper.parent})`, ] } diff --git a/packages/runtime-vapor/src/dom/node.ts b/packages/runtime-vapor/src/dom/node.ts index 47a4368646..6975f17d87 100644 --- a/packages/runtime-vapor/src/dom/node.ts +++ b/packages/runtime-vapor/src/dom/node.ts @@ -49,25 +49,36 @@ function skipBlockNodes(node: Node): Node { } /*! #__NO_SIDE_EFFECTS__ */ -export function _child(node: ParentNode): Node { - return node.firstChild! -} +const _txt: typeof _child = _child /** * Hydration-specific version of `child`. */ /*! #__NO_SIDE_EFFECTS__ */ -export function __child(node: ParentNode, offset?: number): Node { +const __txt: typeof __child = (node: ParentNode): Node => { let n = node.firstChild! - // when offset is -1, it means we need to get the text node of this element // since SSR doesn't generate whitespace placeholder text nodes, if firstChild // is null, manually insert a text node as the first child - if (offset === -1 && !n) { + if (!n) { node.textContent = ' ' return node.firstChild! } + return n +} + +/*! #__NO_SIDE_EFFECTS__ */ +export function _child(node: ParentNode): Node { + return node.firstChild! +} + +/** + * Hydration-specific version of `child`. + */ +/*! #__NO_SIDE_EFFECTS__ */ +export function __child(node: ParentNode): Node { + let n = node.firstChild! while (n && (isComment(n, '[') || isInsertionAnchor(n))) { // skip block node n = skipBlockNodes(n) as ChildNode @@ -121,8 +132,14 @@ type DelegatedFunction any> = T & { } /*! #__NO_SIDE_EFFECTS__ */ -export const child: DelegatedFunction = (node, offset) => { - return child.impl(node, offset) +export const txt: DelegatedFunction = node => { + return txt.impl(node) +} +txt.impl = _child + +/*! #__NO_SIDE_EFFECTS__ */ +export const child: DelegatedFunction = node => { + return child.impl(node) } child.impl = _child @@ -142,17 +159,19 @@ nthChild.impl = _nthChild * Enables hydration-specific node lookup behavior. * * Temporarily switches the implementations of the exported - * `child`, `next`, and `nthChild` functions to their hydration-specific - * versions (`__child`, `__next`, `__nthChild`). This allows traversal + * `txt`, `child`, `next`, and `nthChild` functions to their hydration-specific + * versions (`__txt`, `__child`, `__next`, `__nthChild`). This allows traversal * logic to correctly handle SSR comment anchors during hydration. */ export function enableHydrationNodeLookup(): void { + txt.impl = __txt child.impl = __child next.impl = __next nthChild.impl = __nthChild } export function disableHydrationNodeLookup(): void { + txt.impl = _txt child.impl = _child next.impl = _next nthChild.impl = _nthChild diff --git a/packages/runtime-vapor/src/index.ts b/packages/runtime-vapor/src/index.ts index 0b7b5aaa6f..34711803a0 100644 --- a/packages/runtime-vapor/src/index.ts +++ b/packages/runtime-vapor/src/index.ts @@ -17,7 +17,7 @@ export { export { renderEffect } from './renderEffect' export { createSlot, forwardedSlotCreator } from './componentSlots' export { template } from './dom/template' -export { createTextNode, child, nthChild, next } from './dom/node' +export { createTextNode, child, nthChild, next, txt } from './dom/node' export { setText, setHtml,