-
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
Block Library: Unify handling for block view scripts #32814
Conversation
Size Change: -3.63 kB (0%) Total Size: 1.04 MB
ℹ️ View Unchanged
|
b566d9b
to
9eeafb4
Compare
@vcanales and @jasmussen, I would appreciate a sanity check from you for the Navigation block and in regards to all the changes applied to how this mechanism works now to account for the fact that the same PHP files power both the block in the Gutenberg plugin and in WordPress core. @pento, I would appreciate a sanity check for the File block. As part of this PR I also sorted out the issue you raised in the past about the potential name conflict between packages and blocks by using the following name patterns for entry points: [ 'blocks/' + blockName ]: scriptPath, |
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.
Things worked well on my tests and the change seems a good improvement 👍
I tested that the navigation block continues to be responsive. For the file block, I added some alerts and verified they were shown in the browser (so the script loaded).
This should be backported to core right? |
What about the e2e test failures here, are they unrelated? (the navigation one specifically) |
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.
Changes for the file block look solid, thanks for handling that, @gziolo!
Thanks for looking at this. As we introduce core blocks that have a reliance on frontend scripts it's important to ensure the APIs created move in the right direction. |
I'm looking into it now. It feels like an issue with e2e tests related to changes. It's most likely my fault 😄 |
9eeafb4
to
b796771
Compare
It looks like failing PHPUnit tests are related to the changes to the template editing mode in WP core, related PR: #32888. |
b796771
to
89ba0a6
Compare
Resolved after rebase with It looks like failing e2e tests are completely unrelated to this branch after the fix added in 89ba0a6 for the tests covering Navigation block. |
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.
Tested and it works as expected on the Navigation and File blocks. e2e test failures seem unrelated as well, as they're present in trunk at the moment.
Thanks for looking into this, this process is a great improvement.
* Block Library: Unify handling for block view scripts * Add logic that registers view scripts for blocks * Fix e2e tests with view script for Navigation block
* Block Library: Unify handling for block view scripts * Add logic that registers view scripts for blocks * Fix e2e tests with view script for Navigation block
Description
Compatibility between the plugin and WordPress core
The following code won't work in WordPress core, because
plugins_urls
can only work with the Gutenberg plugin. We need a more general solution for core blocks to move forward:My proposal is that we only call
wp_enqueue_script
with the script handle and we register script separately outside of the PHP file that gets copied to WordPress core. This part is still missing in this PR.Rename
frontend
toview
Based on the feedback from @mtias, I included the change that promotes the name
view
for the script to make it more general. The reasoning is that the output generated by blocks can be consumed not only the frontend part of WordPress but you could render them inside the WP-Admin.How has this been tested?
I tested with the Navigation block and its "Enable responsive menu" option enabled in the sidebar menu.
Once you insert the block, enable the option. It has to be tested on the front end on small viewports.
It should be tested also with the File block and embed previews for PDF files.
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue).
Checklist:
*.native.js
files for terms that need renaming or removal).