-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Framework: Use babel-polyfill in place of runtime builtins #9643
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change for this package, should we update the changelog accordingly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do some cleanup to the get-babel-config.js file and remove the override of useBuiltIns: false,
|
Nice work, I can't test and approve at the moment. It will be the first thing I'll do in the morning unless someone beats me to it. |
|
5 unit tests failed, investigating. |
|
I included a small CSS tweak to fix the block toolbars in 43cde18 (display flex elements in IE need flex-shrink: 0) if they are inside other flex elements :) I didn't do a separate PR because people won't be able to test otherwise. |
43cde18 to
06a2231
Compare
|
Hey hey looks like the tests pass now 🎉 |
lib/client-assets.php
Outdated
| ); | ||
| wp_add_inline_script( | ||
| 'wp-polyfill-fetch', | ||
| 'wp.deprecated( "wp-polyfill-fetch script handle", { plugin: "Gutenberg", version: "4.0" } );' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean that wp-polyfill-ecmascript contains also polyfill for fetch?
I can see some code for Promise in https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.0.0/polyfill.js, but can't see anything related to fetch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it relies on core-js I don't think it's included https://github.com/zloirock/core-js#missing-polyfills
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, occurred to me as well the polyfill is only going to provide language features (the specification). Since fetch is a browser standard, it needs to remain polyfilled. I'll add back.
| useBuiltIns: 'usage', | ||
| } ], | ||
| isTestEnv && [ '@babel/preset-env', { | ||
| useBuiltIns: 'usage', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to revert the change which removes:
useBuiltIns: 'usage',
from test environment because some tests were failing. Those which use Array.values method which isn't supported by Node.
@youknowriad suggested using babel-polyfill instead to have the setup closer to the browser but I found out that it can cause memory issues with Jest. See jestjs/jest#2755 and the line in the changelog:
Breaking Change: Replaced auto-loading of babel-polyfill with only regenerator-runtime, fixes a major memory leak.
|
|
||
| const output = transform( input, { | ||
| configFile: false, | ||
| envName: 'production', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change, we test again production configuration rather than test env ... It is more helpful now :)
|
We still need to test it against IE11, @jorgefilipecosta or @tofumatt can you help to ensure it works consistently? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not part of ECMAScript standard, so not provided through Babel polyfill
youknowriad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Tested in IE and chrome. Works great.
|
I didn't re-test in IE but if @youknowriad says it works in IE11 that's good enough for me; dismissing my review 😄 |

Fixes #9640
Related: #9275
Alternative to: #9641
This pull request seeks to disable our use of the
@babel/runtimeuseBuiltInsoption, replaced instead by@babel/polyfillas a dependency of every script registered by Gutenberg. This could be further enhanced to conditionally load the script only for browsers where expected features are not supported, but at this time it is not evident how such a condition would be formed.While this technically adds a new script to be loaded, there is a net decrease in bundle size, from 2011.96kb total to 1803.72kb (+89.6kb polyfill) (minified, pre-gzip), for an overall savings of 118.64kb. Full build comparison below:
Before
./build/blocks/index.js 219 KiB 23 [emitted] blocks ./build/wordcount/index.js 10 KiB 0 [emitted] wordcount ./build/url/index.js 8.9 KiB 2 [emitted] url ./build/token-list/index.js 13 KiB 3 [emitted] tokenList ./build/shortcode/index.js 16.2 KiB 4 [emitted] shortcode ./build/redux-routine/index.js 18.6 KiB 5 [emitted] reduxRoutine ./build/plugins/index.js 13.3 KiB 6 [emitted] plugins ./build/nux/index.js 16.6 KiB 7 [emitted] nux ./build/keycodes/index.js 3.64 KiB 8 [emitted] keycodes ./build/is-shallow-equal/index.js 1.15 KiB 9 [emitted] isShallowEqual ./build/i18n/index.js 27.7 KiB 10 [emitted] i18n ./build/html-entities/index.js 986 bytes 11 [emitted] htmlEntities ./build/hooks/index.js 19.3 KiB 12 [emitted] hooks ./build/element/index.js 34.3 KiB 13 [emitted] element ./build/editor/index.js 371 KiB 14 [emitted] [big] editor ./build/dom-ready/index.js 778 bytes 15 [emitted] domReady ./build/dom/index.js 15.4 KiB 16 [emitted] dom ./build/deprecated/index.js 10.9 KiB 17 [emitted] deprecated ./build/date/index.js 196 KiB 18 [emitted] date ./build/data/index.js 52.1 KiB 19 [emitted] data ./build/core-data/index.js 57.8 KiB 20 [emitted] coreData ./build/compose/index.js 18 KiB 21 [emitted] compose ./build/block-serialization-spec-parser/index.js 9.48 KiB 22 [emitted] blockSerializationSpecParser ./build/viewport/index.js 13.3 KiB 1 [emitted] viewport ./build/blob/index.js 909 bytes 24 [emitted] blob ./build/autop/index.js 24.7 KiB 25 [emitted] autop ./build/api-fetch/index.js 35.2 KiB 26 [emitted] apiFetch ./build/a11y/index.js 5.32 KiB 27 [emitted] a11y ./build/block-library/index.js 217 KiB 28 [emitted] blockLibrary ./build/edit-post/index.js 87.4 KiB 29 [emitted] editPost ./build/components/index.js 494 KiB 30 [emitted] [big] componentsAfter
./build/blocks/index.js 191 KiB 23 [emitted] blocks ./build/wordcount/index.js 2.53 KiB 0 [emitted] wordcount ./build/url/index.js 8.9 KiB 2 [emitted] url ./build/token-list/index.js 2.39 KiB 3 [emitted] tokenList ./build/shortcode/index.js 8.89 KiB 4 [emitted] shortcode ./build/redux-routine/index.js 18.6 KiB 5 [emitted] reduxRoutine ./build/plugins/index.js 11.7 KiB 6 [emitted] plugins ./build/nux/index.js 16.6 KiB 7 [emitted] nux ./build/keycodes/index.js 3.64 KiB 8 [emitted] keycodes ./build/is-shallow-equal/index.js 1.15 KiB 9 [emitted] isShallowEqual ./build/i18n/index.js 24.6 KiB 10 [emitted] i18n ./build/html-entities/index.js 986 bytes 11 [emitted] htmlEntities ./build/hooks/index.js 10.2 KiB 12 [emitted] hooks ./build/element/index.js 24.3 KiB 13 [emitted] element ./build/editor/index.js 354 KiB 14 [emitted] [big] editor ./build/dom-ready/index.js 778 bytes 15 [emitted] domReady ./build/dom/index.js 11.4 KiB 16 [emitted] dom ./build/deprecated/index.js 7.02 KiB 17 [emitted] deprecated ./build/date/index.js 191 KiB 18 [emitted] date ./build/data/index.js 43.3 KiB 19 [emitted] data ./build/core-data/index.js 48.9 KiB 20 [emitted] coreData ./build/compose/index.js 8.28 KiB 21 [emitted] compose ./build/block-serialization-spec-parser/index.js 9.48 KiB 22 [emitted] blockSerializationSpecParser ./build/viewport/index.js 2.77 KiB 1 [emitted] viewport ./build/blob/index.js 909 bytes 24 [emitted] blob ./build/autop/index.js 11.8 KiB 25 [emitted] autop ./build/api-fetch/index.js 28.9 KiB 26 [emitted] apiFetch ./build/a11y/index.js 1.8 KiB 27 [emitted] a11y ./build/block-library/index.js 202 KiB 28 [emitted] blockLibrary ./build/edit-post/index.js 77.9 KiB 29 [emitted] editPost ./build/components/index.js 478 KiB 30 [emitted] [big] componentsTesting instructions:
Repeat Steps to Reproduce from #9640, verifying both in Internet Explorer and in your preferred browser that there are no issues loading or using the editor.