Skip to content

Commit

Permalink
Patterns: enable cross-browser support for pattern uploading (#64123)
Browse files Browse the repository at this point in the history
* 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()

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
  • Loading branch information
3 people authored Jul 31, 2024
1 parent ddc5536 commit 86735ca
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/edit-site/src/components/add-new-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,14 @@ 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.
* Iterator.prototype.find() is not yet widely supported.
* Convert to array to use the Array.prototype.find method.
*/
const currentCategory = Array.from(
categoryMap.values()
).find( ( term ) => term.name === categoryId );
if ( currentCategory ) {
currentCategoryId =
currentCategory.id ||
Expand Down

0 comments on commit 86735ca

Please sign in to comment.