-
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
Exclude Set instance methods from polyfills #67230
Conversation
Apologies for linking to the wrong issue, fixed. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @zloirock. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: 0 B Total Size: 1.82 MB ℹ️ View Unchanged
|
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 probably the only solution at the moment.
It's a bit risky: the new Set methods are part of the ES2024 standard and the Gutenberg codebase claims to support the latest published standard. If someone uses one of the new methods, it will work in the evergreen browser they likely use for development, and all the tests will also pass. But the promise to support >1% browsers will be silently broken, with a fatal error, because the polyfill is missing.
Thank you for the review, @jsnajdr!
I completely agree, and am unhappy with this solution, even as its author 😕 The only way I can think of mitigating the risk is by keeping the polyfills in the bundle, but excluding them from the build process. Then we'd look for instances of |
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.
After additional discussion in #66552 (comment) it's clear that this patch is still a good idea 🙂
It would be nice to exclude all Set polyfills:
es.set.*
esnext.set.*
but I guess our tools (@babel/preset-env
and core-js-builder
) don't always support wildcards?
The idea is to never polyfill Set
just because there was an usage found in a source file. The native unpatched version provided by the browser should be used.
Right, the issue here is that That said, they both seem to accept regexps! I'm giving that a try, and will update the PR if it works. |
Thank you again for the review, @jsnajdr, I think the regexp approach is much cleaner 🙂 Would anyone else like to comment on this PR before I merge? |
* Exclude Set instance methods from polyfills * Switch to regexp exclusions
* Exclude Set instance methods from polyfills * Switch to regexp exclusions
What?
This PR adds a number of
Set
instance methods to the polyfill exclusions list.Why?
When dependencies were updated in #65926, new
Set
methods started getting polyfilled.The Babel/core-js integration has a severe limitation, in that any Set objects (e.g.
new Set()
) are assumed to need all instance methods, and get them all polyfilled. There is no validation as to whether those methods are actually in use.The list of problematic instance methods
This limitation caused a regression, in that a number of packages unnecessarily got a new dependency on
wp-polyfill
, which in most cases gets loaded as part of the critical path and can thus have an impact on performance.This PR fixes #66552.
How?
There is no good solution to the issue, but the one this PR opts for is to disable polyfilling the aforementioned
Set
instance methods entirely. Developers will need to take care not to use these methods in scenarios where the code may be running in older browsers without native support for them.Testing Instructions
i8n
end up with a dependency onwp-polyfill
wp-polyfill
is no longer present in simple packages likei8n
Testing Instructions for Keyboard
N/A
CC @anomiex @swissspidy