Why use hostSetText not setElementText when patching text nodes #13066
Unanswered
shellRaining
asked this question in
Help/Questions
Replies: 1 comment
-
const el = document.createElement('span')
const text = document.createTextNode('hi')
el.appendChild(text)
el.textContent = 'foo' // will re-create a text node
text.nodeValue = 'foo' // re-using the text node Which one do you think is better? |
Beta Was this translation helpful? Give feedback.
0 replies
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
core/packages/runtime-core/src/renderer.ts
Lines 490 to 503 in 4fea167
core/packages/runtime-dom/src/nodeOps.ts
Lines 77 to 83 in 4fea167
I noticed that when this function is executed, if the n1 node exists, it can be determined that both n1 and n2 are of type Text. So why use hostSetText (which set
nodeValue
in a browser environment) instead of setElementText (which settextContent
in a browser environment)?I wrote a script to test the execution speed of both and found that using textContent to set text is faster. Therefore, I'm wondering if, assuming the code logic is correct, such a replacement could be made to speed up text patching. After making the replacement, I ran unit tests and no errors were reported. As for the e2e tests, it might be due to incorrect configuration on my part, so I haven't run them yet.
test script as follow, If there is an issue with my test, welcome advise~
Beta Was this translation helpful? Give feedback.
All reactions