-
Notifications
You must be signed in to change notification settings - Fork 219
Fix Product Rating Block not showing when manually inserted to Single Product Block #9413
Fix Product Rating Block not showing when manually inserted to Single Product Block #9413
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 Report
assets/js/atomic/blocks/product-elements/rating/edit.tsx
|
Size Change: +91 B (0%) Total Size: 1.11 MB
ℹ️ View Unchanged
|
…ally-added-to-single-product-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.
Works like a charm, well done 🎉 ! I've just left a question.
@@ -33,11 +34,25 @@ const Edit = ( { | |||
...context, | |||
}; | |||
const isDescendentOfQueryLoop = Number.isFinite( context.queryId ); | |||
const { isDescendentOfSingleProductBlock } = useSelect( ( select ) => { |
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.
Would it be worth having this logic stored as a React hook for shared usage across all inner blocks for the Single Product? Could other blocks, such as price and add to cart, also benefit from this change?
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.
Yes! I agree with this, today I opened another PR to an issue that I was investigating and I found out that it was being caused by the same thing, so I created a hook in that PR that I'll be using to refactor this and other blocks that need it
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.
Cool! Looking forward to having #9446 merged so this PR can benefit from this update.
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.
Summary
This solves an issue that was being caused when manually adding the Product Rating block to the Single Product block. The "isDescendentOfSingleProductBlock" attribute is what defines how the Product Rating block will behave depending on the context in which it is inserted. The issue is that when the Product Rating block was manually added, this attribute remained with a
false
value, so this way the block didn't know that it was inside the context of the Single Product block.Walkthrough
🤖 Generated by Copilot at 8b7b69e
useSelect
hook from@wordpress/data
package to select data from WordPress data store (link)Edit
component to useuseSelect
hook to check if block is a descendent ofwoocommerce/single-product
block and store result in new attributeisDescendentOfSingleProductBlock
(link)isDescendentOfSingleProductBlock
andisDescendentOfQueryLoop
attributes (link)useEffect
hook to set both attributes when component mounts or updates (link)BlockAttributes
interface to include new attribute (link)Fixes #9333
Accessibility
prefers-reduced-motion
Other Checks
Testing
Automated Tests
User Facing Testing
WooCommerce Visibility