Repository navigation
Keep Reader saved posts in the WordPress.com account - #26372
Conversation
Generated by 🚫 Danger |
🤖 Build Failure AnalysisThis build has failures. Claude has analyzed them - check the build annotations for details. |
Every build of a PR uploaded its xcframework to `pr-builds/<PR>`, replacing the previous build's file. CloudFront kept serving the cached copy, so an app pinned to the new `pr-build/<PR>` commit downloaded an older xcframework and failed SwiftPM's checksum check. WordPress-iOS CI failed this way on wordpress-mobile/WordPress-iOS#26372, and a local build did too. Each build now goes to `pr-builds/<PR>/<build number>`, as trunk builds already go to `trunk-builds/<commit>`. The build number rather than the commit, so rebuilding the same commit doesn't reuse a path either.
Every build of a PR uploaded its xcframework to `pr-builds/<PR>`, replacing the previous build's file. CloudFront kept serving the cached copy, so an app pinned to the new `pr-build/<PR>` commit downloaded an older xcframework and failed SwiftPM's checksum check. WordPress-iOS CI failed this way on wordpress-mobile/WordPress-iOS#26372, and a local build did too. Each build now goes to `pr-builds/<PR>/<build number>`, as trunk builds already go to `trunk-builds/<commit>`. The build number rather than the commit, so rebuilding the same commit doesn't reuse a path either.
d991415 to
745469e
Compare
Every build of a PR uploaded its xcframework to `pr-builds/<PR>`, replacing the previous build's file. CloudFront kept serving the cached copy, so an app pinned to the new `pr-build/<PR>` commit downloaded an older xcframework and failed SwiftPM's checksum check. WordPress-iOS CI failed this way on wordpress-mobile/WordPress-iOS#26372, and a local build did too. Each build now goes to `pr-builds/<PR>/<build number>`, as trunk builds already go to `trunk-builds/<commit>`. The build number rather than the commit, so rebuilding the same commit doesn't reuse a path either.
|
Rebase this PR, since it contains the same changes in #26404? |
There was a problem hiding this comment.
Do you think the “Export” feature can be removed now? I believe it’s built because the saved posts were local only. Now that they are on the server too, I think the “Export” feature is now redundant? /cc @twstokes
If export is removed, we can remove import too, which I think should simplify the implementation.
There was a problem hiding this comment.
I think it's nice for users to be able to take their data out of the system? That said, this might make more sense as a web feature than a mobile one?
There was a problem hiding this comment.
That said, this might make more sense as a web feature than a mobile one?
I agree.
From the original PR #25509:
Saved Reader posts are local-only and don't sync across devices. This adds the ability to import and export them as a JSON file, so users can back up their saved posts or transfer them between devices/apps.
It's now synced with API.
There was a problem hiding this comment.
WDYT about removing it from the app once it's built for the web?
There was a problem hiding this comment.
AI found an issue with importing exported file. It probably should be fixed if the Export feature is kept:
A page saved by URL is not restored when importing the app's own export
Steps:
- Sign in with a WordPress.com account that has a page saved by URL in Saved.
- Open Reader → Saved and let the list load.
- Open the Saved Posts screen and tap Export Saved Posts. Save the file.
- In Saved, swipe the page saved by URL and tap Remove.
- Open the Saved Posts screen again, tap Import Saved Posts, and pick the file from step 3.
Expected: The alert counts the page as imported, and the page is back in Saved and on wordpress.com/read/saved.
Actual: The alert says "0 imported, 2 skipped, 1 failed". The page does not come back, in the app or on the account. The app log has:
[org.wordpress:wp_mobile::service::reader_saved] The server refused a saved post change: Post not found.
How often: 2 of 2 tries, on two builds of this PR (745469e and a9de039).
| Page saved by URL in Saved | Import result | After import |
|---|---|---|
![]() |
![]() |
![]() |
The exported entry for that page:
{
"author": "",
"isFeed": true,
"postID": 70576,
"siteName": "",
"siteURL": "",
"summary": "A disposable URL-only page for the round 2 export and import check.",
"tags": [],
"title": "Saved Posts review page r2",
"url": "https://example.com/?saved-posts-review=26372-r2"
}Note: the page saved by URL in step 1 was created with the saved-posts API ({"url": "https://example.com/?saved-posts-review=26372-r2"}). Steps 2 to 5 were done in the app.
a9de039 to
2b3fe1d
Compare
|
There are also these issues, but I don't think they are really that important: 1. A saved post doesn't open offline from Saved, even when it's stored on the device Saved opens posts by ID (ReaderSavedPostsView.swift#L64-L92), so the post screen always fetches the post first and shows an error if the fetch fails, even with the post in Core Data. The old Saved stream passed the post itself. Online, every open from Saved shows a spinner for 2 to 6 seconds before the content.
Expected: the post shows from the device. Actual: an error. Found with a unit test of the detail coordinator; the airplane mode steps have not been run by hand. 2. A post saved offline when the account is at the 1,000-save limit stays saved, with no notice The description says a tap past the limit "is undone too, and the notice says the account is at its limit". That only happens online. Offline, the tap is queued; when the device reconnects, the server refuses it for the limit, but no tap is waiting, so the post stays saved and listed with no notice. It never reaches the account, so other devices don't see it. A file import counts such saves as "imported" too.
Expected: the save is undone, with the limit notice. Actual: it stays saved, with no notice, and isn't on wordpress.com/read/saved. Found with a test using the real wordpress-rs service and scripted server replies; not run with a real account at the limit. 3. An imported page saved by URL doesn't send its title to the server The import keeps the file's title for the row on this device, but the save request is only 4. A stale saved list from the server can unsave a post that was just saved If the server's saved list lags behind a save it already confirmed, the next sync shows the post as not saved and removes it from Saved. This comes from wordpress-rs (Automattic/wordpress-rs#1720), but this PR syncs at launch, on every foreground and on every reconnect, so a lagging list has more chances to land. Found with a test using a scripted stale reply; not seen live. |
Saved posts used to live only in Core Data on one device. They now go through wordpress-rs's ReaderSavedService, which keeps them in the user's WordPress.com account and caches the saved list in WordPressApiCache. - A new SwiftUI Saved screen reads the cached list, with pull to refresh, paging, and swipe to remove. - Saving and unsaving go to the account; bookmark icons read the account's status. - Posts saved on the device are sent to the account once per account, in the order the old Saved screen showed them. The Core Data flags are left in place. - Signing out deletes the account's Reader data from the cache. - Without a WordPress.com account, Saved and the save buttons are hidden. - JSON import and export use the account. Pins wordpress-rs to the #1729 PR build; it needs a release before this can merge.
Two exports on the same day wrote to the same file, so one could read the other's half-written file.
An import counted posts the account already had as imported, although the settings footer says duplicates are skipped, and the imported posts only showed in Saved after a pull to refresh.
Moves wordpress-rs to the build of Automattic/wordpress-rs#1734, which reads them from the saved list. Saved rows show the site icon (or an RSS feed's image), the first three tags and the number of comments. A count of 0 isn't shown, because the server sends 0 for posts that can't have comments. The saved date leaves out the year for this year's saves. The JSON export now includes each post's tags. wordpress-rs now has its own `ReaderPost`, so files that import it and WordPressData name the Core Data class as `WordPressData.ReaderPost`.
Saving a post from a stream now sends its details with the save (`saveWithDetails`, from Automattic/wordpress-rs#1734), so the Saved list shows its title, site, excerpt, tags and comment count straight away. Before, the list showed an empty row until the next refresh brought the post back. The details come from the Core Data post. They only fill in what the cache doesn't have, and the saved list's copy replaces them on the next refresh.
The Saved rows asked for the site icon at its full URL with no size, so they never matched what the Reader's post cards had already loaded: the image cache's key includes the size. Each row also drew its placeholder first, because `CachedAsyncImage` only checks the memory cache once its task runs. So the icon arrived a beat late even for a site whose posts were on screen a moment earlier. The rows now build the icon URL with `makeReaderSiteIconURL` and load it at the post cards' size, and read the memory cache while drawing, so an icon that's already loaded shows in the first frame. Sites without an icon URL also get the same built-in icon the cards use.
A post whose author set no featured image had an image on its Reader card but none in Saved. The card falls back to the image the server picks from the post (`featured_media`), and Saved only read `featured_image`. Moves wordpress-rs to the build of Automattic/wordpress-rs#1734 that adds `displayImageUrl`, picked the way the cards pick it. Saved rows and the JSON export use it, and a save sends the image the post's card shows.
Automattic/wordpress-rs#1720 now keeps each save and unsave in the cache and sends them from a queue, one at a time, so they work offline. This pins the build of #1734, which is stacked on it. - Sync at launch, when the app comes to the foreground, and when the device comes back online, as the service asks. `refresh()` on the service is now `sync()`. - The JSON import saves each post as a tap would, oldest first so the newest ends up at the top. The bulk import it used is gone. A save that can't be sent yet still counts as imported. - Reading a post's status can fail now; it's logged and read as not known. - The first-launch import's log line and event include the saves still waiting to be sent.
The export writes a page saved by URL without IDs, but its key needs an external identity with a `0` site and feed. Without them the import reported the page as skipped and didn't save it.
wordpress-rs 0.11.0 (from #26404) is the first release with `ReaderSavedService`, which this branch used from PR builds. - `importSaves` replaces `importLocalSaves` and imports whenever it's asked, so the app records the launch import per account in `UserDefaults`, clears the record on sign-out, and runs one import at a time. - JSON import sends the file's posts in one `importSaves` call, with the file's title, excerpt, image and site, rather than one save per post. - A tap past the account's 1,000-save cap fails with `TooManySaves`, and the notice says the account is at its limit. A sync that leaves saves waiting for room logs it rather than warning. - `ReaderPost.tags` is optional. Core Data can't tell a post without tags from one whose tags it doesn't have, so it sends `nil` for none. - The store takes the notification center it observes, so parallel tests don't sync each other's stores.
Once the server has sent a page saved by URL, the export wrote the server's ID for it, which the API can't save it by. The import then sent it as a post and the server refused it with "Post not found". The export now writes such a page without IDs, and the import saves any entry with no site or feed by its URL, so files exported before this fix import too.
Saved opened every post by its IDs, so the post screen fetched it first: an error offline, and a spinner of a few seconds online. The old Saved stream passed the stored post. Now a post Core Data has with its content opens straight away, and others are still fetched.
A save made offline with the account at its 1,000-save cap waits on this device until there's room, and nothing said so. The banner gives the number of such saves and says to remove some to make room.
The export stopped after 50 pages, assuming 40 posts a page, but the saved list sends 10. An account at the 1,000-save cap exported only its newest 500 posts, with no sign that any were left out. The cap is now 250 pages, which only stops a server that never ends the list.
2b3fe1d to
7224f6c
Compare
|
From Claude: Thanks for these.
The test plan in the description has the simulator checks for each fix. |



Description
Reader's saved posts now live in the user's WordPress.com account instead of only on one device, so they sync between devices and survive a reinstall. Posts already saved on the device move to the account on first launch.
Uses wordpress-rs 0.11, the first release with
ReaderSavedService(Automattic/wordpress-rs#1720 and #1734). Trunk already has it (0.11.1, from #26420), so this PR doesn't change the package.Warning
If you ran an earlier build of this PR, delete the app before installing this one. wordpress-rs 0.11.0 folded the unreleased account and Reader migrations into one, so a cache that ran a PR build's migrations has tables this release doesn't expect. Released versions never had these migrations, so users aren't affected.
How it works
ReaderSavedServicesaves and unsaves through the WordPress.com API and keeps the saved list inWordPressApiCache, under the account. The list shows from disk after a relaunch, including offline.ReaderSavedPostsStoreholds it and replaces it when the account changes. It sends one request at a time, and a second instance would send alongside it.displayImageUrlfrom Give saved posts their site icon, tags and comment count Automattic/wordpress-rs#1734): the featured image, or else the image the server picks from the post. A save sends the card's image too.makeReaderSiteIconURL, including the built-in icons for sites without one) at the same size. Both are part of the image cache's key, so an icon a stream has loaded shows in Saved straight away. The row reads the memory cache while drawing rather than after its first frame.saveWithDetails, from Give saved posts their site icon, tags and comment count Automattic/wordpress-rs#1734), so Saved doesn't show an empty row until the next refresh. They only fill in what the cache doesn't have, and the saved list's copy replaces them on the next refresh.Moving existing saves to the account
isSavedForLaterare sent to it in one import, in the order the old Saved screen showed them (sortRank, newest first). The app records the import per account inUserDefaultsand doesn't repeat it. wordpress-rs imports whenever it's asked, so a repeat would bring back posts unsaved since. Signing out clears the record.savesWaitingForRoom(), read again whenever the list reloads, so the banner goes away once the saves are sent. The same applies to a save made offline that the server refuses for the cap when it syncs.reader_saved_posts_account_import, records how the import ended: counts of local, imported, refused, pending, waiting-for-room and unsaveable saves, or an error kind. It holds no URLs or titles.Other changes
removeWordpressComAccount).ReaderSavedPostsViewController.storedPost(for:in:)), as the old Saved stream did. It opens straight away and works offline. Other posts are still fetched by their IDs first.toggleSavedForLaterForPost:), the old Saved stream as a destination, and the "saved posts don't sync" copy.ReaderPosttype, so the three files that import both it and WordPressData name the Core Data classWordPressData.ReaderPost.Known gaps
ReaderContentType.savedand its branches inReaderStreamViewControllerare now unused. Removing them means reworking that screen's content types, so it's left for a follow-up.Screenshots
The saved posts are placeholder data, injected with a temporary patch for these screenshots.
What I ran
After rebasing on trunk
1f4ba93afe(which includes #26420), this branch (7224f6cff1), wordpress-rs 0.11.1, a new iPhone 18 Pro simulator (iOS 27.2):ReaderSavedPostsSyncTests,ReaderSavedPostsStoreTests,ReaderSavedPostsViewModelTests,ReaderSavedPostsExporterTests,ReaderSidebarSavedTests,ReaderPostToolbarBookmarkTestsTest run with 72 tests in 6 suites passedReaderDetailCoordinatorTestsExecuted 15 tests, with 0 failures** BUILD SUCCEEDED **ReaderSavedPostsCacheTests(before the rebase,2b3fe1d74d, 0.11.0)Test run with 1 test in 1 suite passedReaderSavedPostsStoreTests, 15 runs in a row (before the rebase,a9de039dcf)Earlier, on the PR build of wordpress-rs:
ReaderDetailToolbarTests,ReaderPostToolbarBookmarkTestsandReaderNotificationsBellTestspassed, as didAccountServiceTests,ReaderPresenterTestsandReaderStreamViewControllerTests(Executed 24 tests, with 0 failures). They weren't rerun on 0.11.0, which changes nothing they use.Regression tests that fail without their fix: signing out while a bookmark is on screen doesn't bring the account back (
noSessionWhileSigningOut), export includes pages that weren't loaded (exportLoadsEveryPage), and export includes every save of an account at the cap (exportLoadsAFullAccount: with the old 50-page limit it fails withExpectation failed: posts.count == 1000).Testing instructions
Checked on the simulator with a real WordPress.com account. Its saved list was the same before and after every check. Items marked (
7224f6cff1) were checked on this branch's head, on wordpress-rs 0.11.1; items marked (0.11.0) on the build before the rebase; the rest on the PR build of wordpress-rs, and the app code they use didn't change since except where noted.(
7224f6cff1) Tony's steps for a page saved by URL. The account was at its cap: 999 pages saved by URL and one post. Export wrote all 1,000 saves (272 KB); the page's entry has no IDs. After removing the page in Saved (server: 999), importing the file from Files reported “1 imported, 999 skipped, 0 failed”, the page was back at the top of Saved, and the server's saved keys matched the snapshot taken before the check. Before this fix, the same steps gave “0 imported, 2 skipped, 1 failed” and “Post not found”.(
7224f6cff1) Export at the cap. The first export on this build wrote only 500 of the 1,000 saves, which found the 10-a-page bug fixed in7224f6cff1; after the fix it wrote 1,000.(
7224f6cff1) Banner for saves waiting for room. With the account at its cap, importing a file with one new post reported “1 imported”; the cache had itwaiting_for_room, the server didn't, and Saved showed the banner with “1 post”. Removing a save in Saved made room: the waiting save reached the server within 10 seconds and the banner went away. The account was then put back as it was. The waiting post itself is listed last, because an imported save has no date (see Known gaps).(
7224f6cff1) Opening a saved post from the device. A post saved from Discover (opened once, so it's in Core Data) opens from Saved with its title, author and image already shown after 1 second. Relaunched with-wpcom-api-base-url http://127.0.0.1:9, so every WordPressKit request fails, it still opens from Saved with its full content. The same post opened by its IDs through ajpdebug:///read/blogs/…/posts/…link shows “Error Loading Post”, which is what Saved showed before this change. The test save was removed afterwards. The offline save at the cap that ends up waiting for room (Tony's issue 2) wasn't reproduced on the simulator; the import above puts a save in the samewaiting_for_roomstate.(0.11.0) A fresh install loads Saved from the 0.11.0 cache, with the account's saves.
(0.11.0) Saving with the account at its 1,000-save cap. The test account was at the cap. Tapping a Discover post's bookmark shows “Could not save post for later. You've reached the limit of 1,000 saved posts. Remove some to save more.” The bookmark stays empty, and the server's saved keys are unchanged.
(0.11.0) JSON import with the account at its cap. Importing a file with one new post reports "1 imported, 0 skipped, 0 failed". The cache has the post saved, listed and
waiting_for_room, and the server's saved keys are unchanged. The app was deleted afterwards, so the waiting save was never sent.Upgrade with local saves (PR build). Install trunk, save two posts, then install this build over it. The app log shows
imported 2, refused 0and onereader_saved_posts_account_importevent; Saved shows both posts in the old screen's order without a pull to refresh; the server's saved keys include them. A second launch doesn't import again. On 0.11.0 the app, not wordpress-rs, remembers the import; that's covered byimportRunsOnce,concurrentStartsImportOnceandremoveAccountForgetsTheImport, not rechecked on the simulator.Save and unsave from a stream. The bookmark fills in, the post appears at the top of Saved, and the post screen's toolbar shows it as saved. Swiping to remove takes it off the list and the stream's bookmark empties.
Offline relaunch. With the app's WordPress.com requests blocked, Saved still shows the list from disk.
Save offline, then sync on coming to the foreground. With the saved posts requests refused by a local proxy (a temporary, uncommitted hook in a Jetpack build), saving a Discover post fills its bookmark and puts it at the top of Saved in full, while the server's saved keys stay unchanged. Back online with the app left open, nothing is sent for 30 seconds; sending the app to the background and back sends the save within 2 seconds. Unsaving both test posts online put the server's keys back exactly as they were. The "back online" trigger wasn't exercised on a real network change, because the simulator shares the Mac's network; it's covered by
reachabilitySyncs.Sign out with a Reader stream on screen. Every Reader table and
wordpress_com_accountsin the cache has 0 rows afterwards (read withsqlite3), and signing back in brings the list back.A feed item and a page saved by URL both open from Saved; the URL opens in the in-app web view.
Signed out with only a self-hosted site (a local WordPress Playground site): App Settings has no Saved Posts row. The Reader tab shows its "Sign in with a WordPress.com account" screen, and a deep link to a post lands there too, so the sidebar and bookmark hiding is only a fallback (covered by
ReaderSidebarSavedTestsandReaderPostToolbarBookmarkTests).JSON import and export (PR build; the import now goes through
importSaves, checked at the cap above). Export writes every saved post to its own temp folder. On this build, importing a file with an already-saved post, a new public post and a page saved by URL: the first run reported "1 imported, 2 skipped, 0 failed" and found a bug, a page saved by URL wasn't saved. The fix then covered only a page saved moments before the export; a page the server had already sent still failed, which Tony found andbe66c4a7fafixes (checked above). After the first fix, the page is imported and shows at the top of Saved straight away, with no pull to refresh. The test saves and the file were removed afterwards, and the server's saved keys match what they were before.Site icon, tags and comment count. With a WordPress.com Blog post and a Verge RSS post saved for the check (and removed afterwards), the WordPress.com post shows its site icon,
#chatgpt #claude #mcpand "8 comments". The Verge post shows the feed's image and no comment count. The older WordPress.com save shows its site icon and tag.Save from Discover, then open Saved straight away. The new row already shows its site name, title, excerpt, tags and comment count; after the refresh it has the server's tags and the saved date. The test save was removed afterwards.
A post with no featured image (“Caption Demo”, whose author set none) shows the same image in Saved as on its Reader card.
Paging in the Saved list: not checked in the app, because the test account has only one saved post. Covered by
ReaderSavedPostsViewModelTestsand the export paging test.