Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ignoring of events inside Hypothesis UI elements #6717

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

robertknight
Copy link
Member

@robertknight robertknight commented Dec 9, 2024

The maybeCloseSidebar function inside guest.ts relied on events inside Hypothesis UI elements not reaching it because they were stopped at the shadow root boundary by the stopEventPropagation helper in shadow-root.ts. However this was broken because maybeCloseSidebar is called in response to pointerdown events by stopEventPropagation does not intercept this event.

The issue usually went unnoticed because clicking in the sidebar's toggle button when it was closed resulted in the following sequence of events:

  1. "pointerdown" event, processed by maybeCloseSidebar. This sent a redundant "closeSidebar" message to the sidebar when it was already closed.
  2. "click" event handled, resulting in the sidebar opening.

In some circumstances however, such as when tap-to-click is enabled on macOS [1], these events were sometimes received in the opposite order. As a result the sidebar was opened and then immediately closed.

Simplify the approach by removing the logic for preventing event propagation and instead testing whether the element is a Hypothesis UI element inside maybeCloseSidebar by looking at its tag name.

[1] https://hypothes-is.slack.com/archives/C4K6M7P5E/p1733756425323569

The `maybeCloseSidebar` function inside guest.ts relied on events inside
Hypothesis UI elements not reaching it because they were stopped at the shadow
root boundary by the `stopEventPropagation` helper in shadow-root.ts. However
this was broken because `maybeCloseSidebar` is called in response to
`pointerdown` events but `stopEventPropagation` does not intercept this event.

The issue usually went unnoticed because clicking in the sidebar's toggle
button when it was closed resulted in the following sequence of events:

 1. "pointerdown" event, processed by `maybeCloseSidebar`. This sent a redundant
    "closeSidebar" message to the sidebar when it was already closed.
 2. "click" event handled, resulting in the sidebar opening.

In some circumstances however, such as when tap-to-click is enabled on macOS [1],
these events were sometimes received in the opposite order. As a result the
sidebar was opened and then immediately closed.

Simplify the approach by removing the logic for preventing event propagation and
instead testing whether the element is a Hypothesis UI element inside
`maybeCloseSidebar` by looking at its tag name.

[^1]: https://hypothes-is.slack.com/archives/C4K6M7P5E/p1733756425323569
Copy link

codecov bot commented Dec 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.42%. Comparing base (c738173) to head (deb6160).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6717      +/-   ##
==========================================
- Coverage   99.43%   99.42%   -0.01%     
==========================================
  Files         271      271              
  Lines       10215    10214       -1     
  Branches     2434     2437       +3     
==========================================
- Hits        10157    10155       -2     
- Misses         58       59       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@robertknight robertknight requested a review from acelaya December 9, 2024 17:44
*
* This makes the host page a little bit less aware of the annotator activity.
* It is still possible for the host page to manipulate the events on the capturing
* face.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is hand-wavy and doesn't point to any specific issues with web pages that we need to be aware of, so I'm going to ignore it. I will look back through the commit history tomorrow in case I can find any remaining reasons to keep the logic, but otherwise let's try to simplify the code.

Copy link
Contributor

@acelaya acelaya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@robertknight robertknight marked this pull request as ready for review December 10, 2024 11:39
@robertknight robertknight merged commit e763a9a into main Dec 10, 2024
4 checks passed
@robertknight robertknight deleted the fix-ignoring-events-inside-hypothesis-ui branch December 10, 2024 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants