-
Notifications
You must be signed in to change notification settings - Fork 200
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
Conversation
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
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
* | ||
* 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 thestopEventPropagation
helper in shadow-root.ts. However this was broken becausemaybeCloseSidebar
is called in response topointerdown
events bystopEventPropagation
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:
maybeCloseSidebar
. This sent a redundant "closeSidebar" message to the sidebar when it was already closed.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