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

⚠️ Fixed accessing an obsolete isCollapsed value on pointerup handling ⚠️ #163

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

oleksandr-danylchenko
Copy link
Contributor

Issue

Source - #136 (comment)

Unfortunately, I noticed that the "lagging behind isCollapsed property" is still a thing for touch devices! When I tap somewhere around the selection - the isCollapsed is still true when the onPointerUp gets handled, even within the setTimeout.
image
That creates a weird effect that makes a user tap twice or even more on iOS to dismiss the selection.

Changes Made

I discovered that on iOS it takes up to 40ms. to properly report that the selection range is collapsed even when a user clicks beyond the existing selection! But if we decide to apply such a timeout universally - it'll make user experience on desktops and Androids slower in general.

Instead, I introduced "polling" for the range's collapsed state! If the timeDifference is smaller than the CLICK_TIMEOUT and the range isn't collapsed - we start polling it for up to 50ms. (to be extra cautious). So if the browser changes its state quicker - it won't be held off by a "blind" timeout.

const stopPollingInMs = 50;
setTimeout(() => stopPolling = true, stopPollingInMs);

return poll(() => isCollapsed = sel?.isCollapsed, pollingDelayMs, shouldStopPolling);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first call is immediate, which won't hold off desktop users, for which the isCollapsed: false is available immediately.
And for the rest of the cases, the polling will stop as soon as the range finally gets recognized as collapsed. However, to prevent endless polling and not make the experience sluggish, I limited it with 50ms. cap

@oleksandr-danylchenko oleksandr-danylchenko marked this pull request as draft October 29, 2024 15:05
@oleksandr-danylchenko

This comment was marked as resolved.

# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
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.

1 participant