Private APIs: avoid wp-polyfill dependency from allowlist includes check#77166
Open
mreishus wants to merge 1 commit intoWordPress:trunkfrom
Open
Private APIs: avoid wp-polyfill dependency from allowlist includes check#77166mreishus wants to merge 1 commit intoWordPress:trunkfrom
wp-polyfill dependency from allowlist includes check#77166mreishus wants to merge 1 commit intoWordPress:trunkfrom
Conversation
|
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 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
In
@wordpress/private-apis, change the allowlist check from using.includes()to.indexOf().Why?
This package is currently picking up
wp-polyfillin WordPress builds with coreJS 3.49, because.include()is treated as needing a polyfill when Safari is a target for support.For small packages like
@wordpress/private-apis, this creates an avoidable dependency for consumers. In Jetpack's case, it shows up in generated asset files as:The specific
includesusage in@wordpress/private-apisis a simple check against an array of strings:For that case, replacing it with
indexOf( moduleName ) === -1is the same and avoids the extra polyfill dependency.How?
This behavior appears to be caused by a recent Safari sparse-array bug tracked in WebKit bug 309342 and reflected in
core-jscompat data. Since Safari is marked as no longer supporting.includes, a polyfill is brought back in when using the newest core-js.core-jscommit marking.includesas not supported in Safari: zloirock/core-js@0ad3e00core-js3.49.0 release notes - https://github.com/zloirock/core-js/releases/tag/v3.49.0Testing Instructions
npm add core-js-compat@3.49.0andnpm add core-js@3.49.0to force upgrades to versions that Gutenberg isn't using yet (but consumers may be using)Run
node test.jsand observe:After upgrading core.js, the polyfill marker was added to
.includes()but not.indexOf().Jetpack Evidence
In another, Jetpack, which has already been upgraded to core js 3.49.0, I was able to make similar changes which reduced the build's dependency needs.
Pair 1:
Pair 2:
This PR comes from me examining other increases of
wp-polyfillafter Jetpack upgraded core-data. Of course, the benefit here would not be for Jetpack, it would be for any consumer of@wordpress/private-apiswho has upgraded to this core data version.Testing Instructions for Keyboard
Screenshots or screencast
Use of AI Tools
.includes()+ Core Data Upgrade causing newwp-polyfillusages observed in Jetpack, but this was verified by humans, and also by seeing a drop in recorded polyfill requests after making similar fixes in production./* wp:polyfill */marker being applied to.includes().