Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## trunk #37350 +/- ##
========================================
Coverage 45.8% 45.8%
Complexity 17196 17196
========================================
Files 429 429
Lines 64911 64911
========================================
Hits 29703 29703
Misses 35208 35208
|
Test Results SummaryCommit SHA: 27af4f9
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
louwie17
left a comment
There was a problem hiding this comment.
Thanks for addressing this @joshuatf, I was going to create an issue for this, but you beat me to it by pushing up a PR 🎉
These changes look good, so approving! I did leave some thoughts about calling initBlocks and registerCoreBlocks outside of the respective editor components, something handled by the consumer (aka our client/admin code), but that could also be a follow up.
| const blocks = coreBlocks.filter( ( block: BlockInstance ) => { | ||
| const isRegistered = !! getBlockType( block.name ); | ||
| return ! isRegistered && ALLOWED_CORE_BLOCKS.includes( block.name ); | ||
| } ); |
| const coreBlocks = __experimentalGetCoreBlocks(); | ||
| const blocks = coreBlocks.filter( ( block: BlockInstance ) => { | ||
| return ! getBlockType( block.name ); | ||
| } ); |
There was a problem hiding this comment.
Nice, I guess this works to :)
I had talked with @mdperez86 about it, and thought the initBlocks should more so be something triggered outside of the editor package (same goes for the rich text editor component ), so controlled by the client instead of the editor component.
But this logic would be handy anyhow and fixes the immediate problem. It may still be nice to move the initBlocks and registerCoreBlocks calls outside of the respective Editor components, but that could be a future change.
There was a problem hiding this comment.
Ya, I'm also thinking the same.
Part of me feels like there may be performance gains to not initialize blocks on every single WCA page and only do it when these components are loaded, but those gains may be overstated or even non-existent.
But let's leave it for a follow-up and we can think about the best way to enqueue all these blocks/assets for various use cases in WCA.
There was a problem hiding this comment.
this is not fixed for all use cases. If one is using the filter to add block editor to the product post type, there is no conditional check (here) to prevent the duplicate loading of core blocks error. For example, using the filter itself, in a snippet, with the Kadence theme, it generates the following console errors (truncated):
blocks.min.js?ver=639e14271099dc3d85bf:3 Block "woocommerce/product-summary" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 Ke @ index.js?ver=7.7.2:2 (anonymous) @ index.js?ver=7.7.2:2 (anonymous) @ index.js?ver=7.7.2:2 (anonymous) @ index.js?ver=7.7.2:2 (anonymous) @ index.js?ver=7.7.2:2 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "woocommerce/product-sku" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 At @ index.js?ver=7.7.2:2 (anonymous) @ index.js?ver=7.7.2:2 (anonymous) @ index.js?ver=7.7.2:2 (anonymous) @ index.js?ver=7.7.2:2 (anonymous) @ index.js?ver=7.7.2:2 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/paragraph" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 Uh @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/image" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 Xu @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/heading" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 yu @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/gallery" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 Ic @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/list" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 Fm @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/list-item" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 ld @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/quote" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 my @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/archives" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 tt @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/audio" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 Qt @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/button" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 _n @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/buttons" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 Mn @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/calendar" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 Dn @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/categories" is already registered. ne @ blocks.min.js?ver=639e14271099dc3d85bf:3 je @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 Wn @ block-library.min.js?ver=3115f0b5551a55bb6d3b:12 (anonymous) @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 SE @ block-library.min.js?ver=3115f0b5551a55bb6d3b:14 Io @ edit-post.min.js?ver=d098b8ee5bdffa238c03:7 (anonymous) @ post.php?post=478&action=edit:293 blocks.min.js?ver=639e14271099dc3d85bf:3 Block "core/freeform" is already registered.
Suggest that some type of conditional check needs to be added to determine whether the block editor has already been applied to the product post type by some other (legacy) method and if so, to prevent also triggering the loading of default gutenberg blocks for core and woocommerce
There was a problem hiding this comment.
so controlled by the client instead of the editor component.
YES! You understand. As it is, there are so many legacy use cases from plugins/customization that folks have created for WooCommerce product pages that forced the use of Gutenberg...it is causing great grief to try and remedy the errors being generated by NOT giving anyone a separate option box in WooCommerce as to whether to load block editor and especially whether to load the core blocks (again), which causes an error as I've loaded below.
All Submissions:
Changes proposed in this Pull Request:
Checks core block registration before attempting to register a core block.
Closes #37348 .
How to test the changes in this Pull Request:
Other information:
pnpm --filter=<project> changelog add?FOR PR REVIEWER ONLY: