Repository navigation
feat: report save availability to the host - #792
Conversation
XCFramework BuildThis PR's XCFramework is available for testing. Add the following to your .package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/792")Built from 381e1a4 |
Hosts save natively and need to know when saving is unsafe, such as while an upload holds the editor's save lock, so they can disable their save controls instead of persisting temporary blob URLs. Co-Authored-By: Jeremy Massel <1123407+jkmassel@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lets hosts disable their save controls while the editor has locked saving. The default no-op implementation keeps the change non-breaking. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lets hosts disable their save controls while the editor has locked saving. The listener is notified on the main thread, in order with the editor's availability callbacks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Demonstrates the save availability event: saving mid-upload would persist temporary media URLs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first report fires once the post is set up, before editorDidLoad and onEditorAvailable, and is not resent, so hosts that wait for load would miss it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream mediaUpload clears the batch's lock on any file's error, so hosts can see saving unlocked while other files are still uploading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Android receives the payload values positionally and iOS decodes them by key, so reordering or renaming the keys would silently break hosts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The editor never returns to not-ready while mounted, so the effect's dependencies already prevent repeat reports. This matches useSyncHistoryControls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Matches the other listener setters; GutenbergView already clears every listener on detach, so hosts don't need to pass null. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71ee705 to
daad6f4
Compare
crazytonyli
left a comment
There was a problem hiding this comment.
I guess the idea is that the app should disable save button when isSavingLocked. But what if the save action is still triggered, in code, not by user tapping the save button, would/should the GBK throw an error somehow, or is that acceptable?
Disabling save controls alone leaves saves started in code, such as autosaves, free to persist temporary media URLs mid-upload. GBK can't enforce the lock while hosts save natively. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Good question. The lock is guidance, and hosts should check it before programmatic saves. I updated the documentation to better communicate this. For comparison: the web editor disables various UI mechanisms (save button, keyboard shortcuts), but it does not prevent programmatic saves of in-flight uploads. Once saving moves to GutenbergKit, it will return a Much of this is in a local plan document. I'll move those to a Linear project/issues for better visibility (Update: See P-CMM-11379). Thank you for the question. |
What?
Expose entity save availability via new bridge event.
Why?
Close CMM-2552. Currently, hosts own post saving and rely on their own internal tracking for enabling UI for saving posts. In preparation for GutenbergKit managing post saving via Gutenberg's APIs, GutenbergKit must expose the current save availability status. This is opt-in functionality, not a breaking change.
How?
Introduce a new save availability event and callback for iOS and Android respectively. These are utilized anytime the editor's store modifies its relevant state.
Testing Instructions
Accessibility Testing Instructions
N/A, no navigation changes.
Screenshots or screencast
N/A, no navigation changes.
AI-generated details
Phase 2 of the CMM-2024 editor-driven saving plan. Hosts can now disable their save controls while the editor reports that saving is locked, e.g. during a media upload, instead of persisting temporary
blob:URLs.useSyncSaveAvailabilitysendsonEditorSaveAvailabilityChanged { isSaveable, isSavingLocked }once the editor is ready and then on each change, deduplicated.isDirty/isSavingare left out until the editor saves posts. Adapted from feat: add real editor-driven save post mechanism #445 (co-authored).editor(_:didUpdateSaveAvailability:)with a default no-op implementation, so the change is non-breaking;EditorSaveAvailabilitystruct.setSaveAvailabilityListener(SaveAvailabilityListener?), deliveringGutenbergView.SaveAvailabilityon the main thread.onEditorUnavailable.What locks saving: block media uploads lock saving through the editor's
mediaUploadsetting. That includes uploads routed through the native upload server, since the middleware runs inside the same request. Media picked through the host's native media library doesn't lock the editor.Testing: JS unit tests for the hook; Swift decoding test; Kotlin listener test. JS, Swift and Kotlin unit suites and lint pass locally.
🤖 Generated with Claude Code