-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: Invalidate editor cache when plugins feature flag changes #25170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/26.6
Are you sure you want to change the base?
Changes from all commits
da84446
4991171
bda16ec
d250ed7
a98a5c5
17a8262
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import Foundation | ||
| import UIKit | ||
| import CoreData | ||
| import GutenbergKit | ||
| import WordPressData | ||
| import WordPressKit | ||
| import WordPressCore | ||
|
|
@@ -30,6 +31,9 @@ final class BlogDashboardViewModel { | |
|
|
||
| private var blog: Blog | ||
|
|
||
| /// Tracks the last blog for which the editor was warmed up to avoid redundant warmups. | ||
| private static var lastWarmedUpBlogID: NSManagedObjectID? | ||
|
|
||
| private var error: Error? | ||
|
|
||
| private let wordpressClient: WordPressClient? | ||
|
|
@@ -128,7 +132,7 @@ final class BlogDashboardViewModel { | |
| } | ||
|
|
||
| func viewWillAppear() { | ||
| EditorDependencyManager.shared.prefetchDependencies(for: self.blog) | ||
| warmUpEditorIfNeeded(for: self.blog) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introduced to avoid unnecessary preloading if GutenbergKit is disabled. |
||
| quickActionsViewModel.viewWillAppear() | ||
| } | ||
|
|
||
|
|
@@ -146,7 +150,7 @@ final class BlogDashboardViewModel { | |
| self.loadCardsFromCache() | ||
| self.loadCards() | ||
|
|
||
| EditorDependencyManager.shared.prefetchDependencies(for: blog) | ||
| warmUpEditorIfNeeded(for: blog) | ||
| } | ||
|
|
||
| func clearEditorCache(_ completion: @escaping () -> Void) { | ||
|
|
@@ -185,6 +189,30 @@ final class BlogDashboardViewModel { | |
|
|
||
| private extension BlogDashboardViewModel { | ||
|
|
||
| /// Warms up the editor for the given blog. | ||
| /// | ||
| /// This performs two operations: | ||
| /// 1. WebKit warmup (once per blog) - pre-compiles HTML/JS | ||
| /// 2. Data prefetch (always called) - fetches settings, assets, preload list | ||
| /// | ||
| /// The prefetch is always called because `EditorDependencyManager` handles its own | ||
| /// caching and needs to detect when the plugins feature flag changes. | ||
| func warmUpEditorIfNeeded(for blog: Blog) { | ||
| guard RemoteFeatureFlag.newGutenberg.enabled() else { | ||
| return | ||
| } | ||
|
|
||
| // WebKit warmup - only needed once per blog (shaves ~100-200ms) | ||
| if blog.objectID != Self.lastWarmedUpBlogID { | ||
| Self.lastWarmedUpBlogID = blog.objectID | ||
| let configuration = EditorConfiguration(blog: blog) | ||
| GutenbergKit.EditorViewController.warmup(configuration: configuration) | ||
| } | ||
|
|
||
| // Data prefetch - always call to allow EditorDependencyManager to detect flag changes | ||
| EditorDependencyManager.shared.prefetchDependencies(for: blog) | ||
| } | ||
|
|
||
| func registerNotifications() { | ||
| NotificationCenter.default.addObserver(self, selector: #selector(showDraftsCardIfNeeded), name: .newPostCreated, object: nil) | ||
| NotificationCenter.default.addObserver(self, selector: #selector(showScheduledCardIfNeeded), name: .newPostScheduled, object: nil) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,7 +33,6 @@ final class MySiteViewController: UIViewController, UIScrollViewDelegate, NoSite | |
| } | ||
|
|
||
| private var currentSection: Section = .dashboard | ||
| private static var lastWarmedUpBlogID: NSManagedObjectID? | ||
|
|
||
| @objc | ||
| private(set) lazy var scrollView: UIScrollView = { | ||
|
|
@@ -341,29 +340,6 @@ final class MySiteViewController: UIViewController, UIScrollViewDelegate, NoSite | |
| configureNavBarAppearance(animated: true) | ||
| } | ||
|
|
||
| // MARK: - Editor Warmup | ||
|
|
||
| /// Warms up the editor for the given blog if it hasn't been warmed up already. | ||
| /// This avoids duplicative warmups when the site hasn't changed. | ||
| private func warmUpEditorIfNeeded(for blog: Blog) { | ||
| guard blog.objectID != Self.lastWarmedUpBlogID else { | ||
| // Editor already warmed up for this blog | ||
| return | ||
| } | ||
|
|
||
| Self.lastWarmedUpBlogID = blog.objectID | ||
|
|
||
| let configuration = EditorConfiguration(blog: blog) | ||
|
|
||
| // 1. WebKit warmup - pre-compile HTML/JS (shaves ~100-200ms) | ||
| GutenbergKit.EditorViewController.warmup(configuration: configuration) | ||
|
|
||
| // 2. Data prefetch - pre-fetch settings, assets, preload list via EditorDependencyManager | ||
| Task { | ||
| await EditorDependencyManager.shared.prefetchDependencies(for: blog) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Main Blog | ||
|
|
||
| /// This VC is prepared to either show the details for a blog, or show a no-results VC configured to let the user know they have no blogs. | ||
|
|
@@ -403,9 +379,6 @@ final class MySiteViewController: UIViewController, UIScrollViewDelegate, NoSite | |
| showDashboard(for: blog) | ||
| } | ||
|
|
||
| if RemoteFeatureFlag.newGutenberg.enabled() { | ||
| warmUpEditorIfNeeded(for: blog) | ||
| } | ||
|
Comment on lines
-406
to
-408
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consolidated to |
||
| } | ||
|
|
||
| @objc | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,10 +39,6 @@ final class PostListViewController: AbstractPostListViewController, InteractiveP | |
| refreshNoResultsViewController = { [weak self] in | ||
| self?.handleRefreshNoResultsViewController($0) | ||
| } | ||
|
|
||
| if let blog = self.blog { | ||
| EditorDependencyManager.shared.prefetchDependencies(for: blog) | ||
| } | ||
|
Comment on lines
-42
to
-45
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed as this feels duplicative of |
||
| } | ||
|
|
||
| private lazy var createButtonCoordinator: CreateButtonCoordinator = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix for the unexpected "Plugin loading failed, using default editor configuration" warning.
GutenbergKit's preloading logic returns an empty bundle if
pluginsis disabled. The app preloaded and cached an empty asset bundle, then continued utilizing it even after the plugins feature was enabled. Invalidating the cache ensure GutenbergKit preloads an appropriate bundle.