Skip to content

feat: Enable GutenbergKit asset caching #22035

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

Merged
merged 7 commits into from
Jul 18, 2025

Conversation

dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Jul 18, 2025

Description

Integrate asset caching from wordpress-mobile/GutenbergKit#153.

Close CMM-226. Fix CMM-512.

Testing instructions

1: Smoke test WPCOM Simple site bundled editor

  1. Configure:
    1. Enable Experimental block editor experimental feature
    2. Disable gutenberg_kit_plugins debug flag
  2. Open the editor for a simple site.
  3. Verify the editor loads and you can insert a block.

2: Smoke test WPCOM Simple site remote editor

  1. Configure:
    1. Enable Experimental block editor experimental feature
    2. Enable gutenberg_kit_plugins debug flag
  2. Open the editor for a simple site.
  3. Verify the editor loads and you can insert a Jetpack block.

3: Smoke test WPCOM Atomic site bundled editor

  1. Configure:
    1. Enable Experimental block editor experimental feature
    2. Disable gutenberg_kit_plugins debug flag
  2. Open the editor for an Atomic site.
  3. Verify the editor loads and you can insert a block.

dcalhoun added 5 commits July 18, 2025 12:43
Using `isWPComAtomic` suffices for the need of identifying sites managed
by WPCOM.
The current preloading strategy results in the editor loading twice. The
duplicative load results in hidden editor UI for the second load, as the
loading sequence is not idempotent currently. We should refactor to
ensure the editor UI is only displayed once after the editor fully
loads.

Currently, The first occurs without blog configuration and always loads
the bundled editor. We should ensure preload loads with the proper
configuration and the correct editor (bundled/remote).
The editor relies upon a subscription to editor settings within the
FluxC store. FluxC can dispatch change events multiple times, leading to
unexpected, unnecessary invocations of GutenbergKit's `start` method.
This lead to odd outcomes.

First, during editor setup, we dispatch an event to request the latest
editor settings. FluxC broadcasts two change events: first with the
cached settings, and second when the fetched settings resolve. This
caused two `start` invocations when opening the editor.

Second, the My Site fragment requests the latest settings as a
performance optimization. When closing the editor and returning to My
Site, the request resulted in a broadcast of updated settings, which
attempt to start the editor while it was closing.
@dcalhoun dcalhoun added [Type] Enhancement Gutenberg Editing and display of Gutenberg blocks. labels Jul 18, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Jul 18, 2025

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 18, 2025

Project dependencies changes

list
! Upgraded Dependencies
org.wordpress.gutenbergkit:android:v0.5.0, (changed from v0.4.1)
tree
 +--- project :libs:editor
-|    \--- org.wordpress.gutenbergkit:android:v0.4.1
-|         +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:1.9.0 -> 2.0.21 (*)
-|         +--- androidx.core:core-ktx:1.13.1 -> 1.16.0 (*)
-|         +--- androidx.appcompat:appcompat:1.7.0 -> 1.7.1 (*)
-|         +--- com.google.android.material:material:1.12.0 (*)
-|         +--- androidx.webkit:webkit:1.11.0 -> 1.14.0 (*)
-|         +--- com.google.code.gson:gson:2.8.9 -> 2.13.1
-|         |    \--- com.google.errorprone:error_prone_annotations:2.38.0
-|         \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0 -> 1.9.10 (*)
+|    \--- org.wordpress.gutenbergkit:android:v0.5.0
+|         +--- org.jetbrains.kotlin:kotlin-parcelize-runtime:2.0.21 (*)
+|         +--- androidx.core:core-ktx:1.13.1 -> 1.16.0 (*)
+|         +--- androidx.appcompat:appcompat:1.7.0 -> 1.7.1 (*)
+|         +--- com.google.android.material:material:1.12.0 (*)
+|         +--- androidx.webkit:webkit:1.11.0 -> 1.14.0 (*)
+|         +--- com.google.code.gson:gson:2.8.9 -> 2.13.1
+|         |    \--- com.google.errorprone:error_prone_annotations:2.38.0
+|         +--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2 (*)
+|         \--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 -> 2.1.21 (*)
-\--- org.wordpress.gutenbergkit:android:v0.4.1 (*)
+\--- org.wordpress.gutenbergkit:android:v0.5.0 (*)

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 18, 2025

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr22035-3ef5c35
Commit3ef5c35
Direct Downloadwordpress-prototype-build-pr22035-3ef5c35.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Jul 18, 2025

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr22035-3ef5c35
Commit3ef5c35
Direct Downloadjetpack-prototype-build-pr22035-3ef5c35.apk
Note: Google Login is not supported on these builds.

Copy link

codecov bot commented Jul 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.51%. Comparing base (0f3da5c) to head (3ef5c35).
Report is 2 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #22035      +/-   ##
==========================================
+ Coverage   39.02%   39.51%   +0.48%     
==========================================
  Files        2153     1551     -602     
  Lines      101494    72498   -28996     
  Branches    15585    11838    -3747     
==========================================
- Hits        39613    28650   -10963     
+ Misses      58384    41372   -17012     
+ Partials     3497     2476    -1021     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines -801 to -803
if (isGutenbergKitEditor) {
GutenbergWebViewPool.getPreloadedWebView(this)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This performance optimization leads to duplicate "editor mounted" events, which results in invisible editor UI. We should reinstate this after refactoring the WebView initialization to avoid this issue.

Additional details capture in f013498.

@@ -2503,7 +2500,7 @@ class EditPostActivity : BaseAppCompatActivity(), EditorFragmentActivity, Editor
onXpostsSettingsCapability(isXpostsCapable)
}

val isWpCom = site.isWPCom || siteModel.isPrivateWPComAtomic || siteModel.isWPComAtomic
Copy link
Member Author

Choose a reason for hiding this comment

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

isPrivateWPComAtomic is duplicative of isWPComAtomic in this context of identifying non-self-hosted sites.

Comment on lines 2522 to 2523
// TODO: Use the application password for self-hosted sites
val authHeader = if (isWpCom) "Bearer ${accountStore.accessToken}" else "Basic "
Copy link
Member Author

Choose a reason for hiding this comment

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

To my knowledge, we do not have a method for accessing the application password at this time.

@@ -556,7 +563,7 @@ public void onEditorThemeUpdated(Bundle editorTheme) {
}

public void startWithEditorSettings(@NonNull String editorSettings) {
if (mGutenbergView == null) {
if (mGutenbergView == null || mEditorStarted) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Due to the multiple FluxC subscription updates, the existing logic attempts to start the editor twice on open and once on close. This new state guards against unnecessary editor starts.

Additional details in dd36e2c.

Copy link
Contributor

Choose a reason for hiding this comment

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

This change has caused the regression mentioned here.

Copy link
Contributor

@oguzkocer oguzkocer left a comment

Choose a reason for hiding this comment

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

Approving pending testing.

There are bits that I don't fully understand due to my lack of domain knowledge and bits that I find confusing as outlined as a line comment. However, this shouldn't be a blocker as I asked @dcalhoun to handle this part of the work specifically because I lacked this knowledge, so I think testing it is more important than having a line-by-line understanding at the moment. Having said that, I am slowly acquiring the domain knowledge and hope to contribute more in the reviews in the future.

Comment on lines +2535 to +2536
val siteApiRoot = if (isWpCom) "https://public-api.wordpress.com/"
else siteModel.wpApiRestUrl ?: "$siteURL/wp-json/"
Copy link
Contributor

Choose a reason for hiding this comment

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

As a future improvement, I'd love for us to be a bit more clear on when the editor is fully supported and we know the logic is correct and when it's not or we are making a guess.

  • Moving siteApiRoot url calculation to a central place with some unit tests would be great
  • Having a isGutenbergKit supported function in a central place would also help, where the function would take a configuration type (with api root, authentication header etc) and decides whether it can move forward or not. We can add comments about each scenario.
  • We can add a way to convert a SiteModel into the configuration type mentioned above.
  • The configuration type then can be passed to relevant places, rather than doing to calculation here or in other fragments

My main feedback - and it's not about this PR - is that I am having a hard time following the current code, mostly because it's only partially implemented. If it was fully implemented and I just needed to process it, than it'd be easy, but that's impossible right now without at least comments for each situation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree. Thank you for the note.

Centralizing and documenting common calculations would definitely help communicate intent. A utility for converting SiteModel to editor configuration would also be helpful, and is necessary for implementing the warmup functionality without further duplication.

@dcalhoun dcalhoun marked this pull request as ready for review July 18, 2025 19:55
@dcalhoun dcalhoun requested a review from a team as a code owner July 18, 2025 19:55
@dcalhoun dcalhoun requested review from nbradbury and removed request for a team July 18, 2025 19:55
Copy link

@oguzkocer
Copy link
Contributor

@dcalhoun Tested as instructed and it worked great. Caching does seem to make a huge difference as the difference is very obvious when I switch sites and the assets have to be downloaded again. I think we can merge it 👍

@dcalhoun dcalhoun enabled auto-merge (squash) July 18, 2025 20:11
@dcalhoun dcalhoun merged commit d3b914b into trunk Jul 18, 2025
24 of 27 checks passed
@dcalhoun dcalhoun deleted the feat/enable-gutenberg-kit-asset-caching branch July 18, 2025 20:16
dcalhoun added a commit to wordpress-mobile/GutenbergKit that referenced this pull request Jul 28, 2025
Trailing slashes are now expected to be providing in the configuration.
This expectation was put in place to simplify configuration logic here
and in host apps.

This change prevents double trailing slashes, which began occurring in
WP-Android in the following. This resulted in failed API requests, like
image uploads.

wordpress-mobile/WordPress-Android#22035
dcalhoun added a commit to wordpress-mobile/GutenbergKit that referenced this pull request Jul 28, 2025
…#158)

Trailing slashes are now expected to be providing in the configuration.
This expectation was put in place to simplify configuration logic here
and in host apps.

This change prevents double trailing slashes, which began occurring in
WP-Android in the following. This resulted in failed API requests, like
image uploads.

wordpress-mobile/WordPress-Android#22035
Copy link

sentry-io bot commented Aug 1, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

Did you find this useful? React with a 👍 or 👎

@dcalhoun
Copy link
Member Author

dcalhoun commented Aug 1, 2025

Sentry's suspected issue report seems unlikely. The referenced createGutenbergEditorFragment is only invoked for Gutenberg Mobile. This PR changes GutenbergKit instantiation logic, not logic shared with Gutenberg Mobile.

@oguzkocer
Copy link
Contributor

@dcalhoun I looked into the reported issue yesterday and thought the same thing, but forgot to record it here. So, thanks for doing that! 🙇‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Editing and display of Gutenberg blocks. [Type] Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants