Note that there are some explanatory texts on larger screens.

plurals
  1. POIs DOM rendering GUARANTEED to block during a single (synchronous) function's execution?
    primarykey
    data
    text
    <p>DOM blocking is something many people not familiar with JavaScript's strictly single-threaded synchronous execution model find out about the hard way, and it's usually just something we want to work around somehow (using timeouts, web-workers, etc). All well and good.</p> <p>However, I would like to know if blocking of the actual user-visible rendering is something you can actually <em>rely</em> on. I'm 90% sure it is <em>de facto</em> the case in most browsers but I am hoping this isn't just a happily consistent accident. I can't seem to find any definitive statements from DOM specifications or even vendor documentation like MDM.</p> <p>What worries me slightly is that while changes to the DOM are indeed not visible looking at the page, the internal DOM geometry (including CSS transforms and filters) <em>does</em> actually update during synchronous execution. For example:</p> <pre><code>console.log(element.getBoundingRect().width); element.classList.add("scale-and-rotate"); console.log(element.getBoundingRect().width); element.classList.remove("scale-and-rotate"); </code></pre> <p>... will indeed report two different width values, though the page does not <em>appear</em> to flash. Synchronously waiting after the class is added (using a while loop) doesn't make the temporary changes visible either. Doing a Timeline trace in Chrome reveals that internally paint and re-paint is taking place just the same, which makes sense...</p> <p>My concern is that, lacking a specific reason not, some browsers, like say, those dealing with underpowered mobile CPUs, may choose to actually reflect those internal calculations in the user-visible layout <em>during</em> that function's execution, and thus will result in an ugly "flash" during such temporary operations. So, more concretely, what I'm asking is: Do they have a specific reason not to?</p> <p>(If you are wondering why I care about this at all, I sometimes need to measure calculated dimensions using <code>getBoundingRect</code> for elements in a certain state to plan out spacing or animations or other such things, without actually putting them in that state or animating them first...)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload