Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [*] Notifications: Comment and like notifications from private sites you can't access now show their content instead of an error [#26432]
* [*] Support: The chat keyboard's return key no longer looks like a send button [#26451]
* [*] Support: A conversation now has a title in the navigation bar, and its subject reads above the status instead of below it
* [*] [internal] Experimental Gutenberg editor: turn on "Use Third-Party Blocks (Beta)" by default, matching Android [#26468]


27.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,53 @@ final class EditorConfigurationPluginsTests {
#expect(capability.shouldApplyInEditor == false)
}

@Test("Available when the site has not been probed yet, so the setting stays reachable")
func availableWhenNotYetProbed() throws {
/// GutenbergKit fails to load the editor, rather than falling back, when a site lacks the
/// `editor-assets` route, so plugins wait for the probe to confirm support.
@Test("Unverified when the site has not been probed yet: the row stays reachable, the editor loads no plugins")
func unverifiedWhenNotYetProbed() throws {
let blog = makeSimpleBlog()

#expect(settings.hasProbedSupport(for: .editorAssets, blog: blog) == false)

let capability = resolve(for: blog)

#expect(capability == .available(false))
#expect(capability == .unverified(true))
#expect(capability.isVisibleInSiteSettings == true)
#expect(capability.isInteractive == true)
#expect(capability.shouldApplyInEditor == false)
}

@Test("Unverified keeps the user's opt-out")
func unverifiedKeepsOptOut() throws {
let blog = makeSimpleBlog()
settings.setThirdPartyBlocksEnabled(false, for: blog)

#expect(resolve(for: blog) == .unverified(false))
}

// MARK: - User preference

@Test("Defaults to off, so a capable site does not load plugins until the user opts in")
func defaultsToDisabled() throws {
@Test("Defaults to on, so a capable site loads plugins unless the user opts out")
func defaultsToEnabled() throws {
let blog = makeSimpleBlog()
let settings = settings
settings.setSupports(.editorAssets, true, for: blog)

let capability = resolve(for: blog)

#expect(capability == .available(true))
#expect(capability.shouldApplyInEditor == true)
}

@Test("Respects an explicit opt-out")
func respectsExplicitOptOut() throws {
let blog = makeSimpleBlog()
let settings = settings
settings.setSupports(.editorAssets, true, for: blog)
settings.setThirdPartyBlocksEnabled(false, for: blog)

let capability = resolve(for: blog)

#expect(capability == .available(false))
#expect(capability.shouldApplyInEditor == false)
}
Expand Down Expand Up @@ -211,7 +236,7 @@ final class EditorConfigurationPluginsTests {

@Test("Preference is stored per site")
func preferenceIsPerSite() throws {
let enabledBlog = makeSimpleBlog()
let disabledBlog = makeSimpleBlog()
let otherBlog = withPermanentID(
BlogBuilder(context)
.with(atomic: false)
Expand All @@ -223,12 +248,12 @@ final class EditorConfigurationPluginsTests {
)

let settings = settings
settings.setSupports(.editorAssets, true, for: enabledBlog)
settings.setSupports(.editorAssets, true, for: disabledBlog)
settings.setSupports(.editorAssets, true, for: otherBlog)
settings.setThirdPartyBlocksEnabled(true, for: enabledBlog)
settings.setThirdPartyBlocksEnabled(false, for: disabledBlog)

#expect(resolve(for: enabledBlog) == .available(true))
#expect(resolve(for: otherBlog) == .available(false))
#expect(resolve(for: disabledBlog) == .available(false))
#expect(resolve(for: otherBlog) == .available(true))
}

// MARK: - Editor entry point
Expand All @@ -244,17 +269,17 @@ final class EditorConfigurationPluginsTests {
for: blog,
settings: settings,
isFeatureFlagEnabled: true
) == false
) == true
)

settings.setThirdPartyBlocksEnabled(true, for: blog)
settings.setThirdPartyBlocksEnabled(false, for: blog)

#expect(
EditorConfiguration.shouldEnablePlugins(
for: blog,
settings: settings,
isFeatureFlagEnabled: true
) == true
) == false
)
}

Expand Down Expand Up @@ -290,9 +315,60 @@ final class EditorConfigurationPluginsTests {
let blog = makeSimpleBlog()
let settings = settings
settings.setSupports(.editorAssets, true, for: blog)
settings.setThirdPartyBlocksEnabled(true, for: blog)
// Opt out, since an opt-in would match the default and pass even if the flag cycle erased it.
settings.setThirdPartyBlocksEnabled(false, for: blog)

#expect(resolve(for: blog, isFeatureFlagEnabled: false) == .hidden)
#expect(resolve(for: blog, isFeatureFlagEnabled: true) == .available(true))
#expect(resolve(for: blog, isFeatureFlagEnabled: true) == .available(false))
}

// MARK: - Editor configuration capabilities

