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

change(web): initializes OSK with keyboard if available during init 🪠 #11174

Merged
merged 8 commits into from
Apr 19, 2024

Conversation

jahorton
Copy link
Contributor

@jahorton jahorton commented Apr 5, 2024

By delaying the end of KeymanWeb's init method in order to check if any keyboards are pre-registered, we can initialize the OSK correctly "the first time". This matters by far the most on touch devices, where we have been building a stand-in default touch-layout the first time first due to not waiting long enough for pre-registered keyboards to fully load. (On desktop devices, we just build a very simple, empty stand-in.) Preparing the stand-in is surprisingly expensive/slow on some older touch devices.

By preventing unnecessary construction of a stand-in touch layout (and thus, related DOM initialization + layout reflow) on touch devices when fully leveraged, we can eliminate a notable source of Web engine startup lag that has long been affecting our mobile apps.

I have verified that this allows us to fully bypass the empty touch-layout construction step within the Android Engine, notably cutting the host-page startup time. It currently appears that the iOS app is unable to leverage this as-is, though.

With a little rework of Web's test pages, it can be demonstrated to work for standalone KeymanWeb as well. Their current structures generally do not register keyboards until engine-initialization is complete, which is a necessary prerequisite.

User Testing

TEST_WINDOWS_DESKTOP: Test general use of KeymanWeb on a Windows desktop or laptop. Report any unexpected behavior.

  • Refresh the page and start using KeymanWeb least 5 times. (Test page: "Test unminified Web")

TEST_ANDROID_TABLET: Test general use of KeymanWeb on an Android tablet. Report any unexpected behavior.

  • Force-quit and restart the app at least 5 times.
  • Swap in and out of the system keyboard at least 5 times.

TEST_IOS_PHONE: Test general use of KeymanWeb on an iPhone. Report any unexpected behavior.

  • Force-quit and restart the app at least 5 times.
  • Swap in and out of the system keyboard at least 5 times.

@keymanapp-test-bot keymanapp-test-bot bot added the user-test-missing User tests have not yet been defined for the PR label Apr 5, 2024
@keymanapp-test-bot
Copy link

keymanapp-test-bot bot commented Apr 5, 2024

User Test Results

Test specification and instructions

  • TEST_WINDOWS_DESKTOP (PASSED): Tested using "Test unminified Web" page on a Windows desktop and here is my observation: 1. Refresh the test page. 2. Tested text selection and CJK keyboard functions on a Windows desktop. 3. Repeated Steps 1 and 2 more than 5 times and verified that everything works fine.
  • TEST_ANDROID_TABLET (PASSED): Retested with the attached PR build (Keyman 17.0.303-beta-test-11174) on an Android 12 / API 30 emulator and here is my observation: 1. Opened the Keyman In-app. 2. Force-quit and restarted the app more than five times, verifying that no issues occurred during this process. 3. Set Keyman as the System keyboard. 4. Opened Chrome browser. 5. Switched to Keyman Keyboard. 6. Swapped to Gboard using the globe key. Repeat step 5 and 6 for more than five times and verified that no problems occurred during the process.
  • TEST_IOS_PHONE (PASSED): Retested with the attached PR build (Keyman 17.0.303-beta-test-11174) on an iPhone 13 Mobile device (iOS 17.4) and here is my observation: 1. Opened the Keyman In-app. 2. Force-quit and restarted the app more than five times, verifying that no issues occurred during this process. 3. Set Keyman as the System keyboard. 4. Opened Safari browser. 5. Switched to Keyman Keyboard. 6. Swapped to default keyboard using the globe key. Repeat step 5 and 6 for more than five times and verified that no problems occurred during the process.

Test Artifacts

@keymanapp-test-bot keymanapp-test-bot bot added this to the B17S5 milestone Apr 5, 2024
@jahorton jahorton force-pushed the change/web/anti-layout-reflow-thrashing branch from da7ea66 to c595303 Compare April 5, 2024 06:04
jahorton added 2 commits April 5, 2024 13:07
This prevents unnecessary construction of a stand-in touch layout and related DOM initialization on touch devices when fully leveraged.
@jahorton jahorton force-pushed the change/web/init-osk-with-keyboard branch from 56f28bb to eebf3e5 Compare April 5, 2024 06:07
@keymanapp-test-bot keymanapp-test-bot bot added has-user-test user-test-required User tests have not been completed and removed user-test-missing User tests have not yet been defined for the PR labels Apr 5, 2024
@jahorton jahorton marked this pull request as ready for review April 8, 2024 01:30
@jahorton jahorton marked this pull request as draft April 8, 2024 01:46
@jahorton
Copy link
Contributor Author

jahorton commented Apr 8, 2024

Just noticed an issue with when the OSK is in desktop-keyboard mode; needs a bit more refinement first.

@jahorton jahorton marked this pull request as ready for review April 8, 2024 01:56
@bharanidharanj
Copy link

