Skip to content

Conversation

@jkmassel
Copy link
Contributor

@jkmassel jkmassel commented Dec 16, 2025

What?

Adds an Android preloading system for the Gutenberg editor that prefetches editor dependencies before display, matching the existing iOS implementation.

Why?

The Gutenberg editor requires several API calls and asset downloads during initialization, which can cause slow launch times. This PR introduces a preloading architecture that:

  • Pre-fetches API responses (post types, themes, settings) so the editor doesn't need to make network calls during startup
  • Downloads and caches JavaScript/CSS asset bundles for faster subsequent launches
  • Provides progress feedback to the user during preparation
  • Establishes feature parity with the existing iOS preloading system

How?

New Core Components:

  • EditorService - Orchestrates loading all editor dependencies with progress tracking
  • EditorPreloadList - Pre-fetched API responses injected into the editor JavaScript
  • EditorAssetsLibrary (in stores/) - Downloads and caches asset bundles
  • EditorHTTPClient - Authenticated HTTP client for WordPress REST API
  • RESTAPIRepository - REST API calls with response caching
  • EditorURLCache - URL-level caching with configurable policies

New Model Classes:

  • EditorAssetBundle - Represents downloaded editor assets
  • EditorCachePolicy - Configurable caching strategies (Always, MaxAge, Ignore)
  • EditorSettings, EditorDependencies - Editor configuration models
  • GBKitGlobal, LocalEditorAssetManifest, RemoteEditorAssetManifest - Asset manifest parsing

Demo App Updates:

  • Added SitePreparationActivity and SitePreparationViewModel showing the preloading flow with progress UI

Other Changes:

Testing Instructions

  1. Build and run the Android demo app
  2. Select a site configuration
  3. Observe the "Site Preparation" screen showing loading progress
  4. Tap "Prepare from scratch" to test full loading without cache
  5. Tap "Prepare" to test cached loading
  6. Verify the editor loads correctly with preloaded data
  7. Run make test-android to verify all new unit tests pass

See the tests in #250 for examples of tests sites you can use.

@jkmassel jkmassel changed the base branch from trunk to add/preload-list-tests December 16, 2025 16:14
Comment on lines +128 to +131
val viewModel = ViewModelProvider(
this,
SitePreparationViewModelFactory(application, configurationItem)
)[SitePreparationViewModel::class.java]

Choose a reason for hiding this comment

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

⛏️Aren't we using injection in the example project? ViewModels can be simply injected.

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 don't think we are at the moment – I'd be happy to adopt it, but I think it's outside the scope of this PR :)

responseHeaders = EditorHTTPHeaders(entry.headers)
)
} catch (e: Exception) {
null

Choose a reason for hiding this comment

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

Do we want to track the exception here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case probably not, because we'll treat a cache failure as a simple cache miss. I've modified this to use runCatching in c64592b, which should hopefully make the intent more clear!

@dcalhoun dcalhoun force-pushed the add/preload-list-tests branch from 209696f to f59acb1 Compare December 17, 2025 19:26
@jkmassel jkmassel force-pushed the add/preload-list-tests branch from f59acb1 to c82027d Compare December 17, 2025 20:17
Base automatically changed from add/preload-list-tests to trunk December 17, 2025 20:50
@jkmassel jkmassel force-pushed the add/android-preload-list branch 4 times, most recently from 0e760f1 to 8060669 Compare December 18, 2025 21:11
@jkmassel jkmassel changed the title Add Android Preload List (DNM) Add Android Preload List Dec 22, 2025
@jkmassel jkmassel force-pushed the add/android-preload-list branch from 86161e3 to 0d0ce7f Compare December 22, 2025 18:32
@jkmassel jkmassel marked this pull request as ready for review December 22, 2025 20:41
@jkmassel jkmassel force-pushed the add/android-preload-list branch from bd9046e to 84042ab Compare December 22, 2025 20:44
@jkmassel jkmassel added the [Type] Enhancement A suggestion for improvement. label Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants