-
Notifications
You must be signed in to change notification settings - Fork 218
Refactor useForcedLayout
to subscribe to store changes and to batch block insertions
#7879
Conversation
The release ZIP for this PR is accessible via:
|
Script Dependencies ReportThere is no changed script dependency between this branch and trunk. This comment was automatically generated by the |
TypeScript Errors ReportFiles with errors: 429 🎉 🎉 This PR does not introduce new TS errors. |
Size Change: +174 B (0%) Total Size: 975 kB
ℹ️ View Unchanged
|
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 successfully tested this PR both using wp.org and wp.com.
I do have to say that on wp.com, I haven't been able to run npx @wordpress/create-block -t @woocommerce/extend-cart-checkout-block my-test-plugin
. When trying to do that via SSH, I received the following error message:
bash: npx: command not found
Apart from that, the PR was working as expected.
I love the effort you put into testing the performance of this Thomas! |
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 tested this on wordpress.com and there are no regression there as well, the code looks clean, thank you for working on this Thomas!
No worries Niels, you can run that locally, cd into the new directory, run Thank you for testing @nielslange and @senadir |
Following on from the discussion in pca54o-4GY-p2#comment-4658 I implemented the suggestion of @jsnajdr. I altered
useForcedLayout
to subscribe to changes tocore/block-editor
in the registry. I also batched the action dispatches to that store. Whereas we previously inserted blocks individually, we now insert multiple blocks at once if necessary.I added two new functions (the functionality already existed in the old
useForcedLayout
hook, I just separated it):getMissingBlocks
andfindBlockPosition
. These functions find which registered blocks are missing from a forced layout, and find the index that these blocks should be inserted at, respectively.Fixes #7367
Testing
Automated Tests
Internal dev testing
@woocommerce/extend-cart-checkout-block
template. (Go toplugins
and exectue:npx @wordpress/create-block -t @woocommerce/extend-cart-checkout-block my-test-plugin
).Enable tax rates and calculations
)I want to receive updates about products and promotions.
checkbox in the Contact Information block, ensure you see the VAT Number block rendered at the bottom of the Checkout block (this is intentional).User Facing Testing
WooCommerce Visibility
Performance Impact
I tested the performance of my version by logging the difference in
performance.now()
between the start and end of thesubscribe
function (this is where most of the work gets done) and in the old version by logging the difference inperformance.now()
in theuseLayoutEffect
. I took an average of the values of every timestamp collected when inserting a new block and it averaged out around 10ms for both implementations.I also took the following measurements:
Changelog