-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add Gutenberg content parser to use in block processors #22886
Conversation
📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
|
public var comment: SwiftSoup.Comment | ||
public var elements: Elements | ||
public var blocks: [GutenbergParsedBlock] | ||
public weak var parentBlock: GutenbergParsedBlock? |
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.
parentBlock
is treated as a weak reference because the parent block also references this block via its blocks
property. This will facilitate the automated deallocation.
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.
The library SwiftSoup is added via the Swift Package Manager. But we could also include it as a Pod.
} | ||
} | ||
|
||
private var comment: SwiftSoup.Comment |
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.
This type includes SwiftSoup
to avoid conflicts with the CoreData model Comment
.
I'm moving this to the next milestone since this is not a blocker, and the code freeze will be completed today. |
👋 @fluiddot - No rush on this, but I wanted to ask: Did you evaluate what it'd take to put the processor(s) in the Mobile Gutenberg package versus the iOS app codebase? Is there something that makes the content parsers unique to the WordPress app, versus the Gutenberg project? Thanks! |
Nope, I haven't explored what would be needed for moving these files to the Gutenberg Mobile package. There are several parts of the editor implemented in the client like this one that I agree seem to have a better fit in the Gutenberg Mobile. Ideally, the Gutenberg Mobile package should provide all the functionality to use the editor in any app, but the reality is that Gutenberg Mobile is quite coupled to the WP/JP app code.
Part of the logic is related to Gutenberg, as the structure of blocks is defined by the editor. However, there's a bit of overlap in the processing because the need of the processors is due to updating media attributes that are defined by the client. As an example, an Image block needs to be updated with the server media ID, and the media structure is defined in the WP/JP apps. In the future, it would be great if we identify which parts should be provided by Gutenberg Mobile and which ones should be delegated to the client. However, currently, this separation is a bit blurry. |
Makes sense @fluiddot, and certainly something we could defer to the future. 👍 |
👋 Hey @fluiddot, I'm bumping this PR to 24.8 since it's code freeze day. If this PR needs to target 24.7, please target the release branch once it's been cut. Thanks! |
There is a good reason for consolidating this code in Gutenberg. The app and the editor produce different results when handling uploads. Here's an example of <!-- wp:image {\"id\":1431,\"sizeSlug\":\"large\"} -->
<figure class=\"wp-block-image size-large\">
<img src=\"https://alextest41234.files.wordpress.com/2024/04/img_0005-2-1.jpg?w=1024\" class=\"wp-image-1431\"/>
</figure>
<!-- /wp:image --> And here's Gutenberg: <!-- wp:image {\"id\":1431,\"sizeSlug\":\"large\"} -->
<figure class=\"wp-block-image size-large\">
<img src=\"https://alextest41234.files.wordpress.com/2024/04/img_0005-2-1.jpg?w=1024\" alt=\"\"
class=\"wp-image-1431\"/>
</figure>
<!-- /wp:image --> Notice an
To address the performance issues, I recommend moving this code to the background. I can make this change in the scope of the current project since I'm working in this area. |
I agree that consolidating the block processors within the Gutenberg Mobile project could be beneficial. However, I don't believe it will directly address the core issue. The main challenge stems from the fact that the logic for generating the block's markup resides on the JavaScript side (Gutenberg). Currently, the block processors are detached from Gutenberg, requiring them to stay updated with the logic of each block. Given that this is a manual process, discrepancies, as you highlighted @kean, can arise. While finding a method to synchronize the block processors with Gutenberg's logic would be ideal, I anticipate it would introduce considerable complexity.
Please correct me if I'm mistaken, but even if we move the code to the background, the post-saving process will still be time-consuming due to the required processing. Is that correct? |
"30 media items: 5.250 seconds" – oh, I didn't know we we talking seconds 😨 |
There is one more variable: the server. I noticed that it modifies the
An app can call JavaScript directly with little overhead. |
Good point. That's definitely another factor to take into account. Usually, when changes are made to a block (either in the frontend or the backend) they are updated in the same Gutenberg version. In most cases, those changes are also made in the mobile native version (i.e. Gutenberg Mobile). However, the web version doesn't have the same concept of block processors that are run outside the context of the editor, like the case of the app. Hence, in case we consolidate them in the Gutenberg repo, it will take time for Gutenberg contributors to be aware of the need to update them.
True. We could consider a potential workaround where the block processor resides on the JavaScript side and imports the necessary code from Gutenberg to process the block. It's worth noting that, as far as I know, such an approach doesn't currently exist, so it would require building it from scratch. |
@@ -64,6 +64,15 @@ | |||
"version": "0.2.3" | |||
} | |||
}, | |||
{ | |||
"package": "SwiftSoup", | |||
"repositoryURL": "https://github.com/scinfu/SwiftSoup.git", |
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.
The size of the dependency is a bit concerning:
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Swift 58 1709 3707 10315
It should not affect incremental builds, I think it's something to be considered.
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 would suggest considering wrapping https://developer.wordpress.org/block-editor/reference-guides/packages/packages-blocks/ and other related WordPress JS APIs in Objective-C and invoking them using JavaScriptCore. This way, we'll be able to reuse the existing parser. You can run Javascript in background on iOS to ensure that processing doesn't take a lot of time.
A native package that would wrap the existing JS packages could be useful for more scenarios than this. For example, the app could use it for addressing the "dangling" media uploads issue.
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.
The size of the dependency is a bit concerning:
[...]
It should not affect incremental builds, I think it's something to be considered.
I haven't checked how much this library increases the binary. If it's significant we might consider other libraries.
I would suggest considering wrapping https://developer.wordpress.org/block-editor/reference-guides/packages/packages-blocks/ and other related WordPress JS APIs in Objective-C and invoking them using JavaScriptCore. This way, we'll be able to reuse the existing parser. You can run Javascript in background on iOS to ensure that processing doesn't take a lot of time.
A native package that would wrap the existing JS packages could be useful for more scenarios than this. For example, the app could use it for addressing the "dangling" media uploads issue.
This approach is intriguing and would certainly ensure consistent results when processing a block compared to Gutenberg. As a long-term solution, I'd advocate exploring this approach. However, I believe it would entail significant complexity in implementation, particularly regarding how to bundle the necessary code and potential tweaks to the Gutenberg code. @kean not sure if with your comment you're proposing following this instead of the refactor implemented in this PR. 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.
your comment you're proposing following this instead of the refactor implemented in this PR. WDYT?
It's more long-term. I worked with JS-based packages before, so I know it should be feasible, but I don't know how much effort it would take.
particularly regarding how to bundle the necessary code
These packages are already part of the Gutenberg-mobile project, aren't they?
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.
These packages are already part of the Gutenberg-mobile project, aren't they?
Yes, but we bundled them with Metro and files are compiled with Hermes (the setup for React Native). I presume the output of this setup won't be supported natively. We'd need to generate a new bundle compatible with JavaScriptCore
.
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.
The app doesn't need to use these JS files directly. It could part of the existing Gutenberg framework.
Hi @fluiddot 👋 , I'm bumping this PR's milestone to |
Hey @fluiddot, I'm bumping the milestone for this PR to |
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 @fluiddot! Sorry for the delay. I'm getting the branch caught up with trunk
and letting CI run. If we're all green then I'll merge. Thanks for the hard work! 🚀
@@ -48,6 +48,7 @@ | |||
* [**] Block editor: Highlight text fixes [https://github.com/WordPress/gutenberg/pull/57650] | |||
* [*] [Jetpack-only] Stats: Eliminated common error causes in the Insights tab. [#22890] | |||
* [*] [Jetpack-only] Reader: Fix displaying stale site information [#22885] | |||
* [*] [internal] Incorporate a parser to handle Gutenberg blocks more efficiently for improved performance [#22886] |
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.
Seems this entry landed in the wrong section, I'll update it in another 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.
Related to wordpress-mobile/gutenberg-mobile#6696.
To test:
Note
This functionality will be tested on separate PRs where some block processors are using it.
Regression Notes
Potential unintended areas of impact
N/A
What I did to test those areas of impact (or what existing automated tests I relied on)
N/A
What automated tests I added (or what prevented me from doing so)
N/A
PR submission checklist:
RELEASE-NOTES.txt
if necessary.Testing checklist: