Page MenuHomePhabricator

Do we still need to check if requestAnimationFrame is available?
Closed, ResolvedPublic

Description

Looking through the browser support matrix[1] and the caniuse report for whether requestAnimationFrame is available[2], it looks like all supported browsers have requestAnimationFrame. But as was pointed out to me recently, caniuse doesn't always reflect the reality for all page views.

If we can assume its always available, we can drop checks from mw.loader startup code (the fallback there is what prompted me to investigate) as well as a bunch of other places in core and deployed extensions. I'll file tasks to remove elsewhere if this gets approved.

So, can we assume its always available?

[1] https://www.mediawiki.org/wiki/Compatibility#Browser_support_matrix
[2] https://caniuse.com/mdn-api_window_requestanimationframe

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Krinkle moved this task from Inbox to Backlog on the MediaWiki-ResourceLoader board.
Krinkle subscribed.

requestAnimationFrame was introduced in the HTML spec much after the HTML 5 and HTML 5.1 specs, so our current checks do not cover it. I would expect certain headless browsers with a new JavaScript/ES6-capable engine, and some kind of DOM library to not implement this for example. That means we don't currently ensuring its presence, and we generally consider it worthwhile to make the startup phase as robust as possible, so that after that phase we can reliably and comfortably engage with the Basic foundation and the optional Modern layer atop.

I don't think we need to support the fallback for those theoretical cases, so perhaps we just need to update the feature test to look for a newer HTML APIs than this. Right now we poll the HTML API through support of the localStorage key. Perhaps requestAnimationFrame itself would make a good candidate.

See T141344 for an example of a feature-test campaign, through which we will observe and validate our hypothesis. The hypothesis could be that no known browsers would pass our current check without also passing this new check. We can then look at the data we find, which browsers they are from, and decide what to do based on that. If we find notable Grade X browsers that we'd like to provide the Modern layer to still, then we could continue to have a fallback. If we find that they would be better served with the Basic layer only, then we'd update the feature-test.

In any event, it would possibly be a better use of time to do this after T178356, which will naturally eliminate a large group of edge cases.

Krinkle raised the priority of this task from Low to Medium.Sep 26 2021, 9:37 PM
Krinkle moved this task from Backlog to Accepted Enhancement on the MediaWiki-ResourceLoader board.

Okay, will work in this after we begin requiring ES6

Krinkle changed the task status from Open to Stalled.Oct 23 2021, 3:11 AM

If we can assume its always available, we can drop checks from mw.loader startup code (the fallback there is what prompted me to investigate)

I can't see any checks for requestAnimationFrame in startup, even at the time this task was filed. There are some fallbacks in other places (e.g. in mw.loader.js).

I agree that it is probably now safe to drop these.

There is not a direct relation between the language runtime (e.g. V8, SpiderMonkey, JSC) or specification (ECMAScript), and the browser engine (Firefox, Chromium, WebKit). That is to say, requestAnimationFrame is not an ES5 or ES6 feature. It's an HTML feature (MDN, spec).

But, with the cut to ES6 in T178356, we have indeed jumped past the point where all Grade A browser versions (i.e. modern browsers we support) also implement this HTML API, as shown by CanIUse and MDN browser compat data.

I believe this is also validated by the eslint-plugin-compat which includes this dataset and is configured in our ESLint preset with our browser support matrix. So this and any other Web APIs (e.g. DOM, HTML, Paint Timing, IntersectionObserver, etc) can be unconditionally used if the browser compat data indicates as much (ideally detected by ESLint).

Change 947889 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] resources: Remove fallback for window.requestAnimationFrame

https://gerrit.wikimedia.org/r/947889

Change 947889 merged by jenkins-bot:

[mediawiki/core@master] resources: Remove fallback for window.requestAnimationFrame

https://gerrit.wikimedia.org/r/947889

Change 998420 had a related patch set uploaded (by Fomafix; author: Fomafix):

[mediawiki/extensions/Kartographer@master] Remove fallback for window.requestAnimationFrame

https://gerrit.wikimedia.org/r/998420

Change 998420 merged by jenkins-bot:

[mediawiki/extensions/Kartographer@master] Remove fallback for window.requestAnimationFrame

https://gerrit.wikimedia.org/r/998420

Change #1027252 had a related patch set uploaded (by Fomafix; author: Fomafix):

[mediawiki/skins/Metrolook@master] Remove fallback for window.requestAnimationFrame

https://gerrit.wikimedia.org/r/1027252

Change #1027252 merged by jenkins-bot:

[mediawiki/skins/Metrolook@master] Remove fallback for window.requestAnimationFrame

https://gerrit.wikimedia.org/r/1027252