Skip to content

Replace site-settings snackbar with My Site connectivity banner#22834

Merged
jkmassel merged 2 commits into
trunkfrom
jkmassel/site-offline-banner
May 21, 2026
Merged

Replace site-settings snackbar with My Site connectivity banner#22834
jkmassel merged 2 commits into
trunkfrom
jkmassel/site-offline-banner

Conversation

@jkmassel
Copy link
Copy Markdown
Contributor

@jkmassel jkmassel commented May 4, 2026

Description

Follow-up to #22785 (review feedback from @nbradbury). The snackbar from a failed editor capabilities fetch is non-actionable and disappears, leaving the user with no way to recover. On a cold launch with flaky network, it pops up before the user has done anything.

This PR moves the fetch into a new SiteConnectivityBannerViewModelSlice that posts a persistent SingleActionCard banner into the My Site header (last position, below the reauth banner) when the fetch fails AND there's no cache. Tapping the banner retries the fetch (bypassing the per-session dedup). Successful fetch — or a cached value — clears the banner.

The banner copy is generic — "Unable to connect to your site. Some functionality might be limited." — because the apiRoot fetch failure signals broader site reachability problems, not just editor issues.

Why a slice?

MySiteViewModel already carries LargeClass/LongMethod/LongParameterList suppressions. The fetch is logically self-contained (takes a SiteModel, posts a card or null), so it makes sense to extract. The slice owns the per-site session dedup that #22833 introduced inline — same behavior, dedicated home, dedicated tests.

Testing instructions

Covered by 9 new unit tests in SiteConnectivityBannerViewModelSliceTest:

  • Fetch succeeds → banner null
  • Fetch fails with no cache → banner shown
  • Fetch fails with cached value → banner null (silent)
  • Background dedup after success
  • Background retry after failure (no dedup until success)
  • User-initiated bypasses dedup
  • Banner retry tap bypasses dedup and clears banner on success
  • clearBanner() clears
  • Two different sites → both fetch (no cross-site dedup)

