-
Notifications
You must be signed in to change notification settings - Fork 384
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
Preload validation counts data if AMP submenu is expanded #6770
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
931b666
to
5694ce5
Compare
*/ | ||
protected function maybe_add_preload_rest_paths() { | ||
if ( | ||
AMP_Options_Manager::OPTION_NAME === get_admin_page_parent() |
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 couldn't find a way to cover this condition with a unit test. I'm not sure how can I override get_admin_page_parent()
in the test suite.
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've found a (hacky) way to do so in 7981cb0.
Codecov Report
@@ Coverage Diff @@
## develop #6770 +/- ##
=============================================
+ Coverage 77.47% 77.48% +0.01%
- Complexity 6704 6708 +4
=============================================
Files 267 267
Lines 21378 21388 +10
=============================================
+ Hits 16563 16573 +10
Misses 4815 4815
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Plugin builds for 7981cb0 are ready 🛎️!
|
…min-validation-counts * 'develop' of github.com:ampproject/amp-wp: Skip Technical Background step if there is no dependency support Allow excessive CSS in Customizer preview
@delawski I have amended this with another small enhancement. Namely, in the case where there are no validation counts, previously there would be a flash of the loading spinner in both when the menu was pre-expanded and when it was expanded on hover: flash-of-loading-counts.movIn bc07073 I've made use of flash-of-loading-counts.movIf it happens that new validation counts have been generated after previously none were returned, then the result is just that no spinner appears before the counts are added: no-loading-spinner-when-previously-zero-counts.movI think this may offer a marginally better experience. Let me know what you think. |
Thanks for the amendment. I think the UX is even better now. Everything works as expected and the code looks good. |
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.
Changes looks good me.
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 wasn't getting the spinner when I didn't have errors:
AMP.Settings.tweety-two.WordPress.mp4
But also wasn't updating when I have new errors:
AMP.Settings.tweety-two.WordPress.1.mp4
@fellyph I wasn't able to reproduce this issue: validation-counts.mp4Can you provide your test steps? |
Agreeing with @delawski, I was unable to reproduce this at my end as well. |
@delawski I was using WordPress 5.9 beta 3, but now testing develop branch, I'm not getting the issue anymore on WordPress 5.8 and 5.9 beta 3. |
Summary
Fixes #6765.
So far, the Validated URLs and Error Index counts (validation counts in short) in WP admin were fetched from the REST API whenever the AMP submenu has been expanded. This approach has been introduced in #5900 in order to limit server resources usage - it's useless to calculate the validation counts if the AMP submenu is never revealed.
As a side-effect, a UX issue as described in #6765 has been introduced. If the AMP submenu is initially expanded, e.g. a user is on the AMP Settings screen or is browsing Validated URLs, the validation counts are still fetched asynchronously from REST API causing a momentary flash of a loading spinner inside the red badge.
In this PR, we take advantage of
apiFetch
preload middleware for providing the validation counts on page load but only if the AMP submenu is initially expanded. For other cases, we keep use the sameMutationObserver
-based solution so that the validation counts are still not calculated needlessly.Before
validation-counts-before.mp4
After
validation-counts-after.mp4
Checklist