Test Results

  • TEST_WINDOWS_DESKTOP (PASSED): Tested using "Test unminified Web" page on a Windows desktop and here is my observation: 1. Refresh the test page. 2. Tested text selection and CJK keyboard functions on a Windows desktop. 3. Repeated Steps 1 and 2 more than 5 times and verified that everything works fine.

@bharanidharanj
Copy link

Test Results

  • TEST_ANDROID_TABLET (FAILED): Tested with the attached PR build (Keyman 17.0.303-beta-test-11174) on an Android 12 Tablet / API 30 emulator and here is my observation: 1. Force-quit and restart the app for 5 times. 2. Swapped in and out of the system keyboard at least 5 times and noticed that the Keyman Keyboard banner appears instead of the predictive text after keyboard swapping. Seems to be an issue.

@bharanidharanj
Copy link

Test Results

  • TEST_IOS_PHONE (FAILED): Tested with the attached PR build (Keyman 17.0.303-beta-test-11174) on an iPhone 13 mobile device and here is my observation: 1. Noticed that a blank keyboard appeared on the screen after opening the keyman In-App. Seems to be an issue.

@keymanapp-test-bot keymanapp-test-bot bot removed the user-test-required User tests have not been completed label Apr 8, 2024
Copy link

sentry-io bot commented Apr 9, 2024

Sentry Issue: KEYMAN-WEB-JH

From the iOS user-test failure

@jahorton
Copy link
Contributor Author

@keymanapp-test-bot retest TEST_IOS_PHONE TEST_ANDROID_TABLET

I've added code that should ensure the banner displays consistently now; the OSK now proactively checks what mode the banner should be in when it's initialized. (Previously, it always waited to be told.)

@keymanapp-test-bot keymanapp-test-bot bot added user-test-required User tests have not been completed and removed user-test-failed labels Apr 10, 2024
@bharanidharanj
Copy link

Test Results

  • TEST_ANDROID_TABLET (PASSED): Retested with the attached PR build (Keyman 17.0.303-beta-test-11174) on an Android 12 / API 30 emulator and here is my observation: 1. Opened the Keyman In-app. 2. Force-quit and restarted the app more than five times, verifying that no issues occurred during this process. 3. Set Keyman as the System keyboard. 4. Opened Chrome browser. 5. Switched to Keyman Keyboard. 6. Swapped to Gboard using the globe key. Repeat step 5 and 6 for more than five times and verified that no problems occurred during the process.

@bharanidharanj
Copy link

Test Results

  • TEST_IOS_PHONE (PASSED): Retested with the attached PR build (Keyman 17.0.303-beta-test-11174) on an iPhone 13 Mobile device (iOS 17.4) and here is my observation: 1. Opened the Keyman In-app. 2. Force-quit and restarted the app more than five times, verifying that no issues occurred during this process. 3. Set Keyman as the System keyboard. 4. Opened Safari browser. 5. Switched to Keyman Keyboard. 6. Swapped to default keyboard using the globe key. Repeat step 5 and 6 for more than five times and verified that no problems occurred during the process.

@keymanapp-test-bot keymanapp-test-bot bot removed the user-test-required User tests have not been completed label Apr 10, 2024
Base automatically changed from change/web/anti-layout-reflow-thrashing to beta April 12, 2024 00:49
@darcywong00 darcywong00 modified the milestones: B17S5, B17S6 Apr 12, 2024
Comment on lines 39 to 41
try {
KeymanWeb.registerStub(JSON.parse(jsInterface.initialKeyboard()));
} catch {};
Copy link
Member

Choose a reason for hiding this comment

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

We should not be silently throwing away exceptions. If there is a specific exception that we need to handle and ignore, then that needs to be documented -- at the very least with a comment. But better to avoid the exception altogether if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this is location that, if an error triggers, is guaranteed to cause a blank keyboard. It's before the keyman.init call.

Here's a Sentry event this is meant to silence: https://keyman.sentry.io/share/issue/d9d9bd46c7404254891b606b87570bec/

I'm... not sure how that error looks on the JS side. I can attempt to reproduce it and see if there's a simple-enough way to filter it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inspecting that Sentry event, though... it hasn't really shown up in several builds, so perhaps it is safe to drop. (Last case was from 17.0.293-beta.)

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps the best solution for now is log all exceptions to sentry, and then we can filter out known 'good' exceptions as we encounter them. So we should never have an empty catch {} -- it should at the very least have a tellSentryAboutMyPain() even if we then want to continue on as 'normal'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went ahead and dropped the try-catch entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

... and restored, now with a console.error(<error>) in it.

@jahorton jahorton merged commit 09a65a4 into beta Apr 19, 2024
19 checks passed
@jahorton jahorton deleted the change/web/init-osk-with-keyboard branch April 19, 2024 05:41
@keyman-server
Copy link
Collaborator

Changes in this pull request will be available for download in Keyman version 17.0.311-beta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants