<?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>246048</bug_id>
          
          <creation_ts>2022-10-04 16:19:36 -0700</creation_ts>
          <short_desc>Incorrect scroll position reported</short_desc>
          <delta_ts>2024-11-12 12:59:52 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Scrolling</component>
          <version>Safari 15</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 15</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=181954</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jack Doyle">jack</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>mattwoodrow</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>1903268</commentid>
    <comment_count>0</comment_count>
    <who name="Jack Doyle">jack</who>
    <bug_when>2022-10-04 16:19:36 -0700</bug_when>
    <thetext>Simple test case: 
https://codepen.io/GreenSock/pen/VwxxwWm?editors=0010

Scroll on any iOS device relatively quickly up and down. Notice the blue bar bounces around like crazy rather than staying &quot;stuck&quot;. The scroll position seems to be incorrectly reported or rendering is happening out-of-sync.

Challenge: can you please recommend a way to keep the blue bar &quot;stuck&quot; using transforms? I can&apos;t use something like position: fixed because the container may have a transform applied. sticky isn&apos;t an option either. I need a way to get the correct scroll position and apply it at the correct time to make that element appear frozen while scrolling its container. 

Help?! 

I&apos;ve reached out directly to the Safari team at least 5 times over the past few months and never receive an answer, so I&apos;m posting a bug report here. 

I have no idea if these are related to this issue, but here are several other reduced test cases showing various scroll-related bugs/inconsistencies in iOS Safari: 

- https://codepen.io/GreenSock/pen/XWajYwG/16c435b12ef09c38125204818e7b45fc
- https://codepen.io/GreenSock/pen/ExbrPNa/087cef197dc35445a0951e8935c41503
- https://codepen.io/GreenSock/pen/JjOxYpQ/3dd65ccec5a60f1d862c355d84d14562</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1903276</commentid>
    <comment_count>1</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2022-10-04 17:08:16 -0700</bug_when>
    <thetext>It&apos;s currently not possible to position an element in JavaScript in a way that is frame-accurate with user scrolling. Scrolling on iOS is always asynchronous.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1903278</commentid>
    <comment_count>2</comment_count>
    <who name="Jack Doyle">jack</who>
    <bug_when>2022-10-04 17:14:03 -0700</bug_when>
    <thetext>Dang!

Okay, &quot;currently not possible...&quot; does that mean that may change sometime soon? [fingers crossed]

And can you think of any out-of-the-box strategies to somehow make this work?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1903289</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2022-10-04 17:22:20 -0700</bug_when>
    <thetext>The only way would be to use position:fixed or position:sticky.

Can you hoist your fixed thing outside the transformed ancestor?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1903333</commentid>
    <comment_count>4</comment_count>
    <who name="Jack Doyle">jack</who>
    <bug_when>2022-10-04 22:16:09 -0700</bug_when>
    <thetext>Unfortunately, no, that isn&apos;t possible. We don&apos;t have control over the markup/structure. 

There aren&apos;t any tricks to getting scroll to be synchronous?

I attempted to preventDefault() on touchmove events and handle the scrolling via JavaScript which should totally work in theory, but there&apos;s a nasty bug in iOS Safari since 2018 (from what I can tell) that makes it impossible because the event.clientY/X are incorrectly reported, as illustrated in one of my demos provided:

https://codepen.io/GreenSock/pen/ExbrPNa/087cef197dc35445a0951e8935c41503

That bug report is here: https://bugs.webkit.org/show_bug.cgi?id=181954

I tried bumping it months ago and got no answer. 

So I have no way of figuring out where the user&apos;s finger actually is in the viewport (reliably) when scroll is involved. Or am I missing something?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1904936</commentid>
    <comment_count>5</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-10-11 16:20:17 -0700</bug_when>
    <thetext>&lt;rdar://problem/101055653&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2072730</commentid>
    <comment_count>6</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2024-11-04 20:26:21 -0800</bug_when>
    <thetext>There are a number of data races that cause the web process scroll position to be stale relative to the UI process.

In the following, {} represents some asynchronous behavior, and newlines represent thread or process hop.

A page render is triggered via :

CADisplayLink -&gt; RemoteLayerTreeDrawingAreaProxy::didRefreshDisplay -&gt;
                IPC -&gt; RemoteLayerTreeDrawingArea::displayDidRefresh -&gt; { zero delay timer } -&gt; Page::updateRendering()

A scroll update getting to the web process goes via:

UIScrollView -&gt; { Core Animation pre-commit hook } -&gt; -[WKContentView didUpdateVisibleRect:] -&gt;
                IPC -&gt; ViewUpdateDispatcher work queue -&gt; 
                             -&gt; ViewUpdateDispatcher::visibleContentRectUpdate

There are two main races here. The RemoteLayerTreeDrawingArea::displayDidRefresh message may reach the web process before the ViewUpdateDispatcher::visibleContentRectUpdate, and the ViewUpdateDispatcher work queue can delay the visibleContentRectUpdate getting to the main thread.

For everything to work correctly, the new scroll position from UIScrollView needs to get into a visibleContentRectUpdate before Page::updateRendering() runs. That rarely happens.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>