Stats post detail: prefetch email tab availability and seed it from the email pages - #113931
Stats post detail: prefetch email tab availability and seed it from the email pages#113931dognose24 wants to merge 2 commits into
Conversation
|
WordPress.com
Automattic for Agencies
|
|
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Sections (~394 bytes added 📈 [gzipped]) Details
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~141 bytes removed 📉 [gzipped]) Details
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. |
…he email pages Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C5G7Fg8tpLg8Qe9EaSs79t
…s provably inactive Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01C5G7Fg8tpLg8Qe9EaSs79t
cc68906 to
51db32c
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves the Stats post-detail “Email opens/clicks” tab-strip UX by warming the /rate-based availability query earlier and by seeding the cache on navigations where email availability is already known (Email → Post traffic), reducing or eliminating the “tabs pop in late” flash.
Changes:
- Extracts the email-tab availability react-query options into a shared
postEmailStatsAvailabilityQueryOptionsfactory and prefetches it from the statspost()route controller. - Seeds the availability cache when navigating from Email opens/clicks back to Post traffic to render the tab strip immediately.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| client/my-sites/stats/stats-details-navigation/index.tsx | Seeds the email availability cache when navigating from email tabs to Post traffic. |
| client/my-sites/stats/hooks/use-post-email-stats-availability-query.ts | Extracts shared query options and adds a cache seeding helper for known-positive navigations. |
| client/my-sites/stats/controller.jsx | Prefetches the email availability query during route handling to overlap with chunk loading. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const { queryKey } = postEmailStatsAvailabilityQueryOptions( siteId, postId ); | ||
| if ( queryClient.getQueryData( queryKey ) === undefined ) { | ||
| queryClient.setQueryData( queryKey, { total_sends: 1 } ); | ||
| } |
| const canHaveEmailStats = | ||
| !! supportsEmailStats && | ||
| ( isSimpleSite( state, siteId ) || | ||
| isJetpackModuleActive( state, siteId, 'subscriptions', true ) !== false ); |
Part of STATS-464.
Follow-up to #113843 (merged); rebased onto trunk.
Proposed Changes
postEmailStatsAvailabilityQueryOptionsfactory and prefetch it from thepost()route controller. The gate skips the warm-up only when subscriptions is provably inactive: at route time the Jetpack module state is usually not loaded yet (QueryJetpackModulesruns after mount and/me/sitesdoes not requestactive_modules), so an unknown state still prefetches, while the page's ownenabledcheck stays strict. The/raterequest now runs in parallel with the post detail chunk download instead of after mount.seedPostEmailStatsAvailability): being on an email tab already proves the post has email stats, so that navigation renders the tab strip immediately.Why are these changes being made?
/ratequery that is deliberately not persisted, so on a fresh visit the strip appears only once the request resolves. Review of Stats post detail: show email tabs based on actual email stats #113843 measured a ~760ms gap when navigating from the Emails page (a pre-existing behavior on trunk, ~640ms).Testing Instructions
.../stats/opens/emails/<post>/raterequest starting together with theasync-load-...-stats-post-detailchunk rather than after it./raterequest needed for it to appear./raterequest; sites without email stats support (no subscriptions module) issue no/raterequest from the controller.Pre-merge Checklist
/raterequest. Self-hosted Jetpack / Odyssey not tested yet.)