Skip to content

Conversation

@crazytonyli
Copy link
Contributor

@crazytonyli crazytonyli commented Jan 25, 2026

Description

This PR extracts the wiring GBK editor code to a new class PostGBKEditorViewController, which is not now the superclass of the existing NewGutenbergViewController.swift.

There is no much actual code changes other than moving them. However, there is one runtime change (the only one that I noticed): the order of function calls in viewDidLoad: previously, createRevisionOfPost was the first, but now it's the last. I have examined the implementation, and I don't think this change would cause any practical issues.

Note

I highly recommend reviewing this PR commit by commit. You'll see the exact code movement from there.

Testing instructions

Smoke test the GBK editor.

@crazytonyli crazytonyli added this to the 26.7 milestone Jan 25, 2026
@crazytonyli crazytonyli requested a review from kean January 25, 2026 20:11
@sonarqubecloud
Copy link

@dangermattic
Copy link
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

@wpmobilebot
Copy link
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 Number30596
VersionPR #25166
Bundle IDorg.wordpress.alpha
Commitf452c12
Installation URL6pj1pougqhp4g
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
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 Number30596
VersionPR #25166
Bundle IDcom.jetpack.alpha
Commitf452c12
Installation URL6oqrtgu4e9s48
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Contributor

🤖 Build Failure Analysis

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

@kean
Copy link
Contributor

kean commented Jan 26, 2026

This PR extracts the wiring GBK editor code to a new class PostGBKEditorViewController, which is not the superclass of the existing NewGutenbergViewController.swift.

Hey, can you provide a bit of rationale for the change please? What is the problem it solves? Were there alternative options?

@crazytonyli
Copy link
Contributor Author

@kean Sorry, there is a typo there. I meant to write "PostGBKEditorViewController is not now the superclass of the existing NewGutenbergViewController.swift." With that correction, do you have the same questions?

@kean
Copy link
Contributor

kean commented Jan 26, 2026

Yes, what's the goal of extracting a superclass? NewGutenbergViewController and PostGBKEditorViewController is one screen. There is no logical way to extract code from it or split it.

Inheritance, in general, makes code harder to reason about.

@crazytonyli
Copy link
Contributor Author

@kean My bad. I should have included more context in the PR description. I will implement a new post editor, inheriting from the PostGBKEditorViewController, to support editing custom posts (relates to your comment in #25157 (comment)). Soon, we'll be able to reuse the new superclass to support editing both post types, and the UI will look similar to what users are used to.

I don't think it makes sense to add custom post support to the NewGutenbergViewController, which implements PostEditor (tightly coupled with AbstractPost). It's going to be messy to support editing another model (AnyPostWithEditContext from the Rust library). And most importantly, custom post support is very new, and at the moment, there are many things you can do with regular posts and pages that you cannot do with custom posts, like offline editing, updating post settings, viewing revisions, resolving conflicts, etc.

I imagine, in the long run, as we add features to the custom post type support, it will be able to be used to edit regular posts and pages, too. And, by then, we no longer need NewGutenbergViewController.

@kean kean requested a review from dcalhoun January 26, 2026 21:24
@kean
Copy link
Contributor

kean commented Jan 26, 2026

are many things you can do with regular posts and pages that you cannot do with custom posts, like offline editing, updating post settings, viewing revisions, resolving conflicts, etc.

That's a lot of features to re-implement and they all rely on Core Data, just like the rest of the app.

@crazytonyli
Copy link
Contributor Author

I have not looked into all those features, so I can't say for sure. But I don't imagine we'll write brand-new code to reimplement them for custom posts. We have reused the same UI to add tags (Core Data) and custom terms (the Rust library). That'd be the first thing to explore for the custom post features, too.

Copy link
Contributor

@kean kean left a comment

Choose a reason for hiding this comment

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

The PR looks good. I'm give another pass tomorrow to review the remaining bits.

It makes sense to have a component that provides some defaults on top of GBK's ViewController and have different screens that use them. One more area is the "Comment Editor" that isn't completed yet. I would however suggest considering using composition in NewGutenbergViewController – add GBKEditor on top of it.

Copy link
Contributor

@kean kean left a comment

Choose a reason for hiding this comment

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

Hey, I finished the review and added a couple of comments. I assume that the code was moved, so I focused mainly on the overall design.

@dcalhoun, if you also want to weight in, please do.

self.blog = blog
self.navigationBarManager = PostEditorNavigationBarManager()

EditorLocalization.localize = { $0.localized }
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) Should probably bet set once on app launch (existing code)

}
}
/*
Fix issue: Non-'@objc' instance method 'editorDidLoad' declared in 'PostGBKEditorViewController' cannot be overridden from extension
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to eliminate this by moving these methods toe the main class declaration outside of the extension.

  • seealso: Extract the GBK editor parts to a super class #25166 (review). A cleaner way to implement it would probably be by using composition and providing a separate set of customization points in GBKViewController instead of overriding a subset of the existing GutenbergKit.EditorViewControllerDelegate methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally did not change the API in this PR, because the main purpose are 1) to get rid of the new SimpleGBKEditorViewController in #25157, and 2) minimal changes (in terms of runtime behaviour) to the existing code to make PR easier to review and quick to merge.

In future PRs, I'll start using the new super class in the custom post editor, and make further changes to the API.

let blog: Blog
let navigationBarManager: PostEditorNavigationBarManager

/* private */ let editorViewController: GutenbergKit.EditorViewController
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) Are you planning to address these comment before merging?

// MARK: - PostEditorNavigationBarManagerDelegate

var publishButtonText: String {
wpAssertionFailure("To be implemented by subclasses")
Copy link
Contributor

@kean kean Jan 30, 2026

Choose a reason for hiding this comment

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

(nit) This is another area where composition would be probably better/cleaner. I would probably recommend to move PostEditorNavigationBar entirely out of GBKEditorViewController. If we end up using GBKEditorViewController for comments, it won't even use the same navigation bar.

@dcalhoun
Copy link
Member

@dcalhoun, if you also want to weight in, please do.

Thanks for the reminder. I plan to review, but it may be next week. No worries if we need to merge before I provide feedback. This is on my list.

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.

6 participants