Skip to content

Conversation

@pan-kot
Copy link
Member

@pan-kot pan-kot commented Aug 26, 2025

Description

We have two drastically different types of d&d transition: pointer-based and keyboard-based. Due to async nature of events, there was a bug where the pointer-based transition crashed when user pressed Escape. It happened because:

  1. User starts pointer-based d&d transition (moves or resizes an item, but w/o commit);
  2. User presses Escape (or Space, Enter) - the keyboard handler submits/discards the transition;
  3. User moves cursor a little - the onPointerMove handler is still there, it attempts to update the transition that no longer exists, which leads to a crash.

Besides, pressing arrow keys while the pointer-based transition was in progress led to unexpected results, too. The solution is to disallow keyboard input while pointer-based d&d is engaged by immediately cancelling the transition in this case.

I additionally refactored the code a little so that the global handlers are injected in a better predictable manner, so instead of relying on whether the handlers are present - we rely on a ref that tells us whether a transition is engaged.

Rel: AWSUI-61155, similar to: #367

The change also fixes AWSUI-61157. Before, when the right-click (reproducible with a mouse, but not with trackpad) was made during a pointer-based d&d operation, the transition was stuck because the related pointer-up was removed. This is no longer the case.

Before:

Screen.Recording.2025-08-26.at.13.57.00.mov

After:

Screen.Recording.2025-08-26.at.13.57.40.mov

How has this been tested?

  • Added new functional test as a regression
Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov
Copy link

codecov bot commented Aug 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.39%. Comparing base (5ba94ef) to head (25497ab).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #368      +/-   ##
==========================================
+ Coverage   94.97%   95.39%   +0.42%     
==========================================
  Files          67       67              
  Lines        3263     3282      +19     
  Branches      699      707       +8     
==========================================
+ Hits         3099     3131      +32     
+ Misses        164      151      -13     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pan-kot pan-kot requested a review from johannes-weber August 26, 2025 11:38
@pan-kot pan-kot marked this pull request as ready for review August 26, 2025 11:38
@pan-kot pan-kot requested a review from a team as a code owner August 26, 2025 11:38
@pan-kot
Copy link
Member Author

pan-kot commented Aug 26, 2025

@johannes-weber I also tested the board manually by mixing different d&d interactions, including pointer-based, UAP-based, keyboard-based. That is to ensure it is not possible to disengage the global listeners w/o submitting or cancelling the respective transition. If that is the case - the moved/resized item will be stuck in mid-air, unable to commit. Please do a round of manual testing too, just to be sure.

// isn't set in stone.
export const CLICK_DRAG_THRESHOLD = 3;

// We use singleton helper to avoid creating event listeners per each board item.
Copy link
Member

Choose a reason for hiding this comment

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

Great improvement! It did not make sense having the global event listeners attached on every board item!

@johannes-weber
Copy link
Member

I did manual testing and was not able to crash it with a mix of D&D and keyboard interactions. Tested with a trackpad, I don't have a external mouse available.
LGTM!

johannes-weber
johannes-weber previously approved these changes Aug 26, 2025
@pan-kot pan-kot added this pull request to the merge queue Aug 26, 2025
Merged via the queue into main with commit 95e6e11 Aug 26, 2025
38 of 39 checks passed
@pan-kot pan-kot deleted the fix-pointer-dnd-abort-on-keydown branch August 26, 2025 14:37
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