Skip to content

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

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

mikejolley
Copy link
Member

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:

  1. Enable free shipping and re-label it as "Free Shipping - Dash". Disable other methods.
  2. Enable Local Pickup and rename re-label it as "Local Pickup - Dash"
  3. Add a dash to the name of some pickup locations
  4. Add an item to cart and go to the cart page. Free shipping should be selected (if not, go to checkout and select it). Ensure the dash is an actual - and not an entity.
  5. Go to checkout and see the shipping rate name in order summary. Check the dash is a -.
  6. Select local pickup and a location. Check the dash is a -.
  7. Place order. Check the shipping name uses a real - in the order confirmation.

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

@mikejolley mikejolley self-assigned this Aug 5, 2025
@mikejolley mikejolley added the Cart Issues related to the cart. label Aug 5, 2025
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Aug 5, 2025
@woocommercebot woocommercebot requested review from a team and ralucaStan and removed request for a team August 5, 2025 12:55
Copy link
Contributor

github-actions bot commented Aug 5, 2025

Testing Guidelines

Hi @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:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

Copy link
Contributor

github-actions bot commented Aug 5, 2025

Size Change: +287 B (0%)

Total Size: 5.91 MB

compressed-size-action

Copy link
Contributor

github-actions bot commented Aug 5, 2025

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

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.

Copy link
Contributor

coderabbitai bot commented Aug 5, 2025

📝 Walkthrough

Walkthrough

This 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 StoreCart interface and default cart data are expanded with new fields for error handling, state flags, and reordered properties for consistency.

Changes

Cohort / File(s) Change Summary
Changelog Documentation
plugins/woocommerce/changelog/wooplug-5235-double-encoded-html-entities-in-woocommerce-blocks-shipping
Documents a patch fixing double-encoded HTML entities in shipping rate names for WooCommerce Blocks Cart and Checkout, ensuring correct display of special characters.
Cart Data Normalization & Decoding
plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
Adds normalization helper functions for billing/shipping addresses, coupons, fees, and shipping rates. Extends the decodeValues function to support shipping rate objects. Updates the defaultCartData object and the useStoreCart hook to use normalization, include new fields (error arrays, state flags), and reorder properties for clarity. Refactors address handling and centralizes decoding logic.
StoreCart Type Expansion
plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
Expands and reorders the StoreCart interface, adding properties for billing address, error arrays, state flags, and a deprecated billing data alias. Adjusts property order for clarity and consistency, but does not change method signatures.

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
Loading

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 details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2fc4ff7 and 57af1a6.

📒 Files selected for processing (3)
  • plugins/woocommerce/changelog/wooplug-5235-double-encoded-html-entities-in-woocommerce-blocks-shipping (1 hunks)
  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts (4 hunks)
  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/code-quality.mdc)

**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable

Files:

  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
**/*.{php,js,ts,jsx,tsx}

⚙️ CodeRabbit Configuration File

**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:

  • Guards against unexpected inputs.
  • Sanitizes and validates any potentially dangerous inputs.
  • Is backwards compatible.
  • Is readable and intuitive.
  • Has unit or E2E tests where applicable.

Files:

  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
🧠 Learnings (19)
📓 Common learnings
Learnt from: samueljseay
PR: woocommerce/woocommerce#58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.
Learnt from: ralucaStan
PR: woocommerce/woocommerce#58782
File: plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/product-details/style.scss:21-26
Timestamp: 2025-06-13T15:24:45.923Z
Learning: In WooCommerce blocks, bold styling for `.wc-block-components-product-details__name` should be scoped only to the Cart block (`.wc-block-cart__main`); on the Checkout block, product names are not bold because prices are highlighted instead.
Learnt from: lysyjan
PR: woocommerce/woocommerce#59632
File: packages/js/email-editor/src/layouts/flex-email.tsx:116-122
Timestamp: 2025-07-14T10:41:46.200Z
Learning: In WooCommerce projects, formatting suggestions should respect the project's Prettier configuration and linting rules. Changes that would break the lint job should be avoided, even if they appear to improve readability.
Learnt from: ralucaStan
PR: woocommerce/woocommerce#58782
File: plugins/woocommerce/client/blocks/assets/js/base/utils/render-frontend.tsx:0-0
Timestamp: 2025-06-16T16:12:12.148Z
Learning: For WooCommerce checkout blocks, lazy loading was removed in favor of direct imports to prevent sequential "popping" effects during component loading. This approach prioritizes user experience over code splitting, with minimal bundle size impact and improved performance (1.7s to 1.1s speed score improvement). The checkout flow benefits from having all components load together rather than incrementally.
Learnt from: mreishus
PR: woocommerce/woocommerce#58891
File: plugins/woocommerce/src/Blocks/Utils/BlocksSharedState.php:0-0
Timestamp: 2025-06-16T21:59:26.255Z
Learning: In WooCommerce's CartSchema::get_item_response() method, when called in the context of BlocksSharedState::register_cart_interactivity(), the method returns a plain array rather than a WP_REST_Response object, making it directly suitable for wp_interactivity_state() without needing to call ->get_data().
Learnt from: samueljseay
PR: woocommerce/woocommerce#59051
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-footer-block/index.tsx:66-70
Timestamp: 2025-06-23T05:47:52.696Z
Learning: For WooCommerce mini-cart blocks in plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/, the standardized conditional pattern for experimental features should be `if ( isExperimentalMiniCartEnabled() ) { blockSettings.save = () => <InnerBlocks.Content />; }` - defaulting to the traditional Save component and only overriding when the experimental feature is enabled.
Learnt from: samueljseay
PR: woocommerce/woocommerce#58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:78-96
Timestamp: 2025-06-18T06:05:25.472Z
Learning: In WooCommerce mini cart implementation, the cart state is server-populated before JavaScript initialization, so wooStoreState.cart and wooStoreState.cart.totals will be available on first render without requiring null-safe guards.
Learnt from: mikejolley
PR: woocommerce/woocommerce#57961
File: plugins/woocommerce/includes/class-wc-session-handler.php:302-333
Timestamp: 2025-06-19T11:58:57.484Z
Learning: In WooCommerce's session handler, the cart merging behavior was revised to always merge guest and user carts when both contain items, rather than having the guest cart take precedence. The migrate_cart_data() method in class-wc-session-handler.php implements this by using array_merge() to combine both carts when neither is empty.
Learnt from: gigitux
PR: woocommerce/woocommerce#59659
File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/frontend.ts:136-147
Timestamp: 2025-07-22T09:30:43.528Z
Learning: In WooCommerce blocks TypeScript code, avoid type assertions (`as`) when accessing properties from unified stores. Instead, create proper union types that combine all the different store component types using `Partial<>` wrappers, and export the unified type to help third-party extenders. For example: `type UnifiedStore = BaseStore & Partial<StoreA> & Partial<StoreB>`.
Learnt from: triple0t
PR: woocommerce/woocommerce#59186
File: packages/js/email-editor/src/store/initial-state.ts:9-10
Timestamp: 2025-06-26T12:13:32.062Z
Learning: In WooCommerce email editor store initialization (packages/js/email-editor/src/store/initial-state.ts), the current_post_id and current_post_type from window.WooCommerceEmailEditor are required parameters that should cause explicit errors if missing, rather than using fallback values or optional chaining. The design preference is to fail fast when critical initialization data is unavailable.
Learnt from: nerrad
PR: woocommerce/woocommerce#60176
File: plugins/woocommerce/client/legacy/css/admin.scss:9088-9105
Timestamp: 2025-08-04T00:21:51.440Z
Learning: WooCommerce is currently in the midst of an admin redesign project, so temporary/short-term CSS solutions for admin pages are preferred over long-term refactoring when addressing immediate needs.
📚 Learning: in woocommerce blocks, when porting existing code patterns that have known issues (like parseint tru...
Learnt from: samueljseay
PR: woocommerce/woocommerce#58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.

Applied to files:

  • plugins/woocommerce/changelog/wooplug-5235-double-encoded-html-entities-in-woocommerce-blocks-shipping
  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
📚 Learning: in woocommerce blocks, bold styling for `.wc-block-components-product-details__name` should be scope...
Learnt from: ralucaStan
PR: woocommerce/woocommerce#58782
File: plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/product-details/style.scss:21-26
Timestamp: 2025-06-13T15:24:45.923Z
Learning: In WooCommerce blocks, bold styling for `.wc-block-components-product-details__name` should be scoped only to the Cart block (`.wc-block-cart__main`); on the Checkout block, product names are not bold because prices are highlighted instead.

Applied to files:

  • plugins/woocommerce/changelog/wooplug-5235-double-encoded-html-entities-in-woocommerce-blocks-shipping
  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
📚 Learning: in woocommerce core repository, changelog entries for all prs live in `plugins/woocommerce/changelog...
Learnt from: jorgeatorres
PR: woocommerce/woocommerce#59675
File: .github/workflows/release-bump-as-requirement.yml:48-65
Timestamp: 2025-07-15T15:39:21.856Z
Learning: In WooCommerce core repository, changelog entries for all PRs live in `plugins/woocommerce/changelog/` directory and are processed during releases, not at the repository root level.

Applied to files:

  • plugins/woocommerce/changelog/wooplug-5235-double-encoded-html-entities-in-woocommerce-blocks-shipping
📚 Learning: in the woocommerce fulfillments system, only the ups shipping provider is currently fully implemente...
Learnt from: tpaksu
PR: woocommerce/woocommerce#59172
File: plugins/woocommerce/src/Internal/Fulfillments/Providers/MPLShippingProvider.php:14-21
Timestamp: 2025-06-26T10:47:27.212Z
Learning: In the WooCommerce fulfillments system, only the UPS shipping provider is currently fully implemented. All other shipping provider classes in plugins/woocommerce/src/Internal/Fulfillments/Providers/ are placeholders for future implementations, so empty shipping country arrays and stub methods in these classes are intentional and should not be flagged as issues.

Applied to files:

  • plugins/woocommerce/changelog/wooplug-5235-double-encoded-html-entities-in-woocommerce-blocks-shipping
📚 Learning: woocommerce legacy javascript files in plugins/woocommerce/client/legacy/js/ must use older javascri...
Learnt from: opr
PR: woocommerce/woocommerce#0
File: :0-0
Timestamp: 2025-06-20T17:38:16.565Z
Learning: WooCommerce legacy JavaScript files in plugins/woocommerce/client/legacy/js/ must use older JavaScript syntax and cannot use modern features like optional chaining (?.) due to browser compatibility requirements. Explicit null checking with && operators should be used instead.

Applied to files:

  • plugins/woocommerce/changelog/wooplug-5235-double-encoded-html-entities-in-woocommerce-blocks-shipping
  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
📚 Learning: the displaystyleswitcher component in plugins/woocommerce/client/blocks/assets/js/blocks/product-fil...
Learnt from: dinhtungdu
PR: woocommerce/woocommerce#59900
File: plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/inner-blocks/attribute-filter/inspector.tsx:0-0
Timestamp: 2025-07-24T05:37:00.907Z
Learning: The DisplayStyleSwitcher component in plugins/woocommerce/client/blocks/assets/js/blocks/product-filters/components/display-style-switcher/index.tsx has been updated so that its onChange prop accepts only a string type (not string | number | undefined), eliminating the need for type assertions when using this component.

Applied to files:

  • plugins/woocommerce/changelog/wooplug-5235-double-encoded-html-entities-in-woocommerce-blocks-shipping
  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
📚 Learning: woocommerce block templates have a predictable structure where each block has one top-level div with...
Learnt from: samueljseay
PR: woocommerce/woocommerce#59142
File: plugins/woocommerce/src/Blocks/BlockTypes/MiniCart.php:594-602
Timestamp: 2025-06-25T06:51:41.381Z
Learning: WooCommerce block templates have a predictable structure where each block has one top-level div with wp-block-woocommerce- class containing arbitrary nested content that should be preserved.

Applied to files:

  • plugins/woocommerce/changelog/wooplug-5235-double-encoded-html-entities-in-woocommerce-blocks-shipping
📚 Learning: in woocommerce blocks typescript code, avoid type assertions (`as`) when accessing properties from u...
Learnt from: gigitux
PR: woocommerce/woocommerce#59659
File: plugins/woocommerce/client/blocks/assets/js/blocks/add-to-cart-with-options/frontend.ts:136-147
Timestamp: 2025-07-22T09:30:43.528Z
Learning: In WooCommerce blocks TypeScript code, avoid type assertions (`as`) when accessing properties from unified stores. Instead, create proper union types that combine all the different store component types using `Partial<>` wrappers, and export the unified type to help third-party extenders. For example: `type UnifiedStore = BaseStore & Partial<StoreA> & Partial<StoreB>`.

Applied to files:

  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
📚 Learning: in woocommerce mini cart implementation, the cart state is server-populated before javascript initia...
Learnt from: samueljseay
PR: woocommerce/woocommerce#58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:78-96
Timestamp: 2025-06-18T06:05:25.472Z
Learning: In WooCommerce mini cart implementation, the cart state is server-populated before JavaScript initialization, so wooStoreState.cart and wooStoreState.cart.totals will be available on first render without requiring null-safe guards.

Applied to files:

  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
📚 Learning: in plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-addres...
Learnt from: ralucaStan
PR: woocommerce/woocommerce#58782
File: plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/customer-address.tsx:76-90
Timestamp: 2025-06-13T13:37:35.793Z
Learning: In plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-address-block/customer-address.tsx, the `shouldAnimate` flag is expected to be `false` only on initial render and may remain `true` after the first edit; it does not need to be reset.

Applied to files:

  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
📚 Learning: for woocommerce mini-cart blocks in plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/, t...
Learnt from: samueljseay
PR: woocommerce/woocommerce#59051
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-footer-block/index.tsx:66-70
Timestamp: 2025-06-23T05:47:52.696Z
Learning: For WooCommerce mini-cart blocks in plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/, the standardized conditional pattern for experimental features should be `if ( isExperimentalMiniCartEnabled() ) { blockSettings.save = () => <InnerBlocks.Content />; }` - defaulting to the traditional Save component and only overriding when the experimental feature is enabled.

Applied to files:

  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
📚 Learning: in woocommerce's cartschema::get_item_response() method, when called in the context of blocksshareds...
Learnt from: mreishus
PR: woocommerce/woocommerce#58891
File: plugins/woocommerce/src/Blocks/Utils/BlocksSharedState.php:0-0
Timestamp: 2025-06-16T21:59:26.255Z
Learning: In WooCommerce's CartSchema::get_item_response() method, when called in the context of BlocksSharedState::register_cart_interactivity(), the method returns a plain array rather than a WP_REST_Response object, making it directly suitable for wp_interactivity_state() without needing to call ->get_data().

Applied to files:

  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
📚 Learning: in woocommerce email editor store initialization (packages/js/email-editor/src/store/initial-state.t...
Learnt from: triple0t
PR: woocommerce/woocommerce#59186
File: packages/js/email-editor/src/store/initial-state.ts:9-10
Timestamp: 2025-06-26T12:13:32.062Z
Learning: In WooCommerce email editor store initialization (packages/js/email-editor/src/store/initial-state.ts), the current_post_id and current_post_type from window.WooCommerceEmailEditor are required parameters that should cause explicit errors if missing, rather than using fallback values or optional chaining. The design preference is to fail fast when critical initialization data is unavailable.

Applied to files:

  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
📚 Learning: for woocommerce checkout blocks, lazy loading was removed in favor of direct imports to prevent sequ...
Learnt from: ralucaStan
PR: woocommerce/woocommerce#58782
File: plugins/woocommerce/client/blocks/assets/js/base/utils/render-frontend.tsx:0-0
Timestamp: 2025-06-16T16:12:12.148Z
Learning: For WooCommerce checkout blocks, lazy loading was removed in favor of direct imports to prevent sequential "popping" effects during component loading. This approach prioritizes user experience over code splitting, with minimal bundle size impact and improved performance (1.7s to 1.1s speed score improvement). The checkout flow benefits from having all components load together rather than incrementally.

Applied to files:

  • plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts
  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
📚 Learning: in plugins/woocommerce/client/admin/client/settings-payments/components/other-payment-gateways/other...
Learnt from: vladolaru
PR: woocommerce/woocommerce#58784
File: plugins/woocommerce/client/admin/client/settings-payments/components/other-payment-gateways/other-payment-gateways.tsx:43-50
Timestamp: 2025-06-18T07:56:06.961Z
Learning: In plugins/woocommerce/client/admin/client/settings-payments/components/other-payment-gateways/other-payment-gateways.tsx, the user vladolaru prefers to keep the current setUpPlugin function signature with optional positional context parameter rather than refactoring to an options object or making context required.

Applied to files:

  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
📚 Learning: in woocommerce's session handler, the cart merging behavior was revised to always merge guest and us...
Learnt from: mikejolley
PR: woocommerce/woocommerce#57961
File: plugins/woocommerce/includes/class-wc-session-handler.php:302-333
Timestamp: 2025-06-19T11:58:57.484Z
Learning: In WooCommerce's session handler, the cart merging behavior was revised to always merge guest and user carts when both contain items, rather than having the guest cart take precedence. The migrate_cart_data() method in class-wc-session-handler.php implements this by using array_merge() to combine both carts when neither is empty.

Applied to files:

  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
📚 Learning: for woocommerce payments onboarding step tracking in useeffect hooks, only include the active step i...
Learnt from: vladolaru
PR: woocommerce/woocommerce#58784
File: plugins/woocommerce/client/admin/client/settings-payments/onboarding/components/stepper/index.tsx:57-67
Timestamp: 2025-06-20T13:08:44.017Z
Learning: For WooCommerce Payments onboarding step tracking in useEffect hooks, only include the active step in the dependency array, not the context object. The sessionEntryPoint is static throughout the onboarding session and tracking should only fire on actual step navigation, not context changes.

Applied to files:

  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
📚 Learning: in woocommerce payments onboarding components (like plugins/woocommerce/client/admin/client/settings...
Learnt from: vladolaru
PR: woocommerce/woocommerce#59160
File: plugins/woocommerce/client/admin/client/settings-payments/onboarding/providers/woopayments/steps/payment-methods-selection/index.tsx:0-0
Timestamp: 2025-06-26T14:56:54.917Z
Learning: In WooCommerce payments onboarding components (like plugins/woocommerce/client/admin/client/settings-payments/onboarding/providers/woopayments/steps/payment-methods-selection/index.tsx), when updating local React state based on API calls, the local state should only be updated after the API call succeeds to prevent inconsistent state if the save operation fails. The pattern is to move setPaymentMethodsState calls inside the .then() callback of the API promise.

Applied to files:

  • plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts
🧬 Code Graph Analysis (2)
plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts (2)
plugins/woocommerce/client/blocks/assets/js/types/type-defs/cart-response.ts (9)
  • CartResponseBillingAddress (78-81)
  • CartResponseCoupons (24-24)
  • CartResponseFeeItem (130-134)
  • CartResponseErrorItem (150-153)
  • CartResponseItem (118-118)
  • CartResponseTotals (136-148)
  • CartResponse (159-177)
  • CartResponseShippingAddress (71-76)
  • CartResponseShippingRate (69-69)
plugins/woocommerce/client/blocks/assets/js/types/type-defs/product-response.ts (1)
  • ProductResponseItem (59-103)
plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts (4)
plugins/woocommerce/client/blocks/assets/js/types/type-defs/cart.ts (2)
  • CartShippingPackageShippingRate (60-71)
  • CartShippingRate (73-79)
plugins/woocommerce/client/blocks/assets/js/types/type-defs/cart-response.ts (4)
  • CartResponseBillingAddress (78-81)
  • CartResponseShippingAddress (71-76)
  • CartResponseCouponItem (13-17)
  • CartResponseFeeItem (130-134)
plugins/woocommerce/client/blocks/assets/js/base/utils/address.ts (1)
  • emptyHiddenAddressFields (56-76)
plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts (1)
  • StoreCart (40-66)
🔇 Additional comments (7)
plugins/woocommerce/client/blocks/assets/js/types/type-defs/hooks.ts (1)

41-66: LGTM! Well-structured interface expansion.

The reordering and expansion of the StoreCart interface improves organization and supports the new normalization features. The deprecation of billingData in favor of billingAddress is properly documented.

plugins/woocommerce/changelog/wooplug-5235-double-encoded-html-entities-in-woocommerce-blocks-shipping (1)

1-4: LGTM! Clear and accurate changelog entry.

The changelog entry correctly describes the fix for double-encoded HTML entities in shipping rate names.

plugins/woocommerce/client/blocks/assets/js/base/context/hooks/cart/use-store-cart.ts (5)

29-30: LGTM! Necessary type additions for shipping rate normalization.

The addition of CartShippingRate and CartShippingPackageShippingRate types and the extension of decodeValues to handle shipping rates are essential for fixing the HTML entity encoding issue.

Also applies to: 82-97


99-143: Excellent centralization of normalization logic!

The helper functions properly handle data normalization and HTML entity decoding:

  • normalizeAddress efficiently uses refs to prevent unnecessary re-renders
  • normalizeShippingRates correctly addresses the core issue by decoding shipping rate names
  • All functions properly handle empty arrays

145-170: LGTM! Default cart data properly initialized.

The defaultCartData object correctly implements all properties from the updated StoreCart interface with appropriate default values.


217-250: Well-implemented normalization in the hook!

The useStoreCart hook correctly applies normalization functions to all relevant data:

  • Addresses, coupons, fees, and shipping rates are all properly normalized
  • Backward compatibility maintained with the deprecated billingData property
  • All new state properties are correctly mapped from the store data

This implementation ensures all consumers receive properly decoded data, effectively fixing the double-encoded HTML entities issue.


99-143: Normalization Is Scoped to useStoreCart Only—No Impact on Other Consumers

All searches confirm that decoding and normalization occur solely within the use-store-cart.ts hook. Direct calls to select( cartStore ).getCartData() (and related selectors in reducers, payment utils, etc.) remain untouched and continue to receive raw, encoded values. No existing consumers outside of useStoreCart are affected.

You can safely proceed without further changes.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch wooplug-5235-double-encoded-html-entities-in-woocommerce-blocks-shipping

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@ralucaStan ralucaStan left a 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
Copy link
Contributor

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

Copy link
Member Author

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 ),
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cart Issues related to the cart. plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Double-encoded HTML entities in WooCommerce Blocks shipping method names
2 participants