Font Library: Fix Update button staying active when changes are reverted#78567
Conversation
|
Size Change: +96 B (0%) Total Size: 8.21 MB 📦 View Changed
ℹ️ View Unchanged
|
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the PR!
How about using fast-deep-equal without introducing custom logic? It is also frequently used within the Gutenberg repository.
This can probably be written as follows.
const fontFamiliesHasChanges = ! fastDeepEqual(
globalStyles?.record?.settings?.typography?.fontFamilies,
globalStyles?.editedRecord?.settings?.typography?.fontFamilies
);
Note that the library needs to be added to the @wordpress/global-styles-ui package beforehand.
|
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. |
|
Thanks for the review @t-hamano 🙌 The purpose of the custom logic there is ordering, to properly compare values. When you toggle a variant off and then back on, it gets appended to the end of the array, so you end up with two arrays that hold the same data but in a different order. Without sorting them first, the comparison could fail as it'd be thinking something changed when it actually didn't. The same for saved data (which is probably ordered in the way the user toggled things). I'm happy to pull in |
t-hamano
left a comment
There was a problem hiding this comment.
When you toggle a variant off and then back on, it gets appended to the end of the array, so you end up with two arrays that hold the same data but in a different order. Without sorting them first, the comparison could fail as it'd be thinking something changed when it actually didn't.
Thank you for explaining in detail! In that case, it seems that the current approach is fine.
|
Thanks Aki! |
What?
The "Update" button in the Font Library modal stays enabled after toggling a font variant on and then off again, even though the selection is identical to what was last saved. This makes users think there is something to save when there's not.
Why?
The previous check (
!! globalStyles.edits.settings.typography.fontFamilies) only tested whether an edits entry existed, not whether it differed from what's saved. Once you touch a checkbox, the entry is set and never clears. Even if you go bakc to the to the original selection.How?
Compare the edited
fontFamiliesvalue against the saved one fromglobalStyles.record, not just whether an edits entry exists. AddedgetFontFamiliesKey()to normalize families and faces before comparing, so re-toggling a variant doesn't leave the button enabled just because the order changed. Wrapped the check inuseMemoso it only runs when the edited or saved value actually changes.Testing Instructions
Screenshots or screencast
font-library.mp4