Manual:

  1. Put the device in airplane mode and cold-launch the app (without any saved data – you'll probably have to delete and re-install it), then go to My Site.
  • Verify the connectivity banner appears at the top of My Site (below the site header, below the reauth banner if present).
  • Verify there is no snackbar.
  1. Re-enable connectivity and tap the banner.
  • Verify the fetch runs and the banner disappears on success.
  1. Background the app and reopen with a working network.
  • Verify the banner does not appear.
  1. With a site that has cached capabilities, simulate a network failure on the next fetch.
  • Verify the banner does NOT appear (silent failure when we have data).

Related

@dangermattic
Copy link
Copy Markdown
Collaborator

dangermattic commented May 4, 2026

1 Warning
⚠️ This PR is assigned to the milestone 26.8. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented May 4, 2026

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr22834-320d2b8
Build Number1488
Application IDcom.jetpack.android.prealpha
Commit320d2b8
Installation URL7k473e3f4in1o
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented May 4, 2026

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr22834-320d2b8
Build Number1488
Application IDorg.wordpress.android.prealpha
Commit320d2b8
Installation URL46lc7opevi120
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented May 4, 2026

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@jkmassel jkmassel force-pushed the jkmassel/pr-22785-followups branch from 17973a8 to 5d99212 Compare May 4, 2026 19:54
@jkmassel jkmassel force-pushed the jkmassel/pr-22785-followups branch from 5d99212 to 873cc18 Compare May 13, 2026 18:37
Base automatically changed from jkmassel/pr-22785-followups to trunk May 13, 2026 18:53
@jkmassel jkmassel force-pushed the jkmassel/site-offline-banner branch from 84c2e15 to 10236eb Compare May 20, 2026 19:31
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

❌ Patch coverage is 90.47619% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.32%. Comparing base (d0a7db5) to head (320d2b8).
⚠️ Report is 1 commits behind head on trunk.

Files with missing lines Patch % Lines
...nnectivity/SiteConnectivityBannerViewModelSlice.kt 90.00% 0 Missing and 3 partials ⚠️
...org/wordpress/android/ui/mysite/MySiteViewModel.kt 91.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #22834   +/-   ##
=======================================
  Coverage   37.31%   37.32%           
=======================================
  Files        2319     2320    +1     
  Lines      124559   124574   +15     
  Branches    16921    16926    +5     
=======================================
+ Hits        46484    46498   +14     
+ Misses      74319    74315    -4     
- Partials     3756     3761    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jkmassel jkmassel force-pushed the jkmassel/site-offline-banner branch 2 times, most recently from 30db3cf to 185341e Compare May 20, 2026 22:19
@jkmassel jkmassel marked this pull request as ready for review May 21, 2026 00:39
@jkmassel jkmassel requested a review from nbradbury May 21, 2026 00:39
@jkmassel jkmassel self-assigned this May 21, 2026
@jkmassel jkmassel force-pushed the jkmassel/site-offline-banner branch from 185341e to 2d6b663 Compare May 21, 2026 00:39
@jkmassel jkmassel added this to the 26.8 milestone May 21, 2026
@jkmassel jkmassel force-pushed the jkmassel/site-offline-banner branch from 2d6b663 to ac1833c Compare May 21, 2026 02:04
@nbradbury
Copy link
Copy Markdown
Contributor

nbradbury commented May 21, 2026

@jkmassel This is an improvement, but if I enable airplane mode immediately after logging in, I see three separate warnings about connectivity.

Is there any way we can reduce the number of warnings? Perhaps skip showing the slice when the problem is lack of connectivity, since we know the "No connection" banner will appear.

@jkmassel
Copy link
Copy Markdown
Contributor Author

Is there any way we can reduce the number of warnings? Perhaps skip showing the slice when the problem is lack of connectivity, since we know the "No connection" banner will appear.

@nbradbury – yeah, good feedback. The slice now only shows for failed requests, not connectivity issues. There's some possibility of overlap/transient connectivity failures, so it's a little best-effort, but I think there's a bigger effort to be done here to rework the offline experience in a unified way instead of each widget/feature handling it differently.

WDYT about ecfe476?

@nbradbury
Copy link
Copy Markdown
Contributor

WDYT about ecfe476?

Much better! I'll approve this.

Copy link
Copy Markdown
Contributor

@nbradbury nbradbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

jkmassel added 2 commits May 21, 2026 10:25
Follow-up to #22785. The snackbar from a failed editor capabilities fetch
is non-actionable and disappears, leaving the user with no way to recover.
On a cold launch with flaky network, it pops up before the user has done
anything.

Move the fetch into a new SiteConnectivityBannerViewModelSlice that posts
a persistent SingleActionCard banner into the My Site header (last
position, below the reauth banner) when the fetch fails AND there's no
cache. Tapping the banner retries the fetch (bypassing the per-session
dedup). Successful fetch — or a cached value — clears the banner.

The slice cancels the in-flight fetch on site switch and on each new
fetchCapabilities call, and discards results whose site no longer matches
the active selection — postValue isn't a suspension point, so cancellation
alone won't catch a fetch that has already returned but not yet posted.

Banner taps are no-ops while a retry is in flight, so rapid tapping
doesn't queue concurrent network calls.
Review feedback from @nbradbury: enabling airplane mode immediately
after login surfaces three overlapping connectivity warnings. The
global "No connection" indicator already conveys the offline state, so
the slice's banner adds noise rather than information when the device
itself has no network.

Inject NetworkUtilsWrapper and suppress the banner emission when
isNetworkAvailable() is false. The fetch still runs (and fails)
unchanged — failed fetches don't populate the per-session dedup, so
onResume retries naturally when the user comes back online.

The banner remains useful in the partial-failure case it was designed
for: the device has connectivity but the site's REST endpoint is
unreachable (DNS, captive portal, JPC site offline, etc.).
@jkmassel jkmassel force-pushed the jkmassel/site-offline-banner branch from ecfe476 to 320d2b8 Compare May 21, 2026 16:25
@jkmassel jkmassel enabled auto-merge (squash) May 21, 2026 16:27
@jkmassel jkmassel merged commit 200189f into trunk May 21, 2026
25 checks passed
@jkmassel jkmassel deleted the jkmassel/site-offline-banner branch May 21, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants