Skip to content

Conversation

@kean
Copy link
Contributor

@kean kean commented Nov 20, 2025

What?

The demo app will now honor site's block editor settings (wp-block-editor/v1/settings).

Why?

The idea is to use the newly introduced EditorService to manage the initial load and subsequent refresh of all resources required to launch the editor: editor settings and assets.

In the future PRs, I plan to simplify the code in EditorAssetsLibrary and move it to EditorService. It will fetch the manifest and the assets before "starting" the editor and will inject the preprocessed manifest using the configuration. This will give the host app control over when and how the assets are loaded and stored. With the new implementation, the requests will run in parallel, cutting the first load time by around 900ms (due to parallelization alone).

I will then generate the Android implementation based on the Swift code.

How?

The new EditorService provides two simply APIs for the host app.

The setup method is what you call to configure the editor. On first load, it will fetch the required resources (blocking operation). On the subsequent loads, it will simply use the previously loaded data (changes infrequently). It's up to the app how to handle errors.

public func setup(_ configuration: inout EditorConfiguration) async throws

The host app will also be responsible for calling refresh to update the previously fetched resources (or load the initial ones). It's safe to call refresh multiple times as it will attach to the existing task if present. It's up to the app how to handle errors.

public func refresh() async throws

Testing Instructions

Add a new "remote" editor and verify that the styles are applied.

Screenshots or screencast

Before / After
Screenshot 2025-11-20 at 12 41 36 PM Screenshot 2025-11-20 at 12 41 05 PM

@kean kean force-pushed the task/editor-settings branch from 17e0732 to 4f0d2e8 Compare November 20, 2025 17:55
/// let safeName = url.safeFilename
/// // Result: "https---example.com-path-query-1"
/// ```
var safeFilename: String {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could just replace it with sha256 as the folder name is only needed for technical purposes. wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, hashing is likely sufficient for this purpose.

A readable name might make debugging easier, but that'd likely be infrequent and manageable.

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 was also leaning towards hashing. It's simpler and more robust.

@kean kean requested a review from dcalhoun November 20, 2025 17:58
@kean kean force-pushed the task/editor-settings branch from 4f0d2e8 to 5ef6674 Compare November 20, 2025 18:01
@kean
Copy link
Contributor Author

kean commented Nov 20, 2025

Oh, actually, I'll call setup automatically in EditorViewController. The host app will just need to know about the refresh.

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.

Very nice!

I suppose we could consider adding a Use theme styles toggle beneath the Native Inserter toggle, if helpful.

do {
try await service.setup(&updatedConfiguration)
} catch {
print("Failed to setup editor environment, confinuing with the default or cached configuration:", error)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print("Failed to setup editor environment, confinuing with the default or cached configuration:", error)
print("Failed to set up editor environment, continuing with the default or cached configuration:", error)

/// let safeName = url.safeFilename
/// // Result: "https---example.com-path-query-1"
/// ```
var safeFilename: String {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, hashing is likely sufficient for this purpose.

A readable name might make debugging easier, but that'd likely be infrequent and manageable.

self.authHeader = authHeader
self.urlSession = urlSession

self.storeURL = URL.documentsDirectory
Copy link
Contributor Author

@kean kean Nov 21, 2025

Choose a reason for hiding this comment

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

This should go into "Application" not "Documents".

@kean
Copy link
Contributor Author

kean commented Nov 21, 2025

Use theme styles toggle beneath the Native Inserter toggle, if helpful.

Good idea. It's a bit difficult due to how it's currently structured. I'll add a note to add it after other changes are done.
I'm still thinking about adding a "Preferences" panel. You need a discoverable way to toggle it quickly, and we might use it to show Gutenberg version and information about plugins as a starter.

Co-authored-by: David Calhoun <github@davidcalhoun.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants