<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>249684</bug_id>
          
          <creation_ts>2022-12-20 16:26:11 -0800</creation_ts>
          <short_desc>Run WindowEventLoop tasks in at post-rendering update time</short_desc>
          <delta_ts>2023-06-07 08:17:17 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=249807</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Simon Fraser (smfr)">simon.fraser</reporter>
          <assigned_to name="Simon Fraser (smfr)">simon.fraser</assigned_to>
          <cc>cdumez</cc>
    
    <cc>rniwa</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>wenson_hsieh</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1920937</commentid>
    <comment_count>0</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2022-12-20 16:26:11 -0800</bug_when>
    <thetext>I was trying to implement `testRunner.renderingUpdate()` so you could write a test like:

        window.addEventListener(&apos;load&apos;, async () =&gt; {
            await testRunner.renderingUpdate();
            debug(&apos;rendering update complete&apos;);
            // do stuff
        }, false);


However, that turned out have flakey behavior with respect to the ordering of rAF callbacks:

        window.addEventListener(&apos;load&apos;, async () =&gt; {
            requestAnimationFrame(() =&gt; {
                debug(&apos;requestAnimationFrame callback&apos;);

                requestAnimationFrame(() =&gt; {
                    debug(&apos;second requestAnimationFrame callback, which should always come after the &quot;rendering update complete&quot;&apos;);
                });
            });

            await testRunner.renderingUpdate();
            debug(&apos;rendering update complete&apos;);
        }, false);

Sometimes the second rAF callback happened before &quot;rendering update complete&quot; and sometimes after. This depended on the timing of the microtask callbacks fired from WindowEventLoop, which I believe handles the resume of the load function when the `renderingUpdate` Promise is resolved.

The source of unpredictability which I identified was the timing of the zero-delay timer in WindowEventLoop. The incorrect behavior happened when the WindowEventLoop timer fired between `TiledCoreAnimationDrawingArea::scheduleRenderingUpdateRunLoopObserver()` and `TiledCoreAnimationDrawingArea::updateRenderingRunLoopCallback()`. There&apos;s already code that tries to avoid timing firing delaying the runloop observer for long periods of time (`breakToAllowRenderingUpdate()`), so we can piggyback off that to avoid this timer firing between the scheduling and the fire of the CFRunLoopObserver that controls the rendering update.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1920938</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-12-20 16:26:44 -0800</bug_when>
    <thetext>&lt;rdar://problem/103575958&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1920940</commentid>
    <comment_count>2</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2022-12-20 16:34:13 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/7944</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1921142</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2022-12-21 10:46:24 -0800</bug_when>
    <thetext>Turns out that this affects test behavior, I think largely because at Document::finishedParsing() time we call WebPage::unfreezeLayerTree() which triggers a rendering update, so the first WindowEventLoop opportunity is postponed. This means that a test with a zero-delay JS timer ends up running that timer logic before the WindowEventLoop task, instead of after.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1922754</commentid>
    <comment_count>4</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2023-01-03 16:57:35 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/8173</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1960308</commentid>
    <comment_count>5</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2023-06-07 08:17:17 -0700</bug_when>
    <thetext>Not pursuing this any more.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>