<?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>199691</bug_id>
          
          <creation_ts>2019-07-10 16:37:25 -0700</creation_ts>
          <short_desc>The whole viewport shifts down when resetting document scrollTop</short_desc>
          <delta_ts>2020-04-20 18:58:05 -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>HTML Editing</component>
          <version>Safari Technology Preview</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=198737</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=198599</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=198598</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=198597</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="Xidorn Quan">xidorn-webkit</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>fred.wang</cc>
    
    <cc>rniwa</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>thorton</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>wenson_hsieh</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1551882</commentid>
    <comment_count>0</comment_count>
      <attachid>373876</attachid>
    <who name="Xidorn Quan">xidorn-webkit</who>
    <bug_when>2019-07-10 16:37:25 -0700</bug_when>
    <thetext>Created attachment 373876
testcase

Steps to reproduce:
1. open the attached testcase on iOS
2. tap the &quot;Hello world&quot; text

Expect result:
The keyboard shows up without moving the viewport.

Actual result:
The whole viewport briefly shifts down.


In this testcase, the page tries to move the text up manually (for various reasons), thus it wants to remove the scrolling on document done by the browser. But that triggers this issue.

The effect is similar to bug 198737, and this is probably the actual cause of that issue.

This is reproducible on both iOS 12 and iOS 13.

Similar to bug 198737, you can see this shift clearer via using simulators with Debug / Slow Animations enabled.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1552161</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-07-11 12:50:14 -0700</bug_when>
    <thetext>&lt;rdar://problem/52966595&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1552569</commentid>
    <comment_count>2</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2019-07-12 15:42:30 -0700</bug_when>
    <thetext>The scrolling in iOS is asynchronous. By the time scroll event is fired, the scrolling had already happened asynchronously so that&apos;s too late.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1552599</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2019-07-12 16:21:55 -0700</bug_when>
    <thetext>document.addEventListener(&apos;scroll&apos;, evt =&gt; {
  document.documentElement.scrollTop = 0;
  document.body.scrollTop = 0;
});

This is a really bad pattern that we see commonly; if you rubber-band the content, it will also try to set the scrollTop back to 0.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1552728</commentid>
    <comment_count>4</comment_count>
    <who name="Xidorn Quan">xidorn-webkit</who>
    <bug_when>2019-07-13 21:27:01 -0700</bug_when>
    <thetext>(In reply to Simon Fraser (smfr) from comment #3)
&gt; document.addEventListener(&apos;scroll&apos;, evt =&gt; {
&gt;   document.documentElement.scrollTop = 0;
&gt;   document.body.scrollTop = 0;
&gt; });
&gt; 
&gt; This is a really bad pattern that we see commonly; if you rubber-band the
&gt; content, it will also try to set the scrollTop back to 0.

I feel like this is potentially an anti-pattern, but how would you recommend for the case where author may want to move the element manually, for example, when they want to zoom to the current visible area?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1552763</commentid>
    <comment_count>5</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2019-07-14 14:45:16 -0700</bug_when>
    <thetext>(In reply to Xidorn Quan from comment #4)
&gt; (In reply to Simon Fraser (smfr) from comment #3)
&gt; &gt; document.addEventListener(&apos;scroll&apos;, evt =&gt; {
&gt; &gt;   document.documentElement.scrollTop = 0;
&gt; &gt;   document.body.scrollTop = 0;
&gt; &gt; });
&gt; &gt; 
&gt; &gt; This is a really bad pattern that we see commonly; if you rubber-band the
&gt; &gt; content, it will also try to set the scrollTop back to 0.
&gt; 
&gt; I feel like this is potentially an anti-pattern, but how would you recommend
&gt; for the case where author may want to move the element manually, for
&gt; example, when they want to zoom to the current visible area?

The recommended approach is to move the element immediately when the input element is focused so the WebKit wouldn&apos;t try to scroll to it. In general, once the keyboard has started being brought up, there is nothing you can do to cancel the scrolling.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1552778</commentid>
    <comment_count>6</comment_count>
    <who name="Xidorn Quan">xidorn-webkit</who>
    <bug_when>2019-07-14 17:18:53 -0700</bug_when>
    <thetext>&gt; The recommended approach is to move the element immediately when the input element is focused so the WebKit wouldn&apos;t try to scroll to it.

Thanks for the advice. It&apos;s not always trivial to do in practice, but I guess it&apos;s not impossible either.

I wonder, though, why would resetting the scrollTop makes the viewport shift down while we are just trying to stop it from shifting up?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1553052</commentid>
    <comment_count>7</comment_count>
    <who name="Xidorn Quan">xidorn-webkit</who>
    <bug_when>2019-07-15 17:39:17 -0700</bug_when>
    <thetext>(In reply to Ryosuke Niwa from comment #5)
&gt; The recommended approach is to move the element immediately when the input
&gt; element is focused so the WebKit wouldn&apos;t try to scroll to it.

Actually, this approach doesn&apos;t seem to work either.

As shown in this testcase, I do move the element immediately when it&apos;s focused, and it just has a transition to do so smoothly.

Even if I remove the transition (so that the moving happens immediately in handler of focus event in any sense), the viewport still scroll.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1628545</commentid>
    <comment_count>8</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2020-03-10 23:21:53 -0700</bug_when>
    <thetext>(In reply to Xidorn Quan from comment #7)
&gt; (In reply to Ryosuke Niwa from comment #5)
&gt; &gt; The recommended approach is to move the element immediately when the input
&gt; &gt; element is focused so the WebKit wouldn&apos;t try to scroll to it.
&gt; 
&gt; Actually, this approach doesn&apos;t seem to work either.
&gt; 
&gt; As shown in this testcase, I do move the element immediately when it&apos;s
&gt; focused, and it just has a transition to do so smoothly.
&gt; 
&gt; Even if I remove the transition (so that the moving happens immediately in
&gt; handler of focus event in any sense), the viewport still scroll.

Hm... is this still an issue in the latest betas of iOS 13.4?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1643728</commentid>
    <comment_count>9</comment_count>
    <who name="Xidorn Quan">xidorn-webkit</who>
    <bug_when>2020-04-20 18:58:05 -0700</bug_when>
    <thetext>(In reply to Ryosuke Niwa from comment #8)
&gt; Hm... is this still an issue in the latest betas of iOS 13.4?

Sorry for the late reply.

I didn&apos;t get a chance to test on the beta version, but it still seems to be an issue on the latest 13.4.1.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>373876</attachid>
            <date>2019-07-10 16:37:25 -0700</date>
            <delta_ts>2019-07-10 16:37:25 -0700</delta_ts>
            <desc>testcase</desc>
            <filename>transform-text.html</filename>
            <type>text/html</type>
            <size>971</size>
            <attacher name="Xidorn Quan">xidorn-webkit</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8bWV0YSBuYW1lPSJ2aWV3cG9ydCIgY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