-
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
Patterns: fix bug with pattern categories not saving sometimes #54676
Conversation
…t is finished before saving the pattern
@aaronrobertshaw, @kevin940726 this seems to be a reasonably robust fix for this issue, but open to suggestions if you can see a better way. |
Size Change: +616 B (0%) Total Size: 1.62 MB
ℹ️ View Unchanged
|
Flaky tests detected in fb73520. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6254934255
|
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.
Thanks for fixing this @glendaviesnz 👍
It appears to be robust for me in my testing. I couldn't trigger the pattern save prior to the terms updating, as I can on trunk.
As for the approach, no alternatives I could think of were any better, so I don't have any objections to it. Especially, if it allows this fix to be backported in time for the GB 16.7 and WP 6.4 releases.
Also, special thanks for the nice before and after videos, they definitely make the original issue clear.
I can't take credit for the before video - @annezazu did such a good job of capturing the problem I thought I might as well just borrow that one 😄 |
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.
I can't think of a better way off the top of my head. Let's do this unless someone else has a better idea 👍!
@aaronrobertshaw, @kevin940726 I noticed a bug with this when testing the changes that you suggested Kai, which is the save button could be clicked multiple times while the category promise was resolving, which causes the pattern to save incorrectly. Have updated to disable button and show busy, and have added a note to PR test instructions about this. If one of you has time to give it another quick test to check these changes that would be great thanks. |
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.
After playing and thinking about it for a little bit more, I feel like we shouldn't create categories on blur, but only on save. If the user keeps blurring the input then it will accidentally create a lot of spammy categories, which may be unexpected to the user. If we only create the categories on save then maybe we can also make this flow easier. 🤔
I'll see what I can do!
I refactored the code to move the creation logic to the parent component and make |
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.
The refactor of the week 🏆 goes to @kevin940726 - this is a much better approach, thanks for doing this. This tests well for me in site and post editors:
✅ Category added on synced pattern saved if Create clicked directly after entering category
✅ Can add multiple categories for synced and unsynced patterns and all save as expected
✅ Multiple clicks on the Create
button while saving in progress do not have any adverse effect
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.
The switch to making CategorySelector
fully controlled is much better. Thank you @kevin940726 🙇
I've retested as per the updated test instructions. LGTM!
--------- Co-authored-by: Kai Hao <kai@kaihao.dev>
I just cherry-picked this PR to the release/16.7 branch to get it included in the next release: 40c12b4 |
What?
Ensures that the pattern categories that are entered in the pattern creation modal are always saved before the new pattern is saved.
Why?
Currently if the modal save button is clicked directly after entering a category the pattern is saved before the onBlur add category event has completed, so the pattern ends up as
uncategorised
Fixes: #54617
How?
Only create the pattern categories on submit to also prevent intermediate categories from being created.
Testing Instructions
Create
buttonunsynced
after entering category and then clickCreate
Screenshots or screencast
Before:
category.not.captured.mov
After:
category-after.mp4