Skip to content

Microtasks using MutationObserver scheduler may not run due to page scrolling (iOS 9, WebApp/UIWebView) #2089

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

Open
residualeffect opened this issue Jul 1, 2016 · 1 comment
Milestone

Comments

@residualeffect
Copy link

When using Knockout 3.4.0 in an iOS 9 embedded UIWebView (or from a "iOS Web App" that has been pinned to the home screen from Safari), there seems to be an issue that causes Kncokout microtasks to stop running. This then causes other problems in Knockout - for example, components on the page will no longer update as expected. The issue doesn't seem to happen in the full mobile Safari browser.

The problems start when a microtask is scheduled to run while the page is scrolling.

I've put together an example HTML file that can be used to reproduce the issue when loaded on an iPhone as a pinned "iOS Web App": https://gist.github.com/joshbarger/a8c60ce3ea1245b48af41ad5c515e302

  1. Load the HTML from the gist in the full mobile Safari browser, tap the share button at the bottom, and then "Add to home screen".
  2. Open the page from the new home screen icon rather than in full mobile Safari, and then tap the button a few times. You should see sequential numbers appear on the page below the button.
  3. Pull the page down from the top, let go, and then while the button is scrolling back up to the top, tap the button again. Note that this tap won't generate a number.
  4. Also note that additional taps on the button (even after scrolling has stopped) still won't trigger a number to show up. The microtasks seem to queue up, but don't run anymore.

I also found that the Bluebird project (where some of the microtask code originally came from) had this same problem. For reference, here is the discussion and how the issue was fixed in that project: petkaantonov/bluebird#666

@mbest
Copy link
Member

mbest commented Jul 7, 2016

It looks like the solution they put into Bluebird is to check window.navigator.standalone and then use setImmediate or setTimeout. Thus a Knockout application could apply the same logic as a workaround:

if (window.navigator.standalone) {
    ko.tasks.scheduler = setTimeout;
}

brianmhunt added a commit to knockout/tko.utils that referenced this issue Jul 8, 2016
@mbest mbest modified the milestone: Not assigned Dec 2, 2016
brianmhunt added a commit to knockout/tko that referenced this issue May 8, 2017
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

No branches or pull requests

2 participants