Page MenuHomePhabricator

Don’t polyfill Promise in Bridge modules
Closed, InvalidPublic


It looks like as part of T237688, MediaWiki will soon include a Promise polyfill (Ib0ffb5d982); once that happens, we can stop polyfilling it within Bridge’s dist and app modules.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

The MediaWiki Promise polyfill was merged, so this should be actionable now.

Edit: The polyfill is available as a ResourceLoader module, but not yet loaded by default (Ib0ffb5d982). If we want to make use of it before that change is merged, we should declare an explicit dependency on the polyfill module in Resources.php.

See also this AC/DC commit, where I excluded the Promise polyfill in a plain webpack project. Hopefully it’s not a lot more complicated in conjunction with vue-cli-service.

@Lucas_Werkmeister_WMDE and I looked into this today and encountered some problems with getting this to work. While it is correct that the promise polyfill is included by default (vuejs/vue-cli#1248, vuejs/vue-cli#5208), it should be possible to change that with the following as babel.config.js (possible trimming polyfills if those default polyfills are not needed):

module.exports = {
	presets: [
		[ '@vue/cli-plugin-babel/preset', {
			exclude: [
				'es.promise', // polyfilled via es6-promise ResourceLoader module instead
			polyfills: [ 'es.array.iterator', 'es.object.assign' ],
		} ],

However, that currently doesn't prevent the es.promise polyfill from being included.

The cause is to be found in @vue/babel-preset-app which is included by our @vue/cli-plugin-babel/preset.
This handles the exclude parameter correctly through most of the file, but at the end it requires @babel/preset-env again, but without including the preset options that were carefully constructed through that file. The cause for this seems to have been a bug in babel itself for which adding that extra transpilation seems to be the recommended workaround. It is unclear whether that necessitates the inclusion of the promise polyfill. An upstream pull request to use the envOptions also for that transpilation was created by @Lucas_Werkmeister_WMDE . Further it seems that the original babel bug was resolved and the respective file in vue-cli is actively being worked on.

So there is some hope that this improvement can be implemented soon™.

(@Lucas_Werkmeister_WMDE feel free to correct me if my summary above can be improved)

Change 598683 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/Wikibase@master] WIP: bridge: don’t polyfill Promise

Thanks Michael, that all sounds right to me. I uploaded the partial patch above, though without the upstream change it doesn’t reduce the dist/ size at all.

Lucas_Werkmeister_WMDE changed the task status from Open to Stalled.May 26 2020, 9:15 AM
Lucas_Werkmeister_WMDE moved this task from To do to Doing on the Bridge Technical Improvements board.

(The current status of this is that the vue-cli pull request was merged and we’re waiting on a new upstream release; once that’s there, we can upgrade to the new version, and then the “don’t polyfill Promise” change should actually remove Promise from the bundle.)

vue-cli v4.4.3 was released, so this should be possible now.

Change 605202 had a related patch set uploaded (by Lucas Werkmeister (WMDE); owner: Lucas Werkmeister (WMDE)):
[mediawiki/extensions/Wikibase@master] WIP: bridge: upgrade to vue-cli 4.4.3

Would be great to give this another boost (both for bridge as well as as a standard for all products matching our pattern vue+TypeScript+MediaWiki). => Prioritization Session

Krinkle added a subscriber: Krinkle.

I believe this is unblocked with es6-promise shipping in core. Is that right?

I don’t think it’s ever been blocked on core’s es6-promise, we just haven’t figured out how to make this work with the Bridge build process yet, as far as I’m aware.

Realistically, this is probably something that will be picked up when a feature team focuses on bridge again. Not sure when that is planned to happen. It is on our general tech-maintenance priority list, but rather on the lower end.

Addshore removed a project: Wikidata-Campsite.
Addshore added a subscriber: Addshore.

Prioritized very low, so removing from Wikidata-Campsite

Change 605202 abandoned by Michael Große:

[mediawiki/extensions/Wikibase@master] WIP: bridge: upgrade to vue-cli 4.4.4


Obsolete with migration to vue 3 and vue-cli 5

Change 598683 abandoned by Michael Große:

[mediawiki/extensions/Wikibase@master] WIP: bridge: don\u2019t polyfill Promise


Obsolete with migration to vue 3 and vue-cli 5

This became obsolete with migration to vue 3 - we're no longer supporting browsers that do not know Promise.