-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: trunk
Are you sure you want to change the base?
Conversation
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 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.
021b8cb
to
d15254a
Compare
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. ```
The font on the web editor and GBK remote editor is not the same. ⬇️ ![]() The remote edtiro in the trunk branch also uses a different font. ⬇️ ![]() @dcalhoun I guess this is a known issue? |
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 works great from my testing. Thank you for helping design and implement this!
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. |
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:
EditorConfiguration.template
to use your test site.make build
.GUTENBERG_EDITOR_REMOTE_URL
launch argument is unchecked. Launch the Demo iOS app.Example
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:
fetchEditorAssets
JavaScript function to retrieve the manifest from thewpcom/v2/editor-assets
endpoint, and eventually renders the returned scripts and styles HTML on screen.fetchEditorAssets
JavaScript function internally calls the iOS native codeEditorAssetsProvider
to get the manifest content. However, the manifest content is not verbatim from thewpcom/v2/editor-assets
endpoint.EditorAssetsProvider
callsEditorAssetsMainifest.renderForEditor
to swap the HTTP links in thescript
andlink
tags withgbk-cache-http(s)://
links.script
andlink
tags are rendered on screen, and the web view attempts to load thosegbk-cache-http(s)://
links.CachedAssetSchemeHandler
is triggered to load content for thegbk-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 theeditor-assets
API. When a new download operation is triggered, it gets thehash
value from theeditor-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 thehash
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 thegbk-cache-http(s)
links (see the "How" section above). The "identifier" of the asset is its URL (thehash
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 theeditor-assets
API response, they will be cached either by a call toEditorAssetsLibrary.fetchAssets
, or when the new assets are rendered in the GBK editor.Testing Instructions
Verify that the solution works with sites that are
https://example.com/blog
GUTENBERG_EDITOR_REMOTE_URL
launch argument.Accessibility Testing Instructions
Screenshots or screencast