-
Notifications
You must be signed in to change notification settings - Fork 797
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
[RNMobile] Fetch VideoPress metadata for native block #29997
Conversation
Are you an Automattician? You can now test your Pull Request on WordPress.com. On your sandbox, run
to get started. More details: p9dueE-5Nn-p2 |
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. |
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.
@SiobhyB On iOS works as expected, I tried modifying the settings and confirmed they are fetched properly on the native version. However, on Android using an actual device, I'm getting the following error:
Possible Unhandled Promise Rejection (id: 0):
Error: undefined is not a function
Error: undefined is not a function
I tried to debug it via the Chrome debugger and it doesn't happen. This makes me think that there's a call somewhere within the useVideoData
hook that is not supported in Hermes.
const isNative = Platform.isNative; | ||
|
||
// eslint-disable-next-line no-console | ||
const debug = isNative ? console.log : debugFactory( 'videopress:video:use-video-data' ); |
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.
I noticed that calls to debug
are not being displayed in the native version because it's not enabled. If we add the following line all debug logs are printed:
debugFactory.enable( 'videopress:*' );
Since enable
function should only be called once, I'm wondering if we could add this to the entry point:
import debugFactory from 'debug';
import registerVideoPressBlock from './blocks/video/index';
// eslint-disable-next-line no-undef
if ( __DEV__ ) {
debugFactory.enable( 'videopress:*' );
}
registerVideoPressBlock();
WDYT?
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.
Much nicer, thanks Carlos! Done in 08f9a92.
at() is not supported on some environments, including Hermes, which we rely on for Android.
558671e
to
08f9a92
Compare
@@ -72,7 +77,8 @@ export default function useVideoData( { | |||
setIsRequestingVideoData( false ); | |||
|
|||
// pick filename from the source_url | |||
const filename = response.original?.split( '/' )?.at( -1 ); | |||
const filename = |
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.
Debugging the reasons this code wasn't working with Android led me to this line. Although I couldn't find any open issues that specifically mention that Hermes doesn't work with the at()
method, I did find it isn't supported by some older browsers, and replacing it fixes the issue with Android. I therefore strongly suspect the cause of the issues was Hermes not supporting the at()
method.
Another way of rewriting this could be: const filename = response.original?.split('/').slice(-1)[0];
but I thought that the use of length
may be more easily parsed, although it's more verbose. I'd be interested to hear other thoughts or opinions on this.
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.
Debugging the reasons this code #29997 (review) led me to this line. Although I couldn't find any open issues that specifically mention that Hermes doesn't work with the at() method, I did find it isn't supported by some older browsers, and replacing it fixes the issue with Android. I therefore strongly suspect the cause of the issues was Hermes not supporting the at() method.
Great investigation! It's true that there's no reference to the at
function in the Hermes language features, so as you mentioned might be an incompatibility with the WebView Android version (it's supported from 92
onwards). However, I checked my Android WebView version and it's 111
, so not sure where's the incompatibility coming from 🤔.
Another way of rewriting this could be: const filename = response.original?.split('/').slice(-1)[0]; but I thought that the use of length may be more easily parsed, although it's more verbose. I'd be interested to hear other thoughts or opinions on this.
Another approach would be to import a polyfill for the function. I checked the at
documentation and there's a polyfill in the core-js
library that we could use. Technically, we could import it into Gutenberg by adding the following code to globals.js
:
import 'core-js/proposals/relative-indexing-method';
WDYT?
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.
I've just tested my above suggestion on an actual Android device and works 🎊.
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.
@SiobhyB I took the liberty of opening a PR to include the polyfill in Gutenberg. Let me know if you could take a look and test this PR with the polyfill. Thanks!
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.
Oh, brilliant, thanks for that! Approved the Gutenberg PR and reverted my change to the code in bfc9f37. I'll also go ahead to update the Gutenberg submodule in wordpress-mobile/gutenberg-mobile#5652 once it's merged.
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.
Oh, brilliant, thanks for that! Approved the Gutenberg PR and reverted my change to the code in bfc9f37. I'll also go ahead to update the Gutenberg submodule in wordpress-mobile/gutenberg-mobile#5652 once it's merged.
Great, I've just merged the PR.
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.
Thank you! The Gutenberg Mobile PR is up-to-date now :) It'd be great if we could get this PR merged now, if you think it's ready to be approved.
…hod" This reverts commit 9a3ff4f.
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.
LGTM 🎊 !
I confirm that changes made to the block on the web are reflected when opening the block in the app. I also checked that the block settings are updated even when the post is not refreshed in the app with the latest changes, e.g.:
- Change block settings on the web.
- Save the post.
- Open the same post in the app without refreshing the post list.
- Observe a log in the console notifying about some of the settings being out of sync (e.g.
'rating' is out of sync. Updating 'rating' attr from 'G' to 'PG-13'
).
Part of a series of PRs to address wordpress-mobile/gutenberg-mobile#5611.
Related PRs
The changes in this PR relies on the following:
gutenberg-mobile
: VideoPress block: Fetch VideoPress metadata for native block wordpress-mobile/gutenberg-mobile#5652Proposed changes:
isUserConnected
check. As only simple WordPress.com sites are supported on native for the time being, we can safely assume that users will be connected to Jetpack. We can revisit this in the future when expanding support.debug
functionality (which isn't compatible with native by default) is conditionally changed toconsole.log
.path
on native, to ensure the URL is correctly built in the native apps and to allows us more control over supported endpoints. Support for this endpoint is added in VideoPress block: Fetch VideoPress metadata for native block wordpress-mobile/gutenberg-mobile#5652.Other information:
Jetpack product discussion
p9ugOq-3mV-p2
Does this pull request change what data or activity we track or use?
No, it does not.
Testing instructions:
useSyncMedia
hook has not yet been implemented on native, it's necessary to first apply the following patch before testing these changes.Patch here⤵️
These changes will implement the
useSyncMedia
hook and log the results ofuseVideoData
:video data: {video data}
has been correctly logged to the console.