Skip to content

Conversation

@lucaswerkmeister
Copy link
Member

The wholeText property 1 2 contains the text of the current text node together with any text nodes adjacent to it. Given that we’re processing each text node separately, this doesn’t make sense and means we’re potentially processing the same text multiple times – we should just process textContent instead, which is the node’s own text.

I initially thought this bug wouldn’t be reproducible in practice without manually constructing a DOM with two adjacent text nodes, but then I realized a v-if with a false condition can easily produce such a DOM naturally, hence the test case.


Just a random bug I noticed while staring at the code ^^

The wholeText property [1] [2] contains the text of the current text
node together with any text nodes adjacent to it. Given that we’re
processing each text node separately, this doesn’t make sense and means
we’re potentially processing the same text multiple times – we should
just process textContent instead, which is the node’s own text.

I initially thought this bug wouldn’t be reproducible in practice
without manually constructing a DOM with two adjacent text nodes, but
then I realized a v-if with a false condition can easily produce such a
DOM naturally, hence the test case.

[1]: https://www.php.net/manual/en/class.domtext.php#domtext.props.wholetext
[2]: https://developer.mozilla.org/en-US/docs/Web/API/Text/wholeText
@lucaswerkmeister
Copy link
Member Author

Output of the test without the fix:

1) WMDE\VueJsTemplating\Test\TemplatingTest::testMustacheAfterVIf
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'<p>a: A c: C</p>'
+'<p>a: A c: Ca: A c: Cc: C</p>'

@lucaswerkmeister lucaswerkmeister merged commit 5c214c1 into master Jun 6, 2025
10 checks passed
@lucaswerkmeister lucaswerkmeister deleted the textContent branch June 6, 2025 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants