Skip to content

RS Post Settings: Fetch site post formats from themes API#22710

Merged
nbradbury merged 11 commits intotrunkfrom
feature/rs-posts-post-formats
Mar 23, 2026
Merged

RS Post Settings: Fetch site post formats from themes API#22710
nbradbury merged 11 commits intotrunkfrom
feature/rs-posts-post-formats

Conversation

@nbradbury
Copy link
Copy Markdown
Contributor

@nbradbury nbradbury commented Mar 19, 2026

Description

The RS post settings FormatDialog previously hardcoded all 10 standard post formats. This PR fetches the formats actually supported by the site's active theme using the wordpress-rs themes API (themes().listWithViewContext()), falling back to the full default list if the API call fails.

Testing instructions

Theme with limited format support:

  1. View settings for a post on the "Rabbit Of Caribbeans" test site (whose active theme supports only a subset of formats)
  2. Tap the Format row to open the format dialog
  • Verify the dialog shows only the theme-supported formats plus Standard
format

Fallback on failure:

  1. Open a post, then disable network
  2. Tap the Format row
  • Verify the dialog shows the full default list of 10 formats
format2

@dangermattic
Copy link
Copy Markdown
Collaborator

dangermattic commented Mar 19, 2026

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Mar 19, 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
Versionpr22710-2048290
Build Number1488
Application IDorg.wordpress.android.prealpha
Commit2048290
Installation URL5qf6hehka7rb8
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 Mar 19, 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
Versionpr22710-2048290
Build Number1488
Application IDcom.jetpack.android.prealpha
Commit2048290
Installation URL7ah6p0s8958pg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 18.36735% with 80 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.35%. Comparing base (0c9a9a3) to head (2048290).
⚠️ Report is 2 commits behind head on trunk.

Files with missing lines Patch % Lines
...android/ui/postsrs/screens/PostRsSettingsScreen.kt 0.00% 33 Missing ⚠️
...dpress/android/ui/postsrs/data/PostRsRestClient.kt 30.23% 30 Missing ⚠️
...ress/android/ui/postsrs/PostRsSettingsViewModel.kt 10.52% 14 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #22710      +/-   ##
==========================================
- Coverage   37.35%   37.35%   -0.01%     
==========================================
  Files        2316     2316              
  Lines      123272   123347      +75     
  Branches    16712    16727      +15     
==========================================
+ Hits        46053    46071      +18     
- Misses      73520    73574      +54     
- Partials     3699     3702       +3     

☔ 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.

nbradbury and others added 8 commits March 20, 2026 11:27
Fetch the active theme's supported post formats via the wordpress-rs
themes API instead of hardcoding all 10 formats. Falls back to the
full default list on failure or when the theme doesn't declare support.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove redundant outer try/catch (caller already handles exceptions)
and replace mutable list + none/add pattern with distinct() for
prepending Standard format.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Defer the themes API call until the user actually opens the format
picker, avoiding an unnecessary network request on every screen load.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Request only THEME_SUPPORTS via filterListWithViewContext() to reduce
payload size. Fix format dialog losing its selection when site post
formats load by updating selectedIndex in a LaunchedEffect.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract post format parsing into a dedicated helper that uses
nullable chaining, reducing fetchSitePostFormats to 2 return paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Consolidate duplicated format knowledge into a single SLUG_TO_FORMAT map
and replace LaunchedEffect with idiomatic key() for resetting dialog state.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nbradbury nbradbury force-pushed the feature/rs-posts-post-formats branch from 779cfe7 to 1fdf6df Compare March 20, 2026 15:29
nbradbury and others added 2 commits March 20, 2026 11:45
Fetch site post formats before showing the format dialog instead of
opening it immediately, eliminating visual flicker from the list
swapping. Use a hasFetchedFormats flag so the fetch runs only once
regardless of whether the result matches the defaults or fails.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Open the format dialog immediately on tap and display a
CircularProgressIndicator while the themes API call is in flight,
replacing the previous behavior of delaying the dialog until the
fetch completed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nbradbury nbradbury marked this pull request as ready for review March 20, 2026 16:38
@nbradbury nbradbury requested a review from adalpari March 20, 2026 16:38
@adalpari
Copy link
Copy Markdown
Contributor

Claude found a possible race condition, could you verify it's ok?

  1. Race condition: dialog opens before formats are loaded (medium)

onFormatClicked() triggers resolveSitePostFormats() and immediately opens the dialog. The fetch is async, so the dialog shows a loading spinner. This works, but if the user
opens the dialog, dismisses it, and opens it again quickly, a second fetch won't happen (hasFetchedFormats is set to true even if the first fetch failed via the catch branch).
This means a transient network error permanently locks in DEFAULT_POST_FORMATS for the session.

Suggestion: only set hasFetchedFormats = true on success, so a retry is attempted on next open after a failure.

Copy link
Copy Markdown
Contributor

@adalpari adalpari left a comment

Choose a reason for hiding this comment

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

LGTM!
Just left a comment to check from Claude

Only set hasFetchedFormats on success so transient network errors
don't permanently lock in defaults. Also guard against concurrent
fetches by checking isLoadingFormats before launching.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nbradbury
Copy link
Copy Markdown
Contributor Author

  1. Race condition: dialog opens before formats are loaded (medium)

That's definitely an edge case but still valid. Fixed in Allow retry when site post format fetch fails.

@sonarqubecloud
Copy link
Copy Markdown

@nbradbury nbradbury enabled auto-merge (squash) March 23, 2026 11:36
Copy link
Copy Markdown
Contributor

@adalpari adalpari left a comment

Choose a reason for hiding this comment

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

:shipit:

@nbradbury nbradbury merged commit 12b8607 into trunk Mar 23, 2026
24 checks passed
@nbradbury nbradbury deleted the feature/rs-posts-post-formats branch March 23, 2026 11:41
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