From 98db884ae158a0e21acb7a2a14a538c6ac15702e Mon Sep 17 00:00:00 2001 From: ramon Date: Wed, 31 Jul 2024 10:44:48 +1000 Subject: [PATCH 1/2] Uploading pattern JSON files was triggering an error in Firefox "categoryMap.values().find is not a function". categoryMap.values() method returns an iterator. Iterator.find() doesn't have wide browser support. It doesn't work in Firefox, Safari and others. Converting categoryMap.values() iterator to an array allow the use of find() --- .../src/components/add-new-pattern/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/edit-site/src/components/add-new-pattern/index.js b/packages/edit-site/src/components/add-new-pattern/index.js index e97cef1b2aa911..eef36003dbbeb3 100644 --- a/packages/edit-site/src/components/add-new-pattern/index.js +++ b/packages/edit-site/src/components/add-new-pattern/index.js @@ -173,9 +173,15 @@ export default function AddNewPattern() { // When we're not handling template parts, we should // add or create the proper pattern category. if ( postType !== TEMPLATE_PART_POST_TYPE ) { - const currentCategory = categoryMap - .values() - .find( ( term ) => term.name === categoryId ); + /* + * categoryMap.values() returns an iterator, not an array. + * Iterator.find() is not yet widely supported. + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/find + * Convert to array to use the find method. + */ + const currentCategory = Array.from( + categoryMap.values() + ).find( ( term ) => term.name === categoryId ); if ( currentCategory ) { currentCategoryId = currentCategory.id || From f08bc21600cde54986f19d22584e667649e0c0e1 Mon Sep 17 00:00:00 2001 From: ramon Date: Wed, 31 Jul 2024 11:07:15 +1000 Subject: [PATCH 2/2] Comment tweak. --- packages/edit-site/src/components/add-new-pattern/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/edit-site/src/components/add-new-pattern/index.js b/packages/edit-site/src/components/add-new-pattern/index.js index eef36003dbbeb3..bb9e53da6a5660 100644 --- a/packages/edit-site/src/components/add-new-pattern/index.js +++ b/packages/edit-site/src/components/add-new-pattern/index.js @@ -174,10 +174,9 @@ export default function AddNewPattern() { // add or create the proper pattern category. if ( postType !== TEMPLATE_PART_POST_TYPE ) { /* - * categoryMap.values() returns an iterator, not an array. - * Iterator.find() is not yet widely supported. - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/find - * Convert to array to use the find method. + * categoryMap.values() returns an iterator. + * Iterator.prototype.find() is not yet widely supported. + * Convert to array to use the Array.prototype.find method. */ const currentCategory = Array.from( categoryMap.values()