-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix TypeError when duplicating uncategorized theme patterns #66889
Conversation
Only try to match the pattern categories and get the label if the theme pattern uses the `categories` parameter. Otherwise there will be a TypeError when using the filter.
Size Change: 0 B Total Size: 1.82 MB ℹ️ View Unchanged
|
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. |
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.
Left a small comment, but this looks good. Thank you!
The array fallback is not needed inside getTermLabels, because getTermLabels is used as the value for defaultCategories, which is an empty array by default when it is used inside the function CreatePatternModalContents.
I briefly looked into adding a Playwright test for this but I was not able to figure out if there was a way to test a theme provided pattern. |
Oh, or I am supposed to get theme patterns by |
So I think the test should wait until TT5 is released, so that it can be added to the gutenberg-test-themes. |
Flaky tests detected in 8e64ae6. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11775413937
|
For tests we're using the empty theme, where we can add stuff, like templates, patterns etc.. Did you try adding one there? |
I did not: I am torn about that because then it wont be empty 😅 |
I get it 😄 , but it's not entirely empty right now. Anyway.. This fix is a JS pretty strait forward one, and I believe it would be fine not to add a test. |
…s#66889) * Fix TypeError when duplicating uncategorized patterns Only try to match the pattern categories and get the category label if the theme pattern uses the optional `categories` parameter. Co-authored-by: carolinan <[email protected]> Co-authored-by: ntsekouras <[email protected]> Co-authored-by: getdave <[email protected]>
Five lines below the patch site, there's a similar filter, but accessing property .filter( ( category ) =>
- pattern.wp_pattern_category.includes( category.id )
+ pattern.wp_pattern_category?.includes( category.id )
) |
@mcsf I left it because I was not able to reproduce any errors when testing with user created patterns. |
@mcsf @ntsekouras I ran a quick test and if I unregister the The duplication of user created patterns do not break. I think it is something that needs to be looked at separately. |
* Fix TypeError when duplicating uncategorized patterns Only try to match the pattern categories and get the category label if the theme pattern uses the optional `categories` parameter. Co-authored-by: carolinan <[email protected]> Co-authored-by: ntsekouras <[email protected]> Co-authored-by: getdave <[email protected]>
I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release. |
Syncs Editor packages for WordPress 6.7.1 RC1. Includes the following PRs: - WordPress/gutenberg#66945 - WordPress/gutenberg#66889 - WordPress/gutenberg#67139 Props mmaattiiaass, ramonopoly, mamaduka, get_dave, poena, ntsekouras, mcsf, jsnajdr, 0mirka00, desrosj, joemcgill, cbravobernal, azaozz, room34, mayanktripathi32, im3dabasia1, jonsurrell. Fixes #62478, #62447. git-svn-id: https://develop.svn.wordpress.org/branches/6.7@59437 602fd350-edb4-49c9-b593-d223f7449a82
Syncs Editor packages for WordPress 6.7.1 RC1. Includes the following PRs: - WordPress/gutenberg#66945 - WordPress/gutenberg#66889 - WordPress/gutenberg#67139 Props mmaattiiaass, ramonopoly, mamaduka, get_dave, poena, ntsekouras, mcsf, jsnajdr, 0mirka00, desrosj, joemcgill, cbravobernal, azaozz, room34, mayanktripathi32, im3dabasia1, jonsurrell. Fixes #62478, #62447. Built from https://develop.svn.wordpress.org/branches/6.7@59437 git-svn-id: http://core.svn.wordpress.org/branches/6.7@58823 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Syncs Editor packages for WordPress 6.7.1 RC1. Includes the following PRs: - WordPress/gutenberg#66945 - WordPress/gutenberg#66889 - WordPress/gutenberg#67139 Reviewed by desrosj. Merges [59437] to trunk. Props mmaattiiaass, ramonopoly, mamaduka, get_dave, poena, ntsekouras, mcsf, jsnajdr, 0mirka00, desrosj, joemcgill, cbravobernal, azaozz, room34, mayanktripathi32, im3dabasia1, jonsurrell. Fixes #62478, #62447. git-svn-id: https://develop.svn.wordpress.org/trunk@59438 602fd350-edb4-49c9-b593-d223f7449a82
Syncs Editor packages for WordPress 6.7.1 RC1. Includes the following PRs: - WordPress/gutenberg#66945 - WordPress/gutenberg#66889 - WordPress/gutenberg#67139 Reviewed by desrosj. Merges [59437] to trunk. Props mmaattiiaass, ramonopoly, mamaduka, get_dave, poena, ntsekouras, mcsf, jsnajdr, 0mirka00, desrosj, joemcgill, cbravobernal, azaozz, room34, mayanktripathi32, im3dabasia1, jonsurrell. Fixes #62478, #62447. Built from https://develop.svn.wordpress.org/trunk@59438 git-svn-id: https://core.svn.wordpress.org/trunk@58824 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Syncs Editor packages for WordPress 6.7.1 RC1. Includes the following PRs: - WordPress/gutenberg#66945 - WordPress/gutenberg#66889 - WordPress/gutenberg#67139 Reviewed by desrosj. Merges [59437] to trunk. Props mmaattiiaass, ramonopoly, mamaduka, get_dave, poena, ntsekouras, mcsf, jsnajdr, 0mirka00, desrosj, joemcgill, cbravobernal, azaozz, room34, mayanktripathi32, im3dabasia1, jonsurrell. Fixes #62478, #62447. Built from https://develop.svn.wordpress.org/trunk@59438 git-svn-id: http://core.svn.wordpress.org/trunk@58824 1a063a9b-81f0-0310-95a4-ce76da25c4cd
What Why & How
When a pattern is duplicated, there is a modal with an input field that contains the labels of the pattern categories:
the information about the category is passed on to the new pattern.
The function that gets the labels compares the category from the theme pattern with the existing registered pattern categories, to make sure that the category exists and is displayed with the correct label.
However, the code did not take into account that theme patterns can be registered without the optional
categories
parameter.This PR makes a small change to the filter and mapping using optional chaining, to avoid a TypeError when the
categories
parameter is not used.Closes #66888
Testing Instructions
Activate a theme that registers a pattern without the
categories
parameter. This can be a classic theme or a block theme, for example Twenty Twenty-Five.Open the Patterns screen from Appearance > Patterns or from Appearance > Editor > Patterns.
Locate the pattern that does not have a category.
Select the option to duplicate the pattern.
Confirm that the modal with the information about the duplicated pattern opens and that there are no JavaScript errors in the browser console.
Click the button at the bottom of the modal to duplicate the pattern. Confirm that there are no issues related to the category of the new pattern.
Now, select a different pattern that has a single category or multiple categories, and duplicate it.
Confirm that the category labels show correctly in the modal and that there are no new issues/ regressions.
Click the button at the bottom of the modal to duplicate the pattern. Confirm that there are no issues related to the category of the new pattern.