fix: Improve preloading robustness #288
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Fixes namespace handling for native REST API requests and improves asset bundle validation robustness.
Why?
Native REST API requests (editor settings, active theme, site settings, post types, editor assets) were not properly applying the site namespace from
EditorConfiguration.siteApiNamespace. This caused requests to fail for sites that require namespaced endpoints (e.g.,/wp/v2/sites/123/postsinstead of/wp/v2/posts).Additionally, the asset bundle validation was too fragile—if a bundle directory existed but was incomplete (missing
editor-representation.json), it would be incorrectly treated as valid, causing editor initialization failures.How?
Namespace support for REST API URLs (
RESTAPIRepository.swift): AddedbuildNamespacedURL()helper that inserts the namespace after the version segment of API paths. Applied this to all native API requests: editor settings, active theme, site settings, post types, and individual post/type lookups.Namespace support for editor assets (
EditorAssetLibrary.swift): UpdatededitorAssetsUrl()to apply the namespace when building the editor-assets endpoint URL.Robust bundle validation (
EditorAssetBundle.swift,EditorAssetLibrary.swift):hasBundle()now verifies bothmanifest.jsonANDeditor-representation.jsonexistEditorAssetBundle.init(url:)validateseditor-representation.jsonexists before parsinglistBundles()to usecompactMapwithtry?to skip invalid bundles instead of failingEditor loading view timing (
EditorViewController.swift): MovedhideActivityView()from adeferblock to when the editor is actually ready, ensuring the loading indicator remains visible during WebView initialization.Optional progress callback (
EditorService.swift): Made theprogressparameter inprepare()optional for simpler API usage when progress monitoring isn't needed.Testing Instructions
siteApiNamespaceset to["sites/12345/"])editor-representation.jsonfrom a cached bundle) and verify it's properly skippedAccessibility Testing Instructions
N/A - These changes are internal API/loading improvements with no UI changes.
Screenshots or screencast
N/A - Internal changes only.