This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
Pass proper data to On Sale badge when used in the scope of Product Image #9021
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was no information about product passed to the block, so it fetched information about all products which then wasn't even used
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
🎉 🎉 This PR does not introduce new TS errors. |
Size Change: +37 B (0%) Total Size: 1.11 MB
ℹ️ View Unchanged
|
kmanijak
added
block-type: product elements
Issues related to Product Element blocks.
block-type: product-query
Issues related to/affecting all product-query variations.
labels
Apr 14, 2023
kmanijak
changed the title
Don't use withProductDataContext in Sale Badge block
Pass proper data to On Sale badge when used in the scope of Product Image
Apr 14, 2023
woocommercebot
requested review from
a team and
gigitux
and removed request for
a team
April 14, 2023 09:15
gigitux
approved these changes
Apr 18, 2023
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
block-type: product elements
Issues related to Product Element blocks.
block-type: product-query
Issues related to/affecting all product-query variations.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Product Image reuses On Sale badge block here, but it only passes "block-related" props like
align
andproduct
. However, On Sale badge is wrapped withwithProductDataContext
, which requires additional contextual props, mainly:productId
orpostId
(check here).In this case
productId
was not passed (and neitherisDescendentOfQueryLoop
) so what happened:id
here was undefinedid
all the products have been returned, which had no real value.With this change, the unnecessary call to Store API:
http://store.local/wp-json/wc/store/v1/products?_locale=user
is avoided.You may spot that there's a check that should prevent that to happen. However, because of the data flow,
product
isundefined
at the beginning and that data is hydrated in next re-renders, causing the call to happen anyway. With this change, we make sure that On Sale badge within Product Image has the same context as other product elements, hence the call for a particular product is not duplicated.This PR is a part of #8131
Screenshots
Testing
Automated Tests
User Facing Testing
Additional testing steps for developers - do not include in the Testing Notes
http://store.local/wp-json/wc/store/v1/products?
include={ID}
query paramWooCommerce Visibility
Performance Impact
Changelog