@Test("Confirming third-party block support changes the editor configuration capabilities")
func confirmingThirdPartyBlocksChangesCapabilities() throws {
let blog = makeSimpleBlog()
let settings = settings
let unprobed = settings.editorConfigurationCapabilities(for: blog)

settings.setSupports(.editorAssets, true, for: blog)

#expect(settings.editorConfigurationCapabilities(for: blog) != unprobed)
}

@Test("Confirming theme style support changes the editor configuration capabilities")
func confirmingThemeStylesChangesCapabilities() throws {
let blog = makeSimpleBlog()
let settings = settings
let unprobed = settings.editorConfigurationCapabilities(for: blog)

settings.setSupports(.blockEditorSettings, true, for: blog)

#expect(settings.editorConfigurationCapabilities(for: blog) != unprobed)
}

/// An unprobed site already prepares the editor without theme styles or third-party blocks, so
/// a probe that finds no support leaves the prepared dependencies valid.
@Test("Finding no support leaves an unprobed site's editor configuration capabilities unchanged")
func findingNoSupportKeepsCapabilities() throws {
let blog = makeSimpleBlog()
let settings = settings
let unprobed = settings.editorConfigurationCapabilities(for: blog)

settings
.setSupports(.blockEditorSettings, false, for: blog)
.setSupports(.editorAssets, false, for: blog)

#expect(settings.editorConfigurationCapabilities(for: blog) == unprobed)
}

@Test("A block theme doesn't change the editor configuration capabilities")
func blockThemeKeepsCapabilities() throws {
let blog = makeSimpleBlog()
let settings = settings
let unprobed = settings.editorConfigurationCapabilities(for: blog)

settings.setSupports(.blockTheme, true, for: blog)

#expect(settings.editorConfigurationCapabilities(for: blog) == unprobed)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ extension EditorConfiguration {
/// plugins providing blocks.
///
/// Requires the remote feature flag, a site that can support the feature, and the user's
/// per-site opt-in. See `GutenbergSettings.resolveThirdPartyBlocks(for:)`.
/// per-site preference, which defaults to on.
/// See `GutenbergSettings.resolveThirdPartyBlocks(for:)`.
static func shouldEnablePlugins(
for blog: Blog,
appPassword: String? = nil,
Expand Down
26 changes: 22 additions & 4 deletions WordPress/Classes/Utility/Editor/EditorDependencyManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ final class EditorDependencyManager: Sendable {
_prefetchDependencies(for: blog, postType: postType)
}

@MainActor
@discardableResult
private func _prefetchDependencies(for blog: Blog, postType: PostTypeDetails) -> Task<Void, Never>? {
let key = CacheKey(blog: blog, postType: postType)
Expand All @@ -123,10 +124,16 @@ final class EditorDependencyManager: Sendable {
return nil
}

let configuration = EditorConfiguration(blog: blog, postType: postType)
let service = EditorService(configuration: configuration)
// Starts the probe now, so it runs alongside any other probe for this site.
let probe = capabilityTask(for: blog)

let task = Task {
// The configuration waits for the probe, because the cache ignores the configuration it
// was built with: an unprobed site would cache dependencies without third-party blocks.
await probe.value
let configuration = EditorConfiguration(blog: blog, postType: postType)
let service = EditorService(configuration: configuration)

do {
let dependencies = try await service.prepare()
self.state.withLock { state in
Expand Down Expand Up @@ -246,7 +253,8 @@ final class EditorDependencyManager: Sendable {
///
/// This method:
/// 1. Performs WebKit warmup (once per blog) - pre-compiles HTML/JS (~100-200ms savings)
/// 2. Prefetches editor dependencies - fetches settings, assets, preload list
/// 2. Prefetches editor dependencies - refreshes the site's editor capabilities, then fetches
/// settings, assets, preload list
///
/// Safe to call multiple times - internally handles deduplication.
@MainActor
Expand Down Expand Up @@ -304,10 +312,20 @@ final class EditorDependencyManager: Sendable {
let hasBlockSettings = try await client.supports(.blockEditorSettings, forSiteId: siteId)
let supportsEditorAssets = try await client.supports(.editorAssets, forSiteId: siteId)

GutenbergSettings()
let settings = GutenbergSettings()
let previousCapabilities = settings.editorConfigurationCapabilities(for: blog)

settings
.setSupports(.blockEditorSettings, hasBlockSettings, for: blog)
.setSupports(.blockTheme, hasBlockTheme, for: blog)
.setSupports(.editorAssets, supportsEditorAssets, for: blog)

// The cache ignores the configuration its dependencies were prepared with, so dependencies
// prepared before this probe, e.g. while a failed probe left the site unverified, would
// otherwise keep the editor without theme styles or third-party blocks.
if settings.editorConfigurationCapabilities(for: blog) != previousCapabilities {
await invalidate(for: TaggedManagedObjectID(blog))
}
}

/// Query the server for its editor capabilities, and update the local editor settings store with the result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ enum ThirdPartyBlocksCapability: Equatable {
/// The site supports third-party blocks. The associated value is the user's preference.
case available(Bool)

/// The site hasn't been probed for support yet. The row stays interactive, but the editor
/// loads no third-party blocks until the probe confirms support. The associated value is the
/// user's preference.
case unverified(Bool)

/// Whether the editor should load third-party blocks.
///
/// True only for `.available(true)` — the collapsed form of the precedence table.
var shouldApplyInEditor: Bool {
switch self {
case .hidden, .unsupported:
case .hidden, .unsupported, .unverified:
return false
case .available(let isEnabled):
return isEnabled
Expand All @@ -37,7 +42,7 @@ enum ThirdPartyBlocksCapability: Equatable {
switch self {
case .hidden:
return false
case .unsupported, .available:
case .unsupported, .available, .unverified:
return true
}
}
Expand All @@ -47,7 +52,7 @@ enum ThirdPartyBlocksCapability: Equatable {
switch self {
case .hidden, .unsupported:
return false
case .available:
case .available, .unverified:
return true
}
}
Expand All @@ -59,14 +64,14 @@ extension GutenbergSettings {
/// Precedence:
/// 1. Remote flag off → `.hidden`
/// 2. Site can't authenticate non-core block requests → `.unsupported`
/// 3. Site doesn't advertise the `editor-assets` route → `.unsupported`
/// 4. Otherwise → `.available(userPreference)`
/// 3. Site hasn't been probed yet → `.unverified(userPreference)`
/// 4. Site doesn't advertise the `editor-assets` route → `.unsupported`
/// 5. Otherwise → `.available(userPreference)`
///
/// A site whose capability has not been probed yet is treated as supported rather than
/// unsupported. The probe is fire-and-forget (see `EditorDependencyManager`), so it may not
/// have completed — or, on a fresh install, run at all — by the time this is called. Assuming
/// support keeps the setting reachable; the editor still degrades gracefully if the route is
/// genuinely absent, whereas assuming the opposite would disable the row on capable sites.
/// The probe is fire-and-forget (see `EditorDependencyManager`), so it may not have completed,
/// or may have failed, by the time this is called. An unprobed site keeps the row reachable but
/// loads no third-party blocks, matching Android: GutenbergKit fails to load the editor, rather
/// than falling back, when the `editor-assets` route is missing.
///
/// - Parameters:
/// - blog: The blog to resolve the capability for
Expand Down Expand Up @@ -97,9 +102,11 @@ extension GutenbergSettings {
return .unsupported
}

// Treat "not probed yet" as supported — see the note above.
let hasProbed = hasProbedSupport(for: .editorAssets, blog: blog)
guard !hasProbed || getSupports(.editorAssets, for: blog) else {
guard hasProbedSupport(for: .editorAssets, blog: blog) else {
return .unverified(isThirdPartyBlocksEnabled(for: blog))
}

guard getSupports(.editorAssets, for: blog) else {
return .unsupported
}

Expand Down Expand Up @@ -148,7 +155,8 @@ extension GutenbergSettingsBridge {
switch GutenbergSettings().resolveThirdPartyBlocks(for: blog) {
case .hidden: return .hidden
case .unsupported: return .unsupported
case .available: return .available
// The row is interactive for an unverified site, too.
case .available, .unverified: return .available
}
}

Expand Down
25 changes: 23 additions & 2 deletions WordPress/Classes/Utility/Editor/GutenbergSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,16 @@ class GutenbergSettings {
/// remote feature flag and on the site advertising the capability.
///
/// - Parameter blog: The blog to check the third-party blocks setting for
/// - Returns: true if the user opted in, false otherwise (default: false)
/// - Returns: false if the user opted out, true otherwise (default: true)
func isThirdPartyBlocksEnabled(for blog: Blog) -> Bool {
database.bool(forKey: Key.thirdPartyBlocksEnabled(forBlogURL: blog.url))
let key = Key.thirdPartyBlocksEnabled(forBlogURL: blog.url)

// On by default so rolling out the new editor keeps the plugin blocks sites rely on.
guard database.hasEntry(forKey: key) else {
return true
}

return database.bool(forKey: key)
}

/// Sets whether third-party blocks are enabled for the given blog.
Expand Down Expand Up @@ -330,6 +337,20 @@ class GutenbergSettings {
func hasProbedSupport(for feature: WordPressClient.Feature, blog: Blog) -> Bool {
database.object(forKey: Key.supports(feature, forBlog: blog)) != nil
}

/// The stored capabilities that shape the editor configuration: theme styles and third-party
/// blocks. Editor dependencies prepared with different values are stale.
func editorConfigurationCapabilities(for blog: Blog) -> EditorConfigurationCapabilities {
EditorConfigurationCapabilities(
supportsThemeStyles: getSupports(.blockEditorSettings, for: blog),
supportsThirdPartyBlocks: getSupports(.editorAssets, for: blog)
)
}
}

struct EditorConfigurationCapabilities: Equatable {
let supportsThemeStyles: Bool
let supportsThirdPartyBlocks: Bool
}

@objc(GutenbergSettings)
Expand Down