Bug 263374 - scrollIntoView() in overflow is causing the whole page to move upwards slightly
Summary: scrollIntoView() in overflow is causing the whole page to move upwards slightly
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: Safari 16
Hardware: All All
: P2 Critical
Assignee: Simon Fraser (smfr)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-10-19 04:58 PDT by harnoor1994
Modified: 2024-01-02 13:56 PST (History)
5 users (show)

See Also:


Attachments
Test case (1.19 KB, text/html)
2023-12-18 11:46 PST, Simon Fraser (smfr)
no flags Details
Test case with { behavior: 'smooth', block: 'start' } (1.31 KB, text/html)
2023-12-18 15:31 PST, Simon Fraser (smfr)
no flags Details
Issue Repro Steps (42.90 MB, video/quicktime)
2023-12-18 16:43 PST, Byungseon(Sun) Shin
no flags Details
Invisible area introduced by iframe (93.44 KB, image/png)
2023-12-22 13:12 PST, Byungseon(Sun) Shin
no flags Details
Test case with iframe with { behavior: 'smooth', block: 'start' } (5.85 KB, text/html)
2023-12-22 13:13 PST, Byungseon(Sun) Shin
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description harnoor1994 2023-10-19 04:58:46 PDT
element.ScrollIntoView() is causing the whole page to move upwards when scrollIntoViewOptions are { behavior: 'smooth', block: 'start' };

I have seen multiple people reporting the same issue here: https://stackoverflow.com/a/52835382

And as a workaround I have updated the Options to { behavior: 'smooth', block: 'nearest', inline: 'start' };

However, this is not as smooth as the 'block: start' which works perfectly on Chromium based Browsers. 

Also workaround breaks when elements are not on screen and ScrollIntoView is called.
Comment 1 Simon Fraser (smfr) 2023-10-19 13:44:09 PDT
I'm confused by the "Web Inspector" prefix. Does this happen in Web Inspector, or does it happen in normal web pages?
Comment 2 harnoor1994 2023-10-25 00:18:09 PDT
Updated the bug title.
Comment 3 Radar WebKit Bug Importer 2023-10-26 04:59:14 PDT
<rdar://problem/117528549>
Comment 4 Byungseon(Sun) Shin 2023-11-07 14:09:02 PST
FYI, it's a sample code to explain this issue. 
- https://jsfiddle.net/cqzv37nm/4/
Comment 5 Simon Fraser (smfr) 2023-12-18 11:46:42 PST
Created attachment 469114 [details]
Test case
Comment 6 Simon Fraser (smfr) 2023-12-18 15:27:26 PST
What's happening here is that we reveal the element inside the overflow scroll, and then also scroll the overflow scroller itself to the top of the view, which isn't necessary if it's fully visible.

I'll do some testing to see how other browsers behave.
Comment 7 Simon Fraser (smfr) 2023-12-18 15:28:39 PST
The attached test case has identical behavior in Chrome, Firefox and Safari.
Comment 8 Simon Fraser (smfr) 2023-12-18 15:31:49 PST
Created attachment 469118 [details]
Test case with { behavior: 'smooth', block: 'start' }
Comment 9 Simon Fraser (smfr) 2023-12-18 15:32:51 PST
I don't have enough information to fix this bug at this point. Please attach a test case that has different behavior in Chrome and Safari.
Comment 10 Byungseon(Sun) Shin 2023-12-18 16:43:29 PST
Created attachment 469120 [details]
Issue Repro Steps
Comment 11 Byungseon(Sun) Shin 2023-12-18 16:46:03 PST
@Simon, thank you for taking time to look at this issue.
I may not clearly describe the repro sequences with the test URL. 

I tried with both of the test cases you attached today and I could easily repro the issue. Please review the attached video capture.

To reproduce the issue, click the list and then go to the top of the list and move back and forth afterwards.
Comment 12 Simon Fraser (smfr) 2023-12-18 21:50:03 PST
It looks like you're using a wheel mouse rather than a trackpad, and you're using the mouse wheel while hovered over the scrollbar, is that correct?

I'm not sure how this is related to the JS calling scrollIntoView(). Perhaps you're describing a different bug from the original report.
Comment 13 Byungseon(Sun) Shin 2023-12-18 22:16:26 PST
@Simon, that is right. I used mouse wheel event while hovered over the scrollbar.
I believe we raised the issue for the mouse wheel event as we refer to the stack overflow discussion <https://stackoverflow.com/a/52835382>.
But please let me know which parts of bug report may not described incorrectly.
Comment 14 Simon Fraser (smfr) 2023-12-19 10:25:51 PST
Does your issue reproduce in a test case that never calls scrollIntoView()?
Comment 15 Byungseon(Sun) Shin 2023-12-19 10:32:28 PST
@Simon, thank you for the detailed information. Will double check again.
Comment 16 Byungseon(Sun) Shin 2023-12-19 11:59:06 PST
@Simon, I just checked it again without scrollIntoView call and see the same behavior. So, the issue I reproduce is not related to the scrollIntoView.
Sorry about the confusion. 

However, I can also confirm that the original issue reported by Hanoor still related with the scrollIntoView(block: 'start') since it has been fixed by having (block: 'nearest', inline: 'start') options and it is only needed on the Safari Browser. 

So, I will share more clear repro sequences once we will find a test case for this.
Comment 17 Byungseon(Sun) Shin 2023-12-22 13:12:59 PST
Created attachment 469177 [details]
Invisible area introduced by iframe
Comment 18 Byungseon(Sun) Shin 2023-12-22 13:13:56 PST
Created attachment 469178 [details]
Test case with iframe with { behavior: 'smooth', block: 'start' }
Comment 19 Byungseon(Sun) Shin 2023-12-22 13:18:54 PST
@Simon, I could find the issue only happening when there is invisible area as attached image <invisible area introduced by iframe>. 

Please try with new test case with iframe. When you click the menu item, you can see the page will be moved up by 20px which is same height introduced by the iframe.
Comment 20 Simon Fraser (smfr) 2024-01-02 10:33:15 PST
Thank you for the new test case. I can reproduce.
Comment 21 Simon Fraser (smfr) 2024-01-02 11:41:56 PST
What's happening in your test case is that you end up with two iframes below the 100% height content, making the content scrollable, so clicking on a section tries to scroll as much as it can (20px or so).

Still, there's a bug with `block: start`
Comment 22 Byungseon(Sun) Shin 2024-01-02 12:11:18 PST
@simon, thanks for the review the issue.

I think we can work around the issue by setting the the iframe to display:block instead of display:inline. 

Would it be acceptable workaround based on the current test case since we do not want the iframe be shown on the page?
Comment 23 Simon Fraser (smfr) 2024-01-02 13:30:14 PST
https://bugs.webkit.org/attachment.cgi?id=469178 scrolls in Chrome too, but not Firefox.
Comment 24 Simon Fraser (smfr) 2024-01-02 13:35:10 PST
Each iframe adds 20px of scrollable overflow because of `line-height: 20px;`.

You should also stop using `overflow: overlay` since this is just a synonym for `overflow: auto` (but this doesn't change behavior).

Safari and Chrome have the same behavior here, so I think there's no bug here.
Comment 25 Byungseon(Sun) Shin 2024-01-02 13:56:40 PST
@simon, thanks for taking time to investigate it and confirmation.