fix(input-emulation): prevent char duping race condition (@HenryHYeary) - #8387
Open
HenryHYeary wants to merge 1 commit into
Open
fix(input-emulation): prevent char duping race condition (@HenryHYeary)#8387HenryHYeary wants to merge 1 commit into
HenryHYeary wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Changes
I moved
event.preventDefault()in the keydown handler to before the asynchronous call togetCharFromEventwhere the previous placement of the preventDefault call (after the asynchronous call) was causing a race condition which meant it could lose the race against the browser's native default action. If the browser inserted the native character before preventDefault() ran, both the native character and the emulated character would get inserted, producing a duplicate.I was able to reproduce the bug after adding a 50ms setTimeout delay
right after
layout = await __nonReactive.getInputLayout();. I usedawait new Promise(r => setTimeout(r, 50));.I also refactored the
keyEventCodesreassignments in layout-emulator.ts toANSI_KEYCODES,ISO_KEYCODES, andMATRIX_KEYCODES. I then used these constants in a set to specify all of the emulated key codes, so that a newmayEmulateCharcheck function in layout-emulator could do quick lookups on which keys it would be necessary to emulate. Without this check, preventDefault() would need to run unconditionally for every key while a custom layout is active, which breaks Backspace, Tab, Enter, and other keys the emulator doesn't handle.Notably a key in mayEmulateChar's set could still resolve to null if a layout's keyVariants data is incomplete, but I believe it's the responsibility of the layout creator to ensure the keyVariants data is complete rather than relying on fallbacks.
Checks
packages/schemas/src/languages.tsfrontend/src/ts/constants/languages.tsfrontend/static/languagespackages/schemas/src/themes.tsfrontend/src/ts/constants/themes.tsfrontend/static/themespackages/schemas/src/layouts.tsfrontend/static/layoutsfrontend/static/webfontspackages/schemas/src/fonts.tsfrontend/src/ts/constants/fonts.tsCloses #8383