TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Don't attach tooltips to document.body

230 pointsby atfzlalmost 4 years ago

19 comments

habosaalmost 4 years ago
This is an excellent and technically deep post, I learned a lot reading it and I&#x27;m going to make sure I&#x27;m using my tooltips properly.<p>It&#x27;s a shame that most of the comments here are just people criticizing web dev frameworks and browsers.
Agentlienalmost 4 years ago
This issue of needlessly forcing the system to recalculate a tree of positions and bonds is also common in other UI contexts such as desktop applications and game UIs.<p>In fact, in games it also happens with the transforms of objects and has been the cause of a number of performance issues during development of AAA games I&#x27;ve been part of.
Pxtlalmost 4 years ago
... this post perfectly encapsulates why I hate web development. A painful and easy to miss bug when trying to reimplement a GUI feature that&#x27;s been available in every decent GUI framework for over two decades.
评论 #28254963 未加载
评论 #28255873 未加载
评论 #28256362 未加载
评论 #28255875 未加载
评论 #28256923 未加载
评论 #28255745 未加载
评论 #28258793 未加载
评论 #28255431 未加载
评论 #28258857 未加载
评论 #28255087 未加载
评论 #28254932 未加载
myfonjalmost 4 years ago
As for why the parent render tree invalidation is necessary, consider<p><pre><code> &lt;style&gt; main:only-child * { &#x2F;* ... *&#x2F; } &lt;&#x2F;style&gt; &lt;body&gt; &lt;main&gt;lots of stuff &lt;&#x2F;main&gt; &lt;&#x2F;body&gt; </code></pre> When second node is appended to &lt;body&gt; our CSS selector no longer matches so the rule stops being applied and content of the &lt;main&gt; is no longer styled.<p>When there is (next) sibling wrapper present, anything what happens inside it cannot affect the &lt;main&gt; in our example: in CSS there simply is currently no way to target element according it&#x27;s next sibling inner structure. (There is one for previous sibling: `prev:empty + next {}`: when prev stops being empty, rule stops to match.)
foobar33333almost 4 years ago
It would be nice if the browser title text feature didn&#x27;t flat out suck. Why is there no way to show tooltips immediately rather than having to wait a few seconds. Seems like every website reimplements them because the browser ones are useless.
评论 #28256953 未加载
评论 #28257429 未加载
评论 #28254595 未加载
chrismorganalmost 4 years ago
A remark on the two diagrams following “Then the CSS is parsed and browser creates the CSSOM (CSS Object Model)”: they show body as the root, but would be more accurate if they showed html as be the root and head as hidden by `display: none`.<p>Consider this style rule set which does just what it looks like:<p><pre><code> head, title, style, script { display: block; }</code></pre>
ComputerGurualmost 4 years ago
I imagine another option if you need to assign a node to a class and <i>then</i> measure its size&#x2F;location (which is probably quite often) that you can basically take some preliminary&#x2F;initial values, attach the class, and use an onresize handler to trigger a remeasurement once the reflow has completed at a pace of the browser’s own choosing?
sandstromalmost 4 years ago
At the bottom of the article they mention:<p><pre><code> What happened here? The tooltip was attached to the tooltip container and not to the body. This invalidated a much smaller subtree, which was the tooltip container. The tooltip container is not visible in the page, so modifying it doesn’t invalidate the complete page render tree. If the tooltip container would have been visible in the page, then the complete render tree would be invalidated but in this case only an independent subtree was invalidated. </code></pre> So the tooltip container needs to be hidden with e.g. `display: none`?
评论 #28273710 未加载
评论 #28257405 未加载
nameloswalmost 4 years ago
It&#x27;s the same reason that most React apps start with ReactDOM.render(&lt;App &#x2F;&gt;, document.getElementById(&#x27;app&#x27;)) instead of ReactDOM.render(&lt;App &#x2F;&gt;, document.body).<p>IIRC there were many tutorials in the early days of React that mentioned this.
评论 #28254671 未加载
评论 #28255792 未加载
quickthrower2almost 4 years ago
And Do: profile your web app!
geuisalmost 4 years ago
I appreciate these kinds of frontend deep dives.
sidcoolalmost 4 years ago
I am not a UI dev, but I have seen some noise about using Canvas based text rendering. What is HN&#x27;s opinion on this?
评论 #28254967 未加载
评论 #28255178 未加载
hugneutronalmost 4 years ago
The article didn’t seem to mention anything about performance in other browsers, which I find surprising.
faeyanpiraatalmost 4 years ago
... Next steps are paint and composting ...<p>That step seems unrelated
评论 #28255956 未加载
Aeolunalmost 4 years ago
Having worked with React a lot. I could see the invalidation answer coming from a mile away.<p>Glad all that knowledge is useful in different contexts though.
TekMolalmost 4 years ago
Talking about tooltips:<p>Did anybody get Popper to work as an ES6 module? I tried for a while and gave up.
评论 #28326057 未加载
imranghanialmost 4 years ago
Really insightful.
bsergealmost 4 years ago
Wait, you guys use tooltips?<p>Some websites don&#x27;t even have text accompanying their unintuitive but kewl looking icons.<p>The future is now, old timers!
评论 #28255292 未加载
catmanjanalmost 4 years ago
Yet another browser based leaky abstraction... Looking forward to the inevitable trend flip back to native ui!
评论 #28254425 未加载