<?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>264469</bug_id>
          
          <creation_ts>2023-11-08 23:47:30 -0800</creation_ts>
          <short_desc>Incorrect wheel event behavior with Shadow DOM</short_desc>
          <delta_ts>2024-01-18 09:02:56 -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 17</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 14</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <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>
          
          <blocked>148695</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Bretislav Wajtr">bretislav</reporter>
          <assigned_to name="Simon Fraser (smfr)">simon.fraser</assigned_to>
          <cc>nmouchtaris</cc>
    
    <cc>rniwa</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1991082</commentid>
    <comment_count>0</comment_count>
      <attachid>468530</attachid>
    <who name="Bretislav Wajtr">bretislav</who>
    <bug_when>2023-11-08 23:47:30 -0800</bug_when>
    <thetext>Created attachment 468530
safari-wheel-listener-scroll-issue.html

One of our customers complained about the inability to scroll the page when over certain elements on the page when using MacBook, Safari and either Trackpad or MagicMouse. Note that the same issue cannot be reproduced with other browsers or when scrolling with a mouse with a physical wheel. For reference, this is the bug on our side: https://github.com/vaadin/web-components/issues/6695

We reduced the issue test case to what is attached in safari-wheel-listener-scroll-issue.html. The DOM structure presented there is a simplification of our app structure, the minimal structure where I was still able to reproduce the issue.

Test instructions:
1. Open Safari on Mac and use either Trackpad or MagicMouse for scrolling
2. Open safari-wheel-listener-scroll-issue.html
3. Position the mouse over one of the colored areas and swipe with two fingers in a way that the page should scroll down
4. -&gt; &quot;test-container&quot; element content scrolls 
5. Now Position the mouse over the white stripe
6. Swipe the same way
Actual behavior: Now the &quot;body&quot; scrolls instead of the &quot;test-container&quot;
Expected  behavior: I&apos;d expect the &quot;test-container&quot; to scroll as in other browsers, or when scrolling with mouse with physical wheel

The weird thing is that the issue is caused just by attaching an *empty* &quot;wheel&quot; event listener to one of the elements in the DOM structure -&gt; comment out line 35, so the event listener is not added, and suddenly, the scroll behavior is different and the &quot;test-container&quot; scrolls even when positioned over the white stripe.

I believe that adding an empty event listener anywhere should not change the scrolling behavior of the page, regardless of the DOM structure.

Safari Version 17.1 (19616.2.9.11.7)
Mac Mini M2
macOS 14.1 (23B74)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1991683</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2023-11-10 13:35:26 -0800</bug_when>
    <thetext>Adding a wheel event listener changes everything about how scrolling works, as every event now has to hop across processes.

What you are describing looks like a bug, however I expect that there will always be performance implications from having event listeners.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1991685</commentid>
    <comment_count>2</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2023-11-10 13:47:36 -0800</bug_when>
    <thetext>Does this reproduce without the Shadow DOM stuff in the test page?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1992438</commentid>
    <comment_count>3</comment_count>
    <who name="Bretislav Wajtr">bretislav</who>
    <bug_when>2023-11-14 05:44:15 -0800</bug_when>
    <thetext>@Simon 
No, it cannot be reproduced if I use simple &lt;div&gt; instead of that web-component with a Shadow DOM and &lt;slot&gt; in it. So using the web component in the DOM structure is required to reproduce this issue.

In the real use-case, where we noticed the bug, we use much more complicated structure of web components and other elements... however, I was able to narrow down the test case to what is in the attachment.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1993016</commentid>
    <comment_count>4</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-11-15 23:48:13 -0800</bug_when>
    <thetext>&lt;rdar://problem/118496293&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2005748</commentid>
    <comment_count>5</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2024-01-17 20:56:41 -0800</bug_when>
    <thetext>This fixes it, but I&apos;m not entirely sure if it&apos;s correct:

diff --git a/Source/WebCore/page/mac/EventHandlerMac.mm b/Source/WebCore/page/mac/EventHandlerMac.mm
index c13fcc320751735a86565b8e3e67f8d9c9984608..97e4eb43530930df997f462d942da55b4dde4404 100644
--- a/Source/WebCore/page/mac/EventHandlerMac.mm
+++ b/Source/WebCore/page/mac/EventHandlerMac.mm
@@ -800,7 +800,7 @@ static ContainerNode* findEnclosingScrollableContainer(ContainerNode* node, cons
 {
     // Find the first node with a valid scrollable area starting with the current
     // node and traversing its parents (or shadow hosts).
-    for (ContainerNode* candidate = node; candidate; candidate = candidate-&gt;parentOrShadowHostNode()) {
+    for (auto* candidate = node; candidate; candidate = candidate-&gt;parentInComposedTree()) {
         if (is&lt;HTMLIFrameElement&gt;(*candidate))
             continue;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2005751</commentid>
    <comment_count>6</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2024-01-17 21:21:56 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/22892</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2005865</commentid>
    <comment_count>7</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-01-18 09:02:54 -0800</bug_when>
    <thetext>Committed 273181@main (bd33a8e97f27): &lt;https://commits.webkit.org/273181@main&gt;

Reviewed commits have been landed. Closing PR #22892 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>468530</attachid>
            <date>2023-11-08 23:47:30 -0800</date>
            <delta_ts>2023-11-08 23:49:20 -0800</delta_ts>
            <desc>safari-wheel-listener-scroll-issue.html</desc>
            <filename>safari-wheel-listener-scroll-issue.html</filename>
            <type>text/html</type>
            <size>1953</size>
            <attacher name="Bretislav Wajtr">bretislav</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbmc9ImVuIj4KPGhlYWQ+CiAgICA8bWV0YSBjaGFyc2V0
PSJVVEYtOCIvPgogICAgPG1ldGEgaHR0cC1lcXVpdj0iWC1VQS1Db21wYXRpYmxlIiBjb250ZW50
PSJJRT1lZGdlIi8+CiAgICA8bWV0YSBuYW1lPSJ2aWV3cG9ydCIgY29udGVudD0id2lkdGg9ZGV2
aWNlLXdpZHRoLCBpbml0aWFsLXNjYWxlPTEuMCIvPgogICAgPHRpdGxlPlNhZmFyaSB3aGVlIGxp
c3RlbmVyIHNjcm9sbCBpc3N1ZTwvdGl0bGU+CjwvaGVhZD4KPGJvZHk+Cgo8ZGl2IGlkPSJvdXRs
ZXQiIHN0eWxlPSJoZWlnaHQ6IDEwMHZoOyB3aWR0aDogMTAwJTsgbWFyZ2luLWJvdHRvbTogNTBw
eDsiPgogICAgPHRlc3QtY29udGFpbmVyPgogICAgICAgIDxkaXYgc3R5bGU9ImJhY2tncm91bmQt
Y29sb3I6IGdyZWVuOyBoZWlnaHQ6IDMwMHB4OyB3aWR0aDogMTAwJTsgY29sb3I6IHdoaXRlIj4K
ICAgICAgICAgICAgUG9zaXRpb24geW91ciBtb3VzZSBvdmVyIHRoaXMgdGV4dCBhbmQgdHJ5IHRv
IHN3aXBlIGRvd24gd2l0aAogICAgICAgICAgICB0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