-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Improve dependency extraction to only include wp-polyfill
when needed
#65216
Comments
I'm all in favor of adding Interestingly enough, this setting is set to |
Good one @sgomes! Unless I'm seriously missing something, all of the polyfilled features are already baseline available, so I don't see a good reason to continue defaulting to including the polyfills. Just like @gziolo, I'd be happy to see defaulting to an |
Thank you both, @gziolo @tyxla! 🙌 I've got the outline of a solution, but it's a bit contrived, and I'm not sure I like it too much:
Can you think of a better approach? |
CC @jsnajdr, who has a bunch of experience with babel and webpack plugins, and might know a better way. |
I'm thinking about this right now 🙂 The current polyfill includes the following modules:
It mostly adds new methods, except the It puzzles me that Chrome 109 is mentioned, since we are supposed to support only last 2 Chrome version and Chrome is currently at version 128. Let me try to upgrade the packages with compat data, if that radically changes the output. The |
I did a quick test by including some code that should use polyfills: const arr = [ 1, 2, 3, 4, 5 ];
console.log( arr.with( 2, 6 ) );
const illFormed = 'https://example.com/search?q=\uD800';
try {
encodeURI( illFormed );
} catch ( e ) {
console.log( e ); // URIError: URI malformed
}
console.log( encodeURI( illFormed.toWellFormed() ) ); However, nothing got added to the file processed by Babel as expected as we have Alternative path. Can we go the other way around and disallow code that requires polyfilling? In effect, if we detect not fully supported syntax the Babel processing errors or ESLint complaints? |
Thank you for your comment, @jsnajdr! To answer your questions:
It works around an obscure bug in some browsers: https://issues.chromium.org/issues/42202623 I'm planning on excluding this from the list of polyfills, as this seems to me like yet another case of core-js being too pedantic.
We also support |
That's an intriguing option, thank you @gziolo! Are we okay with disabling all of the functionality that @jsnajdr listed in his comment (except for |
Yes, that's what I found after upgrading |
I would consider it today as the type of polyfills included looks like nice to haves. In the past, we needed it to be able to use all the latest shiny features that had large impact on the developer experience. The list you shared needs to be investigated to check actual usage. |
I'm already knee-deep in babel polyfills, so this shouldn't take too long 👍 I'll let you know what I find! |
@gziolo : It doesn't look like it's possible while we need to polyfill Here's a list of packages and one of the polyfills they use (there may be more):
|
I see it now, old versions of V8 have a bug when the |
I think it should be okay to ignore this polyfill, and have browsers work on a best-effort basis there. It's already highly unlikely that our code will somehow run into such a contrived scenario, let alone it happening to the 1.4% of users on a browser with the bug. What do you think, @jsnajdr? |
In the meantime, I'll continue developing the "auto" mode we discussed, based on the approach I laid out. |
I think I got it working, and it turned out pretty clean! 🙂 Please take a look at #65292 when you get a chance! |
What problem does this address?
Currently, simple scripts like
wp-hooks
depend onwp-polyfill
, even when they don't seem to make use of any of the features that are currently present inwp-polyfill
:The list of polyfilled features in `wp-polyfill` as of issue creation
As far as I can tell, the dependency on
wp-polyfill
comes from a hardcoded boolean intools/webpack/packages.js
:This approach is problematic, since it can lead to the fairly large
wp-polyfill
being loaded in thehead
to support simple scripts likewp-hooks
andwp-i18n
.What is your proposed solution?
At a high level, it seems that
DependencyExtractionWebpackPlugin
should be able to determine on its own whether polyfills are needed, and theinjectPolyfill
configuration option should be dropped (or perhaps turned into an optional override).Perhaps the plugin could look for
core-js
imports, as it currently does for WordPress ones? Though I'm not sure if it runs before or after Babel.Alternatively, we could hardcode a list of excluded packages, but that would involve some amount of error-prone maintenance.
CC @gziolo @jsnajdr @tyxla for some ideas! 🙏
The text was updated successfully, but these errors were encountered: