diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 439ae0936e76..56b497112e16 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -10,6 +10,7 @@ * [*] Add permalink preview in the slug editor and make other improvements [#24949] * [*] Add "Taxonomies" to Site Settings [#24955] * [*] Update "Categories" picker to indicate multiple selection [#24952] +* [*] Fix rare crash on launch when new editor is enabled [#24944] 26.4 ----- diff --git a/Sources/WordPressData/Swift/NSManagedObject.swift b/Sources/WordPressData/Swift/NSManagedObject.swift index bb9c36ec82e4..b01493d564a1 100644 --- a/Sources/WordPressData/Swift/NSManagedObject.swift +++ b/Sources/WordPressData/Swift/NSManagedObject.swift @@ -15,7 +15,7 @@ public extension NSManagedObject { return result.flatMap({ ValueType(rawValue: $0) }) } - var locallyUniqueId: String { + var locallyUniqueID: String { let data = Data(self.objectID.uriRepresentation().absoluteString.utf8) return SHA256.hash(data: data).compactMap { String(format: "%02x", $0) }.joined() } diff --git a/WordPress/Classes/Services/RawBlockEditorSettingsService.swift b/WordPress/Classes/Services/RawBlockEditorSettingsService.swift index e4234b195fbd..832e0f9031bf 100644 --- a/WordPress/Classes/Services/RawBlockEditorSettingsService.swift +++ b/WordPress/Classes/Services/RawBlockEditorSettingsService.swift @@ -11,9 +11,9 @@ final class RawBlockEditorSettingsService { private var prefetchTask: Task? @MainActor - init(blog: Blog) { - self.dotOrgRestAPI = WordPressOrgRestApi(blog: blog)! - self.blogID = blog.locallyUniqueId + init(dotOrgRestAPI: WordPressOrgRestApi, blog: Blog) { + self.dotOrgRestAPI = dotOrgRestAPI + self.blogID = blog.locallyUniqueID } private func fetchSettingsFromAPI() async throws -> Data { diff --git a/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift b/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift index 3b3209f02140..970a1a1eab0b 100644 --- a/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift +++ b/WordPress/Classes/ViewRelated/Blog/My Site/MySiteViewController.swift @@ -358,7 +358,10 @@ final class MySiteViewController: UIViewController, UIScrollViewDelegate, NoSite let configuration = EditorConfiguration(blog: blog) GutenbergKit.EditorViewController.warmup(configuration: configuration) - RawBlockEditorSettingsService(blog: blog).prefetchSettings() + if let dotOrgRestAPI = WordPressOrgRestApi(blog: blog) { + RawBlockEditorSettingsService(dotOrgRestAPI: dotOrgRestAPI, blog: blog) + .prefetchSettings() + } } // MARK: - Main Blog diff --git a/WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift b/WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift index fca8dff431f9..c05b2a94a132 100644 --- a/WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift +++ b/WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift @@ -145,7 +145,7 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor func setHTML(_ html: String) {} func getHTML() -> String { post.content ?? "" } - private let blockEditorSettingsService: RawBlockEditorSettingsService + private let blockEditorSettingsService: RawBlockEditorSettingsService? // MARK: - Initializers required convenience init( @@ -183,7 +183,11 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor let editorConfiguration = EditorConfiguration(blog: post.blog) self.editorViewController = GutenbergKit.EditorViewController(configuration: editorConfiguration) - self.blockEditorSettingsService = RawBlockEditorSettingsService(blog: post.blog) + if let dotOrgRestAPI = WordPressOrgRestApi(blog: post.blog) { + self.blockEditorSettingsService = RawBlockEditorSettingsService(dotOrgRestAPI: dotOrgRestAPI, blog: post.blog) + } else { + self.blockEditorSettingsService = nil + } super.init(nibName: nil, bundle: nil) @@ -474,12 +478,13 @@ class NewGutenbergViewController: UIViewController, PostEditor, PublishingEditor // MARK: - Editor Setup private func fetchEditorDependencies() async throws -> EditorDependencies { - let settings: String? - do { - settings = try await blockEditorSettingsService.getSettingsString(allowingCachedResponse: true) - } catch { - DDLogError("Failed to fetch editor settings: \(error)") - settings = nil + var settings: String? + if let blockEditorSettingsService { + do { + settings = try await blockEditorSettingsService.getSettingsString(allowingCachedResponse: true) + } catch { + DDLogError("Failed to fetch editor settings: \(error)") + } } let loaded = await loadAuthenticationCookiesAsync()