From 80ca41d7527822c4e7677469e460df66c7e4daed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Gomes?= Date: Fri, 22 Nov 2024 12:10:18 +0000 Subject: [PATCH 1/2] Exclude Set instance methods from polyfills --- .../polyfill-exclusions.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/babel-preset-default/polyfill-exclusions.js b/packages/babel-preset-default/polyfill-exclusions.js index 507396c930b99c..0d22225db95b84 100644 --- a/packages/babel-preset-default/polyfill-exclusions.js +++ b/packages/babel-preset-default/polyfill-exclusions.js @@ -7,4 +7,36 @@ module.exports = [ // This is an IE-only feature which we don't use, and don't want to polyfill. // @see https://github.com/WordPress/gutenberg/pull/49234 'web.immediate', + // Remove Set feature polyfills. + // + // 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. + // + // This limitation causes a number of packages to unnecessarily get a + // dependency on `wp-polyfill`, which in most cases gets loaded as part of + // the critical path and can thus have an impact on performance. + // + // There is no good solution to this, and the one we've opted for here is + // to disable polyfilling these features entirely. Developers will need to + // take care not to use them in scenarios where the code may be running in + // older browsers without native support for them. + // + // These need to be specified as both `es.` and `esnext.` due to the way + // internal dependencies are set up in Babel / core-js. + 'es.set.difference.v2', + 'es.set.is-disjoint-from.v2', + 'es.set.is-subset-of.v2', + 'es.set.is-superset-of.v2', + 'es.set.symmetric-difference.v2', + 'es.set.union.v2', + 'es.set.intersection.v2', + 'esnext.set.difference.v2', + 'esnext.set.is-disjoint-from.v2', + 'esnext.set.is-subset-of.v2', + 'esnext.set.is-superset-of.v2', + 'esnext.set.symmetric-difference.v2', + 'esnext.set.union.v2', + 'esnext.set.intersection.v2', ]; From 0a7804d338e0930c56b6dcaa01aa69c464ca0dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Gomes?= Date: Tue, 26 Nov 2024 14:55:23 +0000 Subject: [PATCH 2/2] Switch to regexp exclusions --- .../babel-preset-default/polyfill-exclusions.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/babel-preset-default/polyfill-exclusions.js b/packages/babel-preset-default/polyfill-exclusions.js index 0d22225db95b84..ca8c045d124146 100644 --- a/packages/babel-preset-default/polyfill-exclusions.js +++ b/packages/babel-preset-default/polyfill-exclusions.js @@ -25,18 +25,7 @@ module.exports = [ // // These need to be specified as both `es.` and `esnext.` due to the way // internal dependencies are set up in Babel / core-js. - 'es.set.difference.v2', - 'es.set.is-disjoint-from.v2', - 'es.set.is-subset-of.v2', - 'es.set.is-superset-of.v2', - 'es.set.symmetric-difference.v2', - 'es.set.union.v2', - 'es.set.intersection.v2', - 'esnext.set.difference.v2', - 'esnext.set.is-disjoint-from.v2', - 'esnext.set.is-subset-of.v2', - 'esnext.set.is-superset-of.v2', - 'esnext.set.symmetric-difference.v2', - 'esnext.set.union.v2', - 'esnext.set.intersection.v2', + // + // @see https://github.com/WordPress/gutenberg/pull/67230 + /^es(next)?\.set\./, ];