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

fix: delays kmw-dependent code 'til full page load #28

Merged
merged 1 commit into from
Mar 15, 2021

Conversation

jahorton
Copy link
Contributor

@jahorton jahorton commented Mar 11, 2021

Fixes #26.
Mitigates (and may fix) #27.

Moves all KMW-dependent code (including the 'kmw-disabled' removal bit that fixes #26) until the window has fully loaded, meaning that all script resources (like KMW) have loaded. The old placement of the code could trigger at the 'interactive' state, and before KMW's script loaded at that... which would naturally cause null reference errors.

Note that the clipboard may not work on old iOS devices, but that limitation is due to Safari's support for the underlying command - it's only supported at and after iOS 10. Unfortunately, the mobile layout gives no indication of failure due to use of an older iOS version.

There are a few additional spots in code that may allow #27 to continue occurring; additional work is suggested in these regards. This PR should still mitigate things, though, and releasing the current fixes should help evaluate the scale needed for any remaining work in that direction.

@jahorton jahorton added the bug Something isn't working label Mar 11, 2021
@jahorton jahorton added this to the B14S8 milestone Mar 11, 2021
Comment on lines +244 to +245
// Promises only started being supported in KMW 13 (keymanapp/keyman#1432), but this site supports
// earlier versions, too, so we can't rely on their presence.
Copy link
Member

Choose a reason for hiding this comment

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

Happy for this site to support 13.0+ at this point if that makes things more elegant?

Comment on lines +248 to +255
setTimeout(function(){
if (!!$('.messageBox').length) {
getKeymanWeb().moveToElement('message');
}
// On touch devices, this is necessary (but not sufficient) for ClipboardJS compatibility.
// Must take affect AFTER KMW has initialized.
$('#message').removeAttr('disabled');
},1000);
Copy link
Member

Choose a reason for hiding this comment

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

Is setTimeout really needed here now? Would be awesome if we could eliminate 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.

It would be. That's the part that needs KMW 13.0.

If KMW's script is the last thing to load on the page, keyman.init may not have been called, meaning the touch-aliases won't have been built yet. If we could wait on init's Promise, we could eliminate this timeout in favor of that.

Assuming that making an init call here is safe, granted: this function doesn't know whatever options the site may be setting elsewhere for its init.

Copy link
Member

Choose a reason for hiding this comment

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

So... if we make this 13.0+ then we can eliminate the timeout? Sounds good to me.

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've gone ahead and made this into #29. That way, we get the current batch of work out, and just in case there is any issue with use of init-promises, we can more easily revert just that part.

@jahorton jahorton merged commit 521e457 into master Mar 15, 2021
@jahorton jahorton deleted the fix/delayed-kmw-load-null-ref branch March 15, 2021 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Mobile use currently incompatible with ClipboardJS
2 participants