#60962 closed enhancement (fixed)
Remove now unnecessary polyfill dependencies
Reported by: | swissspidy | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 6.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Script Loader | Keywords: | has-patch commit has-dev-note |
Focuses: | performance | Cc: |
Description
In [43903], wp-polyfill
was added as a direct dependency of the react
asset.
This brought over this Gutenberg PR into core ahead of the 5.0 release.
Apparently, the reason for this was IE 11. React 16 used to require a few runtime JS features that were missing in IE11 and thus needed to be polyfilled. So when using the externalized React version provided by WordPress, it was important for wp-polyfill
to be loaded before React.
However, times have changed.
WordPress core dropped IE 11 support in 2021.
React has since been updated to version 18.
Developers using @wordpress/scripts
to build their assets need to manually include the `wp-polyfill` dependency if they need polyfills.
Yet, if a plugin loads React for something — for example on the frontend — the wp-polyfill
script is still unnecessarily enqueued.
At least the wp-polyfill.min.js
size decreased from 115 KB in WP 6.4 to 39 KB in WP 6.5. But that is still 39 KB of unnecessary JavaScript that is loaded for these cases.
I therefore propose removing the wp-polyfill
dependency from react
. Ideally this accompanied by a dev-note.
Attachments (2)
Change History (28)
#2
@
5 months ago
Yes, we shouldn't need it anymore. In the editor, we will have the polyfill coming from other packages anyway, but I think React doesn't need it these days.
#3
@
5 months ago
- Milestone changed from Future Release to 6.6
Similarly, is wp-polyfill-inert
still needed? It was added in #57492
Looking at https://caniuse.com/mdn-html_global_attributes_inert and our browserslist config, all browsers seem to support it.
So maybe something we can drop too?
This ticket was mentioned in PR #6372 on WordPress/wordpress-develop by @swissspidy.
5 months ago
#4
- Keywords has-patch added; needs-patch removed
To-do:
- [ ] Maybe remove
wp-polyfill-inert
too
Trac ticket: https://core.trac.wordpress.org/ticket/60962
#5
@
5 months ago
Indeed, we can remove "inert" but I wonder if we should keep the an empty script handle around for third-parties.
#6
@
5 months ago
Indeed, we can remove "inert" but I wonder if we should keep the an empty script handle around for third-parties.
I think for now we can probably simply not make it a dependency of wp-polyfill
anymore, so that it doesn't get automatically loaded for everyone using wp-polyfill
.
Related to that, does regenerator-runtime
need to be loaded all the time as well? Can this be loaded on demand instead by projects explicitly enqueuing it if they need it?
This ticket was mentioned in Slack in #core-performance by adamsilverstein. View the logs.
5 months ago
#9
@
5 months ago
Related to that, does regenerator-runtime need to be loaded all the time as well? Can this be loaded on demand instead by projects explicitly enqueuing it if they need it?
I think regenerator-runtime is there to ensure generator support but generators are now supported by all the browsers that we support, so I think it's probably not needed anymore https://caniuse.com/?search=generators
We need to check in the "built files" if generators are kept as they are (because there could be some option to enable/disable in babel)
#10
@
5 months ago
@youknowriad How can this be checked? I'm assuming this applies only to Gutenberg packages with @babel/runtime
as a dependency?
#11
@
5 months ago
@swissspidy So I just checked using a generator in some random Gutenberg script and this is the output that I've got
function* myGenerator() { yield 1; yield 2; yield 3; } window.myGenerator = myGenerator();
It seems the output kept the generator as is, so I'd say that it's probably fine to remove the regenerator-runtime dependency at this point from all of our scripts.
#12
@
5 months ago
- Keywords commit added
- Owner set to swissspidy
- Status changed from new to accepted
- Summary changed from Remove `wp-polyfill` dependency from `react` to Remove now unnecessary polyfill dependencies
@swissspidy commented on PR #6372:
5 months ago
#14
Committed in https://core.trac.wordpress.org/changeset/57981
@swissspidy commented on PR #6372:
5 months ago
#15
Committed in https://core.trac.wordpress.org/changeset/57981
#17
@
5 months ago
I've been thinking a bit more here. It is possible that some plugins are declaring wp-polyfill
as a dependency but are still compiling generators to use the generator runtime. It would be a small breaking change for these plugins.
To be honest, I have no idea if there are such plugins and their numbers, but thought I'd mention.
We could advise them to:
- Update their build tools to not transpile generators.
- Add
regenerator-runtime
dependency explicitly.
I'd probably recommend handling that in the dev note for now (and keep an eye on feedback).
#18
@
5 months ago
Dropping a quick note here in case it's useful.
The following error was reported to the Sensei product team. It appears on any Sensei course page on the learn.wordpress.org
site:
The source code is here.
I'll take a closer look at the proposed solution to try to resolve.
#19
@
5 months ago
Any thoughts on that @swissspidy is it severe enough that we should restore the regenerator-runtime (and find some ways to deprecate it) or should we address this more in terms of communication / dev note?
#20
@
5 months ago
Unless there are more severe reports I still think a dev-note suffices.
I'd say nowadays the majority of WordPress developers use wp-scripts, where this is not an issue.
From what I can see, Sensei uses some Calypso-specific build tooling, so this should be resolved there, either by updating the tooling or manually adding the dependency.
#24
@
3 months ago
@swissspidy there's one report of a plugin breaking in a gutenberg issue that I tracked down to the polyfill removal commit - https://github.com/WordPress/gutenberg/issues/63009.
I haven't dived too deeply into their codebase, so I don't know if it's related to what @youknowriad mentioned here.
I've pointed the reporter to that comment, and mentioned that they can also discuss things on this trac ticket.
#25
@
3 months ago
Thanks, I'm trying to keep an eye on these. There was another report here as well.
#26
@
3 months ago
- Keywords has-dev-note added; needs-dev-note removed
Just opened https://github.com/WordPress/gutenberg/pull/63091 to fix the mapping of regenerator to regenerator-runtime
instead of wp-polyfill
.
The reasoning makes sense to me.