Why does this repaint/reflow hack work?
<p>Sometimes we have to force repaint/reflow for the browser to render certain states. For instance:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>window.onload = function () {
  setTimeout(function(){
    document.getElementById("gradient_text").innerHTML = "bar";
  }, 500);
}</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>#gradient_div {
  background: linear-gradient(#000000,#ffffff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="gradient_div"&gt;
  &lt;p id="gradient_text" onload="update"&gt;
    Foo
  &lt;/p&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
</p>

<p>The "gradient_text" element, refuses to visually update its text to "bar". In some cases, it's enough to trigger a synchronous repaint like so:</p>

<pre><code>...
setTimeout(function(){
  var elem = document.getElementById("gradient_text");
  // sync force repaint hack
  elem.innerHTML="bar";
  elem.style.display = 'none';
  elem.style.display = 'block';
}, 500);
...
</code></pre>

<p>However, this does not work. Apparently, it requires an asynchronous hack:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>window.onload = function () {
  setTimeout(function(){
    var elem = document.getElementById("gradient_text");
    elem.innerHTML = "bar";
    // async force repaint hack
    var display = elem.style.display;
    elem.style.display = 'none';
    setTimeout(function(){
      elem.style.display = display
    }, 50);
  }, 500);
}</code></pre>
<pre class="snippet-code-css lang-css prettyprint-override"><code>#gradient_div {
  background: linear-gradient(#000000,#ffffff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="gradient_div"&gt;
  &lt;p id="gradient_text" onload="update"&gt;
    Foo
  &lt;/p&gt;
&lt;/div&gt;</code></pre>
</div>
</div>
</p>

<p>What's causing the browser engine to behave this way? Mostly interested in Webkit/Blink.</p>