-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Fix encoded html entities for shipping rate names in cart and checkout blocks #60206
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
base: trunk
Are you sure you want to change the base?
Fix encoded html entities for shipping rate names in cart and checkout blocks #60206
Conversation
Testing GuidelinesHi @ralucaStan , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
Size Change: +287 B (0%) Total Size: 5.91 MB |
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
📝 WalkthroughWalkthroughThis change standardizes and centralizes the normalization and decoding of cart data within WooCommerce Blocks. It introduces helper functions to decode and clean billing/shipping addresses, coupons, fees, and shipping rates. The Changes
Sequence Diagram(s)sequenceDiagram
participant UI
participant useStoreCart Hook
participant NormalizationHelpers
participant Store
UI->>useStoreCart Hook: Request cart data
useStoreCart Hook->>Store: Fetch raw cart data
useStoreCart Hook->>NormalizationHelpers: Normalize addresses, coupons, fees, shipping rates
NormalizationHelpers-->>useStoreCart Hook: Return normalized data
useStoreCart Hook-->>UI: Return StoreCart object with normalized fields and new state flags
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Possibly related PRs
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: .coderabbit.yml 📒 Files selected for processing (3)
🧰 Additional context used📓 Path-based instructions (2)**/*.{php,js,jsx,ts,tsx}📄 CodeRabbit Inference Engine (.cursor/rules/code-quality.mdc)
Files:
**/*.{php,js,ts,jsx,tsx}⚙️ CodeRabbit Configuration File
Files:
🧠 Learnings (19)📓 Common learnings
📚 Learning: in woocommerce blocks, when porting existing code patterns that have known issues (like parseint tru...
Applied to files:
📚 Learning: in woocommerce blocks, bold styling for `.wc-block-components-product-details__name` should be scope...
Applied to files:
📚 Learning: in woocommerce core repository, changelog entries for all prs live in `plugins/woocommerce/changelog...
Applied to files:
📚 Learning: in the woocommerce fulfillments system, only the ups shipping provider is currently fully implemente...
Applied to files:
📚 Learning: woocommerce legacy javascript files in plugins/woocommerce/client/legacy/js/ must use older javascri...
Applied to files:
📚 Learning: the displaystyleswitcher component in plugins/woocommerce/client/blocks/assets/js/blocks/product-fil...
Applied to files:
📚 Learning: woocommerce block templates have a predictable structure where each block has one top-level div with...
Applied to files:
📚 Learning: in woocommerce blocks typescript code, avoid type assertions (`as`) when accessing properties from u...
Applied to files:
📚 Learning: in woocommerce mini cart implementation, the cart state is server-populated before javascript initia...
Applied to files:
📚 Learning: in plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-addres...
Applied to files:
📚 Learning: for woocommerce mini-cart blocks in plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/, t...
Applied to files:
📚 Learning: in woocommerce's cartschema::get_item_response() method, when called in the context of blocksshareds...
Applied to files:
📚 Learning: in woocommerce email editor store initialization (packages/js/email-editor/src/store/initial-state.t...
Applied to files:
📚 Learning: for woocommerce checkout blocks, lazy loading was removed in favor of direct imports to prevent sequ...
Applied to files:
📚 Learning: in plugins/woocommerce/client/admin/client/settings-payments/components/other-payment-gateways/other...
Applied to files:
📚 Learning: in woocommerce's session handler, the cart merging behavior was revised to always merge guest and us...
Applied to files:
📚 Learning: for woocommerce payments onboarding step tracking in useeffect hooks, only include the active step i...
Applied to files:
📚 Learning: in woocommerce payments onboarding components (like plugins/woocommerce/client/admin/client/settings...
Applied to files:
🧬 Code Graph Analysis (2)plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts (2)
plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts (4)
🔇 Additional comments (7)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Looks good and tests good; went through a order with coupons and shipping rates with -
. A nice to have if you have the capacity would be to add unit tests to the rates util.
}; | ||
|
||
const normalizeCoupons = ( coupons: CartResponseCouponItem[] ) => { | ||
return coupons.length > 0 |
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.
We could be more defensive here and not just reply on the length check. Same for fees and rated
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.
FWIW This is the same code as before just moved into a utility function. I think we can trust the types here; this comes from cartData
which in terms comes from a hook. I think the there were an unexpected type here we'd get problems in many other places before this.
receiveCart, | ||
receiveCartContents, | ||
hasPendingItemsOperations, | ||
shippingAddress, | ||
shippingRates: normalizeShippingRates( cartData.shippingRates ), |
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.
We could use useMemo:
const normalizedShippingRates = useMemo( () => {
return normalizeShippingRates( cartData.shippingRates );
}, [ cartData.shippingRates ] );
same for coupons and fees
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.
@ralucaStan I looked into this. Because cartData.shippingRates
is an object, it is not usable as a hook dependency (changes on every render). So we'd have to stringify the object or something first which would likely mitigate the benefits of using memo. normalizeShippingRates
doesn't do much, just decodes. Should we leave 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.
Yes, we can leave it.
Submission Review Guidelines:
Changes proposed in this Pull Request:
Shipping rate names from the API are encoded. Similar to how we've handled coupons and fees, rates need to be decoded. To this end, I've added a normalization function within
useStoreCart
so all consumers of that hook have decoded entities.While in there, I standardised this approach for the other properties, and sorted the properties alphabetically for readability.
Closes #60139
(For Bug Fixes) Bug introduced in PR # .
How to test the changes in this Pull Request:
-
and not an entity.-
.-
.-
in the order confirmation.Changelog entry
Changelog Entry Details
Significance
Type
Message
Changelog Entry Comment
Comment