-
Notifications
You must be signed in to change notification settings - Fork 58
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
VideoPress block: Limit synchronization of block attributes to when post has just been saved #5666
VideoPress block: Limit synchronization of block attributes to when post has just been saved #5666
Comments
@SiobhyB I understand that if we listen for the save post event in the |
@fluiddot, that's a good point. I'm looking at the code for Android here as well as that code's associated PR. I don't have any immediate bright ideas, but will keep thinking. 🤔 |
Thanks for sharing those references, I didn't know about them 😅. I spent some time thinking about the potential options and want to share the following two: 1 - Delegate close to the editorAdd a step to the close & save process that is initiated in the host apps. Before closing the editor, the app will notify the editor via the bridge of the intent of closing & saving. The editor will process this event and execute any pre-close code that is needed (e.g. saving the VideoPress block settings). Once the editor is ready, it will notify the app via the bridge that the editor can be closed. The main downside of this approach is that we'll introduce a delay in the close & save flow due to potential asynchronous actions like saving the settings. In case the user has a slow connection, this would imply speeding down the close process. Although we could limit the execution duration of the pre-close actions to ensure that the editor is closed after X seconds. 2 - Delegate the save of VideoPress block settings to the save post logic in the host appsSimilarly to saving the post content, we'd need to provide a mechanism in the bridge to share VideoPress block settings with the host apps. The synchronization could happen when changing any of the settings or upon the close & save moment. With this data in the host apps, we'll update the settings during the save post flow that happens in the apps when closing. This approach would be probably more complex and harder to maintain than the first one, as we need to integrate the synchronization mechanism. Plus, we'd have to make it generic as we don't want to reference WPCOM/VIdeoPress code in Gutenberg where the bridge is. I'd advocate going with the first one due to simplicity, although it won't be trivial to implement and introduce an important change to the close & save flow. @SiobhyB WDYT? |
Thank you for sharing these options.
Your reasoning makes sense to me here, and I agree that this seems the preferable option out of the two. I worry about the potential hit to performance, but think it's the best option we have and could potentially come in useful for other blocks or editor functionality in the future. |
Yes, that approach comes with a potential hit to performance. Ideally, the update should happen in the host apps after the editor is closed like we could on the second option. I'm thinking of a third option that combines the two mentioned above. It involves sending extra data to be saved when closing & saving. What I have in mind is the following:
|
@fluiddot, I've spent some time looking into how changes are saved to Gutenberg upon exiting the editor on Android, with the following resources being what I've relied on the most:
As per this code comment:
We appear to heavily rely on the information we get from autosaving when exiting the editor. If I'm understanding correctly, I believe a user would only be able to exit the editor quickly enough to cause issues after directly typing. If they open up a block's settings and make changes, they have to close the settings sheet before exiting, which would provide the necessary time for autosave to do its job. We could likely have solid confidence in the autosave mechanism catching changes users make to the block's settings before they exit the editor. As we're already relying on the autosave mechanism for saving on exit, I wonder if we could simplify our approach to syncing the VideoPress block's setting by relying on those existing autosave methods. You mentioned at p1681400912036929/1681327194.576099-slack-C04LWMHSGLC that the web also appears to be updating on autosave, so I feel like this could be an acceptable approach and one that wouldn't involve more complex solutions or performance hits. What do you think? |
That's interesting. I haven't tested it myself but if the autosave is triggered quickly after closing the settings, we could rely on this behavior to save settings to VideoPress.
Good point. If the content that we save when exiting is actually the one made via the autosave mechanism, makes sense to use this approach also to sync VideoPress settings.
I agree, with the information you shared seems the autosave is a way more reliable mechanism than I thought for saving content 😅. Being this said, let's go with this approach 🚀 . |
Thanks for the confidence check @fluiddot! I can aim to get a proof of concept ready for review on Monday 🙇♀️ 🤞 |
@SiobhyB let me know if I can help anyhow with the proof of concept. I saw you made some progress in #5663 and its companion PRs, but not sure what's the optimal way to divide up the work. |
@fluiddot, thank you so much, I'm just working on the iOS PR now and hope to have something that's ready for review in the next couple of hours. I don't think there's a great way to divide the development work right now, but would be grateful if you could help to review when it's ready 🙇♀️ |
Sure thing, I'm more than happy to contribute by reviewing the PRs 🙂. |
Noting that upon further experimentation, I found it was possible to get the syncing working upon a manual save without the need for any super complicated solutions. The solution in #5663 works in my testing, even for flows where the user exits the editor. 🎉 The autosave approach began to feel like too much, given the Android app autosaves after any additional text is added to the editor, so the proposed solution in my PR works only when a user manually saves a post. Looking forward to hearing any feedback on this. 🙇♀️ |
@SiobhyB That's great! I noticed that in case the editor is closed, we make the POST request to update the metadata right before closing. It's likely that the editor will be closed at the time the request finishes, so we won't execute this code. However, I think this is no a critical issue as we only want to update the metadata in the native version 👍 . In the future, if we need to upload the autogenerated tracks (reference) after saving the metadata, we'd need to figure out how to do it.
Sounds good. I think saving only when saving a post makes sense. |
The web version of the block only syncs changes to the block's settings when a post has been manually saved (ref). However, there isn't currently a built-in way to check when a post has just been saved on iOS or Android.
To address this, I'm imagining that we would:
useSyncMedia
hook or, alternatively, connect this to a native version of theisSavingPost
selector.When we have implemented a way to detect when a post has just been saved on native, we can then limit the VideoPress block's synchronization accordingly.
The text was updated successfully, but these errors were encountered: