fix(web): infinite model-match replacement looping ðŸª
Addresses part of #10592.
Continues from #10836.
While investigating #10592, I discovered that during rapid-typing scenarios, there's often an asynchronously-infinite loop running within the gesture-engine whenever a simple-tap is autocompleted by a new incoming tap! (To be clear - this is neither intended nor desired.) This was occurring because we weren't checking the component paths' initial states during the replacement process - only the validity of the initial item(s). (Model replacement shouldn't proceed if the replacing model would instantly reject - for any cause.)
To be more detailed: in particular, the 'longpress' and 'longpress-roam' gesture models used by KeymanWeb are rejected when a new touch comes in... and it's not resulting in their permanent cancellation (which is what the design would intend). Instead, they're instantly rejecting/resetting again, constantly - each pass is one iteration of the aforementioned 'loop'. This unintended 'loop' auto-terminates whenever a gesture is positively matched or when none are able to match.
On one hand, this is why the oversight fixed by #10836 wasn't an issue before - it so happens that this loop 'sustains' the selection process and prevents early interruption of the model-matching process. On the other hand... a side-effect of the same loop caused a O(N) process per loop iteration, with N as the number of prior iterations - resulting in an O(N^2) effect on something that should be O(0). That's a really, really bad look. The resulting good news: this fix should improve the gesture engine's performance during rapid touch scenarios, helping to mitigate #10592 (and #10646). There are still other co-morbid issues that also need addressing, though.
If this PR is placed before #10836 in commit history, one unit test will fail. The failure would be due to removing the "sustaining" effect mentioned in the second paragraph.
@keymanapp-test-bot skip
As this PR seeks to address a host of related known errors but only fixes a bit of them, specifying a proper user test at this point would be quite tricky. #10843 will host the main user testing suite for this PR chain, as it exists as the final "rung" of this PR "ladder."
User Test Results
Test specification and instructions
User tests are not required
Test Artifacts
- Android
- Developer
-
iOS
- Keyman for iOS (simulator image)
- FirstVoices Keyboards for iOS (simulator image)
-
TestFlight internal PR build version -
17.0.296 (0.10838.10625)
- Keyboards
- Web
- Windows
Aside from heavily reworking the comments, I made a few extra changes; a 'cancelled' rejection-action was technically allowed on GestureModels, which it shouldn't be, and the changes correct that.
Changes in this pull request will be available for download in Keyman version 17.0.301-beta