Skip to content

Support caching remote assets #148

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

Open
wants to merge 15 commits into
base: trunk
Choose a base branch
from

Conversation

crazytonyli
Copy link

@crazytonyli crazytonyli commented Jun 23, 2025

What?

This is an alternative solution to #107.

Happy path

Here are the steps to see the "happy path" scenario on the Demo iOS app:

  1. Create a self-hosted site.
  2. Install Jetpack and fully connect to WordPress.com. This is necessary to verify jetpack plugins block types are loaded into the editor.
  3. Update the EditorConfiguration.template to use your test site.
  4. Run make build.
  5. Make sure the GUTENBERG_EDITOR_REMOTE_URL launch argument is unchecked. Launch the Demo iOS app.
  6. You should see your site in the "Remote Editors" section of the Demo app.
  7. (Optional) Tap the Refresh button to pre-fetch the editor assets.
  8. Tap your test site to launch the editor.
  9. Open the block inserter and verify the Jetpack blocks (i.e. AI assistant)
Example

Simulator Screenshot - iPhone 16 - 2025-06-23 at 22 21 00

Known issues

When enabling GUTENBERG_EDITOR_REMOTE_URL, the fetched assets can be used by the editor, and the editor can be launched. However, the Jetpack blocks (see the happy path scenario) are not available in the block inserter.

Why?

How?

Here is how the caching mechanism works:

  1. The GBK editor invokes the fetchEditorAssets JavaScript function to retrieve the manifest from the wpcom/v2/editor-assets endpoint, and eventually renders the returned scripts and styles HTML on screen.
  2. The fetchEditorAssets JavaScript function internally calls the iOS native code EditorAssetsProvider to get the manifest content. However, the manifest content is not verbatim from the wpcom/v2/editor-assets endpoint.
  3. EditorAssetsProvider calls EditorAssetsMainifest.renderForEditor to swap the HTTP links in the script and link tags with gbk-cache-http(s):// links.
  4. After the modified manifest content is returned to the GBK editor, the script and link tags are rendered on screen, and the web view attempts to load those gbk-cache-http(s):// links.
  5. The CachedAssetSchemeHandler is triggered to load content for the gbk-cache-http(s):// links. This is where we can fetch and cache the assets from the original HTTP URL.

Difference with #107

The major difference is that #107 caches the editor assets as a whole. But this PR caches the asset individually.

In #107, it stores the hash value (which is proposed in wordpress-mobile/block-editor-assets-endpoint#1) returned by the editor-assets API. When a new download operation is triggered, it gets the hash value from the editor-assets API response. If the value changes, which happens if assets are added or removed, it re-downloads all the assets again, even if some have already been downloaded. Since the editor assets are treated as a complete bundle, the GBK editor can only be loaded after all assets are downloaded.

This PR works with the existing wpcom/v2/editor-assets API, and does not require the hash value. There is an API (EditorAssetsLibrary.fetchAssets) to start downloading the editor assets before launching the GBK editor. But you don't have to wait for the caching to complete; you can launch the editor anytime, and the cache can continue to get to work when users work on their posts. That's because this PR caches assets individually via the gbk-cache-http(s) links (see the "How" section above). The "identifier" of the asset is its URL (the hash used in #107 also uses asset URLs as cache identifiers). A new cache file is created for each asset URL. When new assets are included in the editor-assets API response, they will be cached either by a call to EditorAssetsLibrary.fetchAssets, or when the new assets are rendered in the GBK editor.

Testing Instructions

Verify that the solution works with sites that are

  • located under a subdirectory: https://example.com/blog
  • using a non-English locale for the whole site and/or the logged-in user.
  • The editor functions the same with or without the GUTENBERG_EDITOR_REMOTE_URL launch argument.

Accessibility Testing Instructions

Screenshots or screencast

@crazytonyli crazytonyli requested a review from dcalhoun June 23, 2025 10:37
Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

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

This looks great. The "happy path" succeed for me. 🎉

When enabling GUTENBERG_EDITOR_REMOTE_URL, the fetched assets can be used by the editor, and the editor can be launched. However, the Jetpack blocks (see the happy path scenario) are not available in the block inserter.

This known issue no longer occurs for me. I am able to utilize Jetpack blocks while using the remote editor dev server.

@crazytonyli crazytonyli force-pushed the fetched-assets-editor-cache branch from 021b8cb to d15254a Compare June 26, 2025 02:06
@crazytonyli crazytonyli requested a review from dcalhoun June 26, 2025 03:24
@crazytonyli crazytonyli marked this pull request as ready for review June 26, 2025 03:24
dcalhoun and others added 3 commits June 26, 2025 14:49
Utilize JS fetch until we implement fetching and caching editor assets
for Android.
WP-iOS relies upon an exact version of 2.7.5. This caused a conflict:

```
Failed to resolve dependencies Dependencies could not be resolved because root depends on 'swiftsoup' 2.7.5 and 'gutenbergkit' depends on 'swiftsoup' 2.8.8..<3.0.0.
```
@crazytonyli
Copy link
Author

crazytonyli commented Jun 27, 2025

The font on the web editor and GBK remote editor is not the same. ⬇️

Screenshot 2025-06-27 at 3 37 23 PM

The remote edtiro in the trunk branch also uses a different font. ⬇️

Screenshot 2025-06-27 at 3 47 16 PM

@dcalhoun I guess this is a known issue?

@dcalhoun
Copy link
Member

The font on the web editor and GBK remote editor is not the same. ⬇️
[...]
@dcalhoun I guess this is a known issue?

Yes, #81 tracks loading fonts.

@dcalhoun dcalhoun mentioned this pull request Jun 27, 2025
2 tasks
Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

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

This works great from my testing. Thank you for helping design and implement this!

@dcalhoun
Copy link
Member

  • located under a subdirectory: https://example.com/blog
  • using a non-English locale for the whole site and/or the logged-in user.

I'm unsure why these were originally listed in #107 or they might impact this functionality. Presumably any impact would be present in the existing, non-caching fetching mechanism. It likely safe to merge this. WDYT?

At the moment, the l10n is handled in the app, the site/user setting has no impact on GBK. We plan to expand that l10n to include third-party strings later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants