Skip to content

Conversation

@crazytonyli
Copy link
Contributor

@crazytonyli crazytonyli commented Feb 3, 2026

Description

This PR expands editor cache management to all post types. With the integration of wordpress-mobile/GutenbergKit#299, we can now edit custom posts in the GBK editor.

Testing instructions

Verify the GBK editor continues to work with regular posts and pages.

Verify you can edit custom posts (available in self-hosted sites) using the GBK editor.

@dangermattic
Copy link
Collaborator

dangermattic commented Feb 3, 2026

2 Warnings
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 3, 2026

🤖 Build Failure Analysis

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

Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

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

I perceive the draft status and current code to mean this is not ready for formal review. Regardless, I left a few thoughts for consideration from an initial review and testing.

Overall, things seem to operate relatively well. I noted one preexisting bug: CMM-1214

To elaborate on my original request for an integration PR, I primarily wanted to ensure an integration would merge relatively quickly after we merge the GutenbergKit (GBK) PR to avoid breaking changes in the GBK library blocking other GBK work. Sorry if I did not communicate that clearly enough previously. Thank you for beginning this work nonetheless.

.package(url: "https://github.com/wordpress-mobile/NSURL-IDN", revision: "b34794c9a3f32312e1593d4a3d120572afa0d010"),
.package(url: "https://github.com/zendesk/support_sdk_ios", from: "8.0.3"),
.package(url: "https://github.com/wordpress-mobile/GutenbergKit", from: "0.13.1"),
.package(url: "https://github.com/wordpress-mobile/GutenbergKit", revision: "7a48d8756f33e3d25daa1fff5843d5cd6fdda887"),
Copy link
Member

Choose a reason for hiding this comment

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

When we are ready, we can integrate a GBK prerelease. We'll publish the prerelease via make release VERSION_TYPE=preminor DRY_RUN=true on GBK's trunk branch.

let configuration = EditorConfigurationBuilder(
content: initialContent ?? "",
postType: "comment",
postType: .init(postType: "comment", restBase: "comments"), // FIXME: "comment" is not a post type.
Copy link
Member

Choose a reason for hiding this comment

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

If we feel compelled to "fix" the post type, we might also consider fixing the site URL and API root. GBK currently requires all of these, but effectively discards them when "offline mode" is enabled.

For context, this comment editor is currently unused.

@crazytonyli
Copy link
Contributor Author

I primarily wanted to ensure an integration would merge relatively quickly after we merge the GutenbergKit (GBK) PR to avoid breaking changes in the GBK library blocking other GBK work.

Absolutely. I will not merge the GBK PR until this PR is ready.

@crazytonyli crazytonyli changed the title Prototype custom post types local Support editing custom posts Feb 4, 2026
@crazytonyli crazytonyli force-pushed the prototype-custom-post-types-local branch 2 times, most recently from 6a6c440 to 33deb2f Compare February 8, 2026 21:32
@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 8, 2026

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 Number30868
VersionPR #25208
Bundle IDorg.wordpress.alpha
Commitae4dca3
Installation URL2sa4imkfa7090
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Feb 8, 2026

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 Number30868
VersionPR #25208
Bundle IDcom.jetpack.alpha
Commitae4dca3
Installation URL3hequ9c0t0g10
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

Base automatically changed from prototype-custom-post-types to trunk February 10, 2026 03:29
@crazytonyli crazytonyli force-pushed the prototype-custom-post-types-local branch from 8e6668a to 8a4c6b0 Compare February 10, 2026 07:36
@crazytonyli crazytonyli added this to the 26.7 milestone Feb 10, 2026
@crazytonyli crazytonyli marked this pull request as ready for review February 10, 2026 07:44
Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

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

These changes tested well for me overall. I was able to create/edit/update/publish posts, pages, and "books" post types.

I left a few inline suggestions and questions worth considering.

Also, I note the CPT header lacks bottom padding matching the post/page header. Additionally, the CPT more menu does not support all the options of the post/page header, but this may already be a known limitation. See images below.

CPT vs post header
CPT Post
Image Image
Image Image


/// Cached dependencies keyed by blog's ObjectID string representation.
private let cache = LockingHashMap<EditorDependencies>()
private let state = OSAllocatedUnfairLock(initialState: State())
Copy link
Member

Choose a reason for hiding this comment

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

This is nice. Learning a lot from these changes.

Comment on lines 269 to 276
state.featureFlagObserver = NotificationCenter.default
.publisher(for: FeatureFlagOverrideStore.didChangeNotification)
.filter { ($0.userInfo?[FeatureFlagOverrideStore.notificationFeatureFlagKey] as? String) == RemoteFeatureFlag.newGutenberg.key }
.sink { [weak self] _ in
Task {
await self?.invalidateAll()
}
}
Copy link
Member

Choose a reason for hiding this comment

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

From my testing, this is never triggered when toggling the feature flag.

if prefetchTasks[key] != nil {
return nil
}
let shouldStartPrefetch = state.withLock { state -> Bool in
Copy link
Member

Choose a reason for hiding this comment

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

Claude noted the following, which seems legitimate. What do you think?

There's a check-then-act race in this method (and the same pattern repeats in invalidate(for:) and fetchEditorCapabilities(for:)): shouldStartPrefetch is evaluated in one state.withLock call, but the task isn't stored until a separate state.withLock at the bottom. Between the two, another caller on a different thread could also pass the guard and start a duplicate task.

One fix would be to set a placeholder in the first lock to reserve the slot (e.g. store a not-yet-started sentinel), or restructure so the task is created and stored within a single locked section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that makes sense. The same issue exists in the original code. I think it's a reasonable compromise to avoid overly complicated code. When the race condition occurs, the "preparing editor" code runes more than once, which is harmless. I'd be more careful if the task is writing data to the user's site.

self?.navigationController?.dismiss(animated: true)
}
if post.status == .draft {
alert.addAction(UIAlertAction(title: Strings.saveDraft, style: .default, handler: { _ in
Copy link
Member

Choose a reason for hiding this comment

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

self is captured strongly here (unlike the [weak self] in the discard handler on line 105). Should we use [weak self] here?

precondition(post.id > 0, "No new post support yet")

if post.status == .draft {
return UIAction(title: "Publish") { [weak self] _ in
Copy link
Member

Choose a reason for hiding this comment

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

Should we localize "Publish" here and "Update" on line 161 now?

Comment on lines 79 to +80
// TODO: Check if the post supports Gutenberg first?
CustomPostEditor(client: client, post: post, details: details, blog: blog) {
Task {
_ = try await service.posts().refreshPost(postId: post.id, endpointType: endpoint)
}
}
CustomPostEditor(client: client, post: post, details: details, blog: blog)
Copy link
Member

Choose a reason for hiding this comment

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

We briefly discussed this before (see p1769044197504499-slack-C08UN8YN6KW), but editing classic posts with GBK is less useful at the moment. How difficult might it be to open these classic CPT entries in Aztec? I'm guessing it may be difficult. Alternatively, should we detect them and disallow editing them and display a more helpful notice?

Custom post type editing only supports posts created with the block editor at this time. This post appears to contain incompatible content.

Classic CPT

Image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! That's related to the TODO in this code. Are there any reasonable ways to detect if the post is "classic"?

@crazytonyli
Copy link
Contributor Author

@dcalhoun Thanks for the review. I have addressed all your comments.

@sonarqubecloud
Copy link

@crazytonyli
Copy link
Contributor Author

Additionally, the CPT more menu does not support all the options of the post/page header, but this may already be a known limitation.

Yeah, we don't support preview and post settings yet.

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