-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Gallery block: Determine galleryWithImageBlocks
prop value based on the WordPress version of the site when value is unknown
#47782
Comments
Setting this issue as a high priority because, although it might be an edge case, we detected that around 10% of sessions are self-hosted sites having |
In my testing with WordPress 5.9+ on Android without the Gutenberg plugin, Also, what do you think the most efficient way to retrieve the WP version number would be here? Do we already have this available as a value within the editor? |
Hey @derekblank , sorry for the delayed replay 🙇 . I tried to spare time to find a consistent way to reproduce the issue before sharing my insights but couldn't finish it. In the meantime, let me share a response to some of the above questions.
Exactly, this is the issue we need to solve. We need to ensure that self-hosted sites with WordPress 5.9+ always use Gallery v2. We can update isGalleryV2Enabled although I think we currently don't have access to the WP version within the editor. Unless we expose it, we could apply this solution on the native side, probably in the code references I shared in the issue's description.
Yes, I think we can assume that sites with WP 5.9+ can always use Gallery v2. Hence, probably we don't need to identify the edge case where |
@fluiddot I spent some time searching for the best way to compare the WordPress version number in order to set the Gallery block version to v2 for self-hosted sites using WP 5.9+. In reviewing all of the code references you identified in the parent comment, handling this via the native refs in particular (Gutenberg.swift and RNReactNativeGutenbergBridgeModule.java) feels like a bit of an indirect resolution for an edge case, but it may still be the preferred solution. Obtaining the WP version with Javascript seems surprisingly difficult (whether it's via the editor or outside of it), but feels like a much more direct way to handle the Gallery flag logic for WP 5.9+. I would have expected a site's WP version to be available via an API like One of the more elegant solutions seems to be to match how this is handled for the List and Quote blocks using the mobile block editor settings. I created a PR to demonstrate this, but in testing realized that it may not fully work for users who do not have the Gutenberg plugin installed due to the code being in After reviewing the above solutions, if we feel modifying the flag in the host apps may still be the better solution, could you describe this a bit further? This solution is less obvious to me. Would you expect that we handle the Gallery v2 flag logic directly in the Swift and Java files respectively using the WP version integer, or use the host apps to access the WP version integer and pass it via the bridge? |
@derekblank The idea of adding the condition here is to delegate picking the Gallery version to the host app, similar to other settings we have to configure the editor (reference).
I agree that handling the edge case in JS (i.e. the editor) might seem more straightforward, but keep in mind that the editor is configured by the host app. This is a nuance that makes the editor's architecture diverge from the web version. In the web version, the editor can be configured via the backend as it's rendered within the WordPress instance. In our case, since the editor is served by the apps, we don't have access to that mechanism of backend rendering. The closest thing we have to the backend is actually the host apps.
Yep, I think I also tried to fetch the WP version in the past unsuccessfully. In any case, the WP version is available in the host app. We already query data related to the site from the host app, so doing the same for the WP version might make sense.
I think adding an endpoint would be the most complex option for this case.
The problem, as you mentioned, is that this solution won't work for sites that don't have the Gutenberg plugin. This is the case we are trying to cover, so we'd need to figure out something different. Following the approach of introducing the condition in the backend, the only alternative I see is exposing this setting somehow from WordPress. But for something so specific, I wouldn't go that way.
I agree, this solution seems the best option.
I think the task could be broken down in:
Part of the task would be to navigate the host app's code in order to find where to apply the solution. Let me know if this helps you and don't hesitate to share more questions.
I'd say that unless we foresee the need for the WP version in the editor in future developments, I'd go with applying the solution only on the native side. |
I've identified this area for iOS and implemented the change to BlockEditorSettings+GutenbergEditorSettings.swift, and it appears to be working in my testing. This PR implementation is ready for testing: wordpress-mobile/WordPress-iOS#20736 On the Android side, @mkevins and I identified that themeSupportsGalleryWithImageBlocks would be a good candidate to try similar logic as the iOS PR, so I'll implement that next. |
Description
As described in wordpress-mobile/WordPress-Android#17712, we pick the wrong version of the Gallery block when a self-hosted site is in WordPress 5.9+ and the Gutenberg plugin is not installed. This issue is mainly affecting the cases where the prop used to pick the Gallery version (
galleryWithImageBlocks
) is unknown, which leads to usingv1
since it's the default value.The Gallery block v2 is supported in WordPress 5.9+, so in order to avoid using the wrong version when having an unknown value, we could determine the Gallery block version to use based on the site's WordPress version.
I'm leaving some code references to pinpoint the logic used to determine the Gallery block version to use:
galleryWithImageBlocks
prop set by the appiOS:
gutenberg/packages/react-native-bridge/ios/Gutenberg.swift
Lines 205 to 207 in 705ab44
Android:
gutenberg/packages/react-native-bridge/android/react-native-bridge/src/main/java/org/wordpress/mobile/ReactNativeGutenbergBridge/RNReactNativeGutenbergBridgeModule.java
Lines 161 to 164 in c840e90
Picking Gallery block version based on
galleryWithImageBlocks
gutenberg/packages/edit-post/src/editor.native.js
Lines 29 to 36 in 70cf4fa
gutenberg/packages/block-library/src/gallery/shared.js
Lines 36 to 57 in 3356e6a
gutenberg/packages/block-library/src/gallery/edit-wrapper.js
Lines 20 to 24 in 3356e6a
Step-by-step reproduction instructions
v1
(content is not rendered using inner blocks).Expected behaviour
The correct version of the Gallery block should be used.
Actual behaviour
In some cases, the wrong version of the Gallery block is used.
Screenshots or screen recording (optional)
N/A
WordPress information
Device information
trunk
The text was updated successfully, but these errors were encountered: