Skip to content

Consolidate the Spotlight open path - #25991

Open
crazytonyli wants to merge 4 commits into
task/spotlight-index-fixesfrom
task/spotlight-open-path-cleanup
Open

crazytonyli wants to merge 4 commits into
task/spotlight-index-fixesfrom
task/spotlight-open-path-cleanup

Conversation

@crazytonyli

@crazytonyli crazytonyli commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Opening a Spotlight result currently uses separate callback-based paths for WP.com and self-hosted posts, with duplicate navigation logic for posts and pages.

This PR:

  1. Makes SearchIdentifierGenerator.decomposeFromUniqueIdentifier(_:) reject malformed and unknown identifiers.
  2. Adds AbstractPost.SearchIdentifier to resolve the exact site and post for WP.com and self-hosted sites.
  3. Routes Spotlight results through openItem(withUniqueIdentifier:), with shared post and page navigation. It opens cached posts immediately, fetches missing posts, and rejects trashed posts.

Testing instructions

  • Open published and draft posts and pages from Spotlight on WP.com and self-hosted sites.
  • Open a Spotlight result for a post that is not cached locally.
  • Verify invalid or stale Spotlight results do not navigate or crash.

@dangermattic

dangermattic commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@crazytonyli crazytonyli changed the title task/spotlight open path cleanup Consolidate the Spotlight open path Sep 4, 2026
@crazytonyli
crazytonyli requested a review from jkmassel September 4, 2026 01:28
@crazytonyli crazytonyli added this to the 27.3 milestone Sep 4, 2026
@crazytonyli
crazytonyli marked this pull request as ready for review September 4, 2026 01:29
@wpmobilebot

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number34374
VersionPR #25991
Bundle IDcom.jetpack.alpha
Commit4d8ee7c
Installation URL7taeb88e14s7g
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
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number34374
VersionPR #25991
Bundle IDorg.wordpress.alpha
Commit4d8ee7c
Installation URL26pum17qb0tkg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot wpmobilebot modified the milestones: 27.3, 27.4 Sep 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.3 has now entered code-freeze, so the milestone of this PR has been updated to 27.4.

@wpmobilebot wpmobilebot modified the milestones: 27.4, 27.5 Oct 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.4 has now entered code-freeze, so the milestone of this PR has been updated to 27.5.

@crazytonyli
crazytonyli force-pushed the task/spotlight-open-path-cleanup branch from 4d8ee7c to 5d2f861 Compare October 28, 2026 21:51
return
// A cached copy opens immediately; the network fetch covers posts
// that are indexed but no longer cached locally.
if let post = identifier.post(in: coreDataStack.mainContext) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Finding from Claude:

Tapping a draft in Spotlight can open an out-of-date copy of it. If the draft was changed on the web since the app last synced it, the editor shows the old content.

What happens

fetchPost now returns the post saved on the device whenever there is one, and only asks the server when there isn't. Before this PR, the app always fetched the post from the server first (PostRepository.getPost), which also updated the saved copy.

Who is affected

Anyone who changes a draft on the web or on another device, then opens it from Spotlight before the app syncs it. Spotlight skips the post list, so the app gets no chance to sync first.

What they see

The editor opens with the old content. The app also picks the screen from the saved status, so a draft that was published on the web should open in the editor instead of the preview. That status case was not reproduced; it goes through the same lookup.

How this was checked

PR head 5d2f861, WordPress app, iPhone 18 Pro simulator on iOS 27.0, local self-hosted site.

  1. Created a draft, signed in, and opened Posts → Drafts, so the draft was saved on the device and indexed in Spotlight.
  2. Changed the draft's body through the REST API, standing in for a web edit.
  3. Searched Spotlight for the draft and tapped the result.
Body
Server, after the edit NEW body edited on the web
Editor, opened from Spotlight OLD draft body from before the web edit

Editor opened from Spotlight, showing the old draft body

Not checked: trunk on the simulator (that trunk refreshes the post comes from reading the code), the status-change cases, and what happens if the stale draft is saved.

Worth fixing in this PR: fetch the post from the server first, and fall back to the saved copy only when that fails, for example when offline. That keeps this PR's offline improvement, and the trash check would then see the server's status too.

@crazytonyli
crazytonyli requested a review from jkmassel November 8, 2026 20:32
@wpmobilebot

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

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

…ifier type

Identifiers arrive from the system through Spotlight activities, so the
composite format cannot be assumed. Decomposition now returns nil for a
malformed identifier or an unknown item type instead of indexing past the
end of the components. A post identifier type parses a post's composite
identifier into its site domain and post ID, and resolves the site by WP.com
ID or xmlrpc URL and the cached post from it.
Route every Spotlight tap through one async open method that resolves the
identifier, fetches the post from the cache first and the network second,
refuses trashed posts, and reports whether anything was put on screen. The
activity handler validates the identifier up front and dispatches the open,
so a malformed identifier is rejected instead of misrouted. Post and page
navigation share one method, and the Reader helpers return a result instead
of taking failure closures.
Opening the saved copy first showed edits made on the web only after the
next sync, and chose the screen and the trash check from a stale status.
The server copy is fetched first again; the saved copy is the fallback
when the server can't be reached, and a post deleted on the server opens
nothing.
@crazytonyli
crazytonyli force-pushed the task/spotlight-open-path-cleanup branch from 9a02d26 to 54769e2 Compare November 17, 2026 01:35
@wpmobilebot wpmobilebot modified the milestones: 27.5, 27.6 Nov 20, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.5 has now entered code-freeze, so the milestone of this PR has been updated to 27.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants