-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Migrate the product rating block to fetch product data via the @wordpress/core-data
package
#60127
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
Conversation
…oocommerce into add/entity-product-gallery
…commerce into add/entity-product-price
…ress/core-data package
…ocommerce into add/entity-product-rating
Testing GuidelinesHi @dinhtungdu , 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: +319 B (+0.01%) 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. |
…ntity-product-rating
…ocommerce into add/entity-product-rating
📝 WalkthroughWalkthroughThis change updates the WooCommerce Product Rating block to fetch product data using the Changes
Sequence Diagram(s)sequenceDiagram
participant Editor as Block Editor
participant useProduct as useProduct Hook
participant Block as Product Rating Block
participant Context as Product Data Context
Editor->>useProduct: Fetch product by postId
useProduct-->>Editor: Return product entity
Editor->>Block: Render Block with product, isAdmin
Block->>Context: useProductDataContext({ productEntity, isAdmin })
Context-->>Block: Provide product data
Block->>Block: Compute rating, review count from product
Block->>Block: Render rating UI (show/hide review count)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Possibly related PRs
📜 Recent review detailsConfiguration used: .coderabbit.yml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ 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. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. 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.
Actionable comments posted: 1
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
plugins/woocommerce/changelog/60127-add-entity-product-rating
(1 hunks)plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
(2 hunks)plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
(3 hunks)plugins/woocommerce/client/blocks/assets/js/editor-components/product-rating/index.tsx
(2 hunks)plugins/woocommerce/client/blocks/assets/js/entities/product/types.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/entities/product/types.ts
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
plugins/woocommerce/client/blocks/assets/js/editor-components/product-rating/index.tsx
**/*.{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/entities/product/types.ts
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
plugins/woocommerce/client/blocks/assets/js/editor-components/product-rating/index.tsx
🧠 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: 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.
Learnt from: Aljullu
PR: woocommerce/woocommerce#58809
File: plugins/woocommerce/src/Blocks/BlockTypes/ProductButton.php:222-225
Timestamp: 2025-06-13T17:11:13.732Z
Learning: In `plugins/woocommerce/src/Blocks/BlockTypes/ProductButton.php`, the team intentionally relies on toggling the `disabled` CSS class (via `data-wp-class--disabled`) instead of binding the `disabled` attribute, to mirror the behavior of the classic WooCommerce template.
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: 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.
Learnt from: CR
PR: woocommerce/woocommerce#0
File: .cursor/rules/generate-pr-description.mdc:0-0
Timestamp: 2025-07-21T05:22:46.426Z
Learning: Provide clear, step-by-step instructions for how to test the changes in the PR description.
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: gigitux
PR: woocommerce/woocommerce#58902
File: plugins/woocommerce/client/blocks/assets/js/blocks/product-specifications/edit.tsx:205-206
Timestamp: 2025-06-17T12:40:54.118Z
Learning: In WordPress blocks, when there's a styling mismatch between editor and frontend, check if the PHP renderer (like in `ProductSpecifications.php`) adds specific classes to the output. If so, add those same classes to the `useBlockProps` className in the editor component (like in `edit.tsx`) to ensure consistent styling. For example, adding `wp-block-table` class to both frontend and editor ensures core table styles and theme customizations apply consistently.
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: 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: 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: 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.
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.
📚 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/60127-add-entity-product-rating
📚 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/60127-add-entity-product-rating
plugins/woocommerce/client/blocks/assets/js/entities/product/types.ts
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
plugins/woocommerce/client/blocks/assets/js/editor-components/product-rating/index.tsx
📚 Learning: woocommerce uses wordpress versioning conventions where minor versions in x.y.z format are constrain...
Learnt from: prettyboymp
PR: woocommerce/woocommerce#59048
File: .github/workflows/cherry-pick-milestoned-prs.yml:60-83
Timestamp: 2025-06-26T12:45:40.709Z
Learning: WooCommerce uses WordPress versioning conventions where minor versions in X.Y.Z format are constrained to 0-9 (Y cannot exceed 9). This means version increment logic should reset minor to 0 and increment major when minor reaches 9, rather than allowing two-digit minor versions like 9.10 or 9.11.
Applied to files:
plugins/woocommerce/changelog/60127-add-entity-product-rating
📚 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/60127-add-entity-product-rating
📚 Learning: in `plugins/woocommerce/src/blocks/blocktypes/productbutton.php`, the team intentionally relies on t...
Learnt from: Aljullu
PR: woocommerce/woocommerce#58809
File: plugins/woocommerce/src/Blocks/BlockTypes/ProductButton.php:222-225
Timestamp: 2025-06-13T17:11:13.732Z
Learning: In `plugins/woocommerce/src/Blocks/BlockTypes/ProductButton.php`, the team intentionally relies on toggling the `disabled` CSS class (via `data-wp-class--disabled`) instead of binding the `disabled` attribute, to mirror the behavior of the classic WooCommerce template.
Applied to files:
plugins/woocommerce/changelog/60127-add-entity-product-rating
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
📚 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/60127-add-entity-product-rating
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
plugins/woocommerce/client/blocks/assets/js/editor-components/product-rating/index.tsx
📚 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/60127-add-entity-product-rating
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
📚 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/changelog/60127-add-entity-product-rating
📚 Learning: in wordpress blocks, when there's a styling mismatch between editor and frontend, check if the php r...
Learnt from: gigitux
PR: woocommerce/woocommerce#58902
File: plugins/woocommerce/client/blocks/assets/js/blocks/product-specifications/edit.tsx:205-206
Timestamp: 2025-06-17T12:40:54.118Z
Learning: In WordPress blocks, when there's a styling mismatch between editor and frontend, check if the PHP renderer (like in `ProductSpecifications.php`) adds specific classes to the output. If so, add those same classes to the `useBlockProps` className in the editor component (like in `edit.tsx`) to ensure consistent styling. For example, adding `wp-block-table` class to both frontend and editor ensures core table styles and theme customizations apply consistently.
Applied to files:
plugins/woocommerce/changelog/60127-add-entity-product-rating
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
📚 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/changelog/60127-add-entity-product-rating
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
📚 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/changelog/60127-add-entity-product-rating
📚 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/entities/product/types.ts
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
plugins/woocommerce/client/blocks/assets/js/editor-components/product-rating/index.tsx
📚 Learning: in woocommerce email editor (packages/js/email-editor/src/hacks/publish-save.tsx), the currentpost o...
Learnt from: lysyjan
PR: woocommerce/woocommerce#59931
File: packages/js/email-editor/src/hacks/publish-save.tsx:0-0
Timestamp: 2025-07-23T14:53:29.447Z
Learning: In WooCommerce email editor (packages/js/email-editor/src/hacks/publish-save.tsx), the currentPost obtained from select(editorStore).getCurrentPost() is guaranteed to always be a post object, so null safety checks are not required when accessing its properties like status.
Applied to files:
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
📚 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/atomic/blocks/product-elements/rating/edit.tsx
📚 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/atomic/blocks/product-elements/rating/edit.tsx
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
📚 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/atomic/blocks/product-elements/rating/edit.tsx
📚 Learning: do not suggest using `cross-env` in the woocommerce repository as it's deprecated/archived and the t...
Learnt from: gigitux
PR: woocommerce/woocommerce#58785
File: plugins/woocommerce/client/blocks/package.json:0-0
Timestamp: 2025-06-17T10:25:36.686Z
Learning: Do not suggest using `cross-env` in the WooCommerce repository as it's deprecated/archived and the team is working to remove it from blocks commands to reduce the dependency tree. Instead, inline environment variables like `WP_EXPERIMENTAL_MODULES=true knip` should work fine in supported environments.
Applied to files:
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
📚 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/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx
plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx
🧬 Code Graph Analysis (1)
plugins/woocommerce/client/blocks/assets/js/editor-components/product-rating/index.tsx (2)
plugins/woocommerce/client/blocks/assets/js/types/type-defs/product-response.ts (1)
ProductResponseItem
(59-103)plugins/woocommerce/client/blocks/assets/js/entities/product/types.ts (1)
ProductEntityResponse
(82-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
- GitHub Check: Blocks e2e tests 9/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 2/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 3/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Blocks e2e tests 1/10 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
- GitHub Check: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: JavaScript - @woocommerce/block-library [unit]
- GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
- GitHub Check: Lint - @woocommerce/block-library
- GitHub Check: Check Asset Sizes
- GitHub Check: build
🔇 Additional comments (12)
plugins/woocommerce/client/blocks/assets/js/entities/product/types.ts (1)
37-38
: LGTM! Well-structured type additions.The new
rating_count
andaverage_rating
properties follow the existing type patterns and align with the WooCommerce REST API response format. These additions provide the necessary type foundation for the product rating block migration.plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/edit.tsx (3)
12-12
: LGTM! Proper integration of the useProduct hook.The import follows the established pattern for WooCommerce entity hooks.
60-60
: LGTM! Clean product data fetching.The
useProduct
hook usage is correct and follows the expected pattern for fetching product data based on context.
73-73
: LGTM! Proper prop passing to Block component.The
product
andisAdmin
props are correctly passed to the Block component. The Block component handles undefined product cases gracefully in its implementation.plugins/woocommerce/client/blocks/assets/js/atomic/blocks/product-elements/rating/block.tsx (5)
15-15
: LGTM! Proper import of ProductEntityResponse type.The import aligns with the type migration to support the new product entity structure.
29-31
: LGTM! Well-designed props interface update.The addition of
product: ProductEntityResponse
andisAdmin: boolean
props provides the necessary data for the component while maintaining type safety.
37-45
: LGTM! Proper product data handling with defensive programming.The destructuring of
product: productEntity
and passing it touseProductDataContext
with theisAdmin
flag follows the expected pattern. The conditional handling for undefined product with fallbacks to 0 provides good error resilience.
46-47
: LGTM! Safe rating and review extraction.The conditional checks ensure that rating and review values default to 0 when the product is undefined, preventing potential runtime errors.
55-55
: LGTM! Appropriate logic update for showReviewCount.Using
!isDescendentOfQueryLoop
instead of the removedisDescendentOfSingleProductBlock
maintains the intended behavior for review count display.plugins/woocommerce/client/blocks/assets/js/editor-components/product-rating/index.tsx (3)
8-8
: LGTM! Proper import for ProductEntityResponse type.The import supports the union type handling in the utility functions.
17-27
: LGTM! Robust union type handling with proper validation.The updated
getAverageRating
function properly handles bothProductResponseItem
andProductEntityResponse
types. TheparseFloat
parsing withNumber.isFinite
validation and positive value check provides excellent error resilience.
29-49
: LGTM! Excellent backwards compatibility implementation.The
getRatingCount
function demonstrates excellent backwards compatibility by:
- Supporting union types with proper type discrimination using the
in
operator- Checking for both
review_count
andrating_count
properties to handle different product data shapes- Using robust parsing with
isNumber
utility andparseInt
fallback- Providing consistent validation with
Number.isFinite
and positive value checks- Graceful fallback to 0 for invalid or missing data
This approach aligns well with WooCommerce's preference for maintaining consistency while supporting migration between data structures.
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 to me! I test the Product Collection, Product, and All Products blocks. The rating block works as expected for all of them, both in the editor and on the front end.
🖼️ Screenshots/ screen recordings


🌐 Site details
System Status Report
### WordPress Environment ###
WordPress address (URL): [Redacted]
Site address (URL): [Redacted]
WC Version: 10.2.0-dev
Legacy REST API Package Version: The Legacy REST API plugin is not installed on this site.
Action Scheduler Version: ✔ 3.9.3
Log Directory Writable: ✔
WP Version: 6.8.2
WP Multisite: –
WP Memory Limit: 2 GB
WP Debug Mode: ✔
WP Cron: ✔
Language: en_US
External object cache: –
### Server Environment ###
Server Info: nginx/1.25.4
Server Architecture: Darwin 24.5.0 arm64
PHP Version: 7.4.33
PHP Post Max Size: 8 MB
PHP Time Limit: 30
PHP Max Input Vars: 1000
cURL Version: 8.5.0
OpenSSL/3.1.4
SUHOSIN Installed: –
MySQL Version: 8.0.33
Max Upload Size: 2 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ❌ wp_remote_post() failed. Contact your hosting provider.
Remote Get: ✔
### Database ###
[REDACTED]
### Post Type Counts ###
attachment: 26
global_product_addon: 1
page: 22
post: 3
product: 18
product_tab: 1
product_variation: 7
revision: 225
wp_font_face: 36
wp_font_family: 12
wp_global_styles: 4
wp_navigation: 1
wp_template: 8
wp_template_part: 7
### Security ###
Secure connection (HTTPS): ✔
Hide errors from visitors: ❌Error messages should not be shown to visitors.
### Active Plugins (2) ###
Laravel DD for Wordpress: by Peter Hegman – 1.0.1
WooCommerce: by Automattic – 10.2.0-dev
### Inactive Plugins (16) ###
Akismet Anti-spam: Spam Protection: by Automattic - Anti-spam Team – 5.3.6
bbPress: by The bbPress Contributors – 2.6.13
Block Hooks Experiments for WooCommerce: by Automattic –
Custom Product Tabs Manager: by Addify – 1.2.2
Extra product options For WooCommerce | Custom Product Addons and Fields: by ThemeHigh – 3.3.2
Gutenberg: by Gutenberg Team – 20.7.0-rc.1
Hello Dolly: by Matt Mullenweg – 1.7.2
Product Filters for WooCommerce: by WooCommerce – 1.4.38
Query Monitor: by John Blackbourn – 3.17.2
What Can Wp Scripts Do: by The WordPress Contributors – 0.1.0
WooCommerce: by Automattic – 9.7.1 (update to version 10.0.4 is available)
WooCommerce Beta Tester: by WooCommerce – 3.0.0
WooCommerce PayPal Payments: by PayPal – 3.0.0 (update to version 3.0.9 is available)
WooCommerce Product Add-Ons: by Woo – 7.8.1 (update to version 7.9.2 is available)
WooPayments: by WooCommerce – 9.1.0 (update to version 9.7.0 is available)
WP BASIC Auth: by wokamoto – 1.1.4
### Must Use Plugins (1) ###
WooCommerce Product Details Extension Demo: by – 1.0.0
### Settings ###
Legacy API Enabled: –
Force SSL: –
Currency: USD ($)
Currency Position: right_space
Thousand Separator: .
Decimal Separator: ,
Number of Decimals: 1
Taxonomies: Product Types: external (external)
grouped (grouped)
simple (simple)
variable (variable)
Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
exclude-from-search (exclude-from-search)
featured (featured)
outofstock (outofstock)
rated-1 (rated-1)
rated-2 (rated-2)
rated-3 (rated-3)
rated-4 (rated-4)
rated-5 (rated-5)
Connected to WooCommerce.com: –
Enforce Approved Product Download Directories: ✔
HPOS feature enabled: ✔
Order datastore: Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore
HPOS data sync enabled: –
Enabled Features: analytics
marketplace
order_attribution
site_visibility_badge
remote_logging
email_improvements
point_of_sale
custom_order_tables
### Logging ###
Enabled: ✔
Handler: Automattic\WooCommerce\Internal\Admin\Logging\LogHandlerFileV2
Retention period: 30 days
Level threshold: –
Log directory size: 2 MB
### WC Pages ###
Shop base: #7 - /shop/
Cart: #8 - /cart/ - Contains the woocommerce/cart block
Checkout: #9 - /checkout/ - Contains the woocommerce/checkout block
My account: #10 - /my-account/ - Contains the [woocommerce_my_account] shortcode
Terms and conditions: ❌ Page not set
### Theme ###
Name: Twenty Twenty-Five
Version: 1.2
Author URL: https://wordpress.org
Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme
Theme type: Block theme
WooCommerce Support: ❌ Not declared
### Templates ###
Overrides: /Users/tung/workspace/woocommerce/plugins/woocommerce/templates/block-notices/error.php
/Users/tung/workspace/woocommerce/plugins/woocommerce/templates/block-notices/notice.php
/Users/tung/workspace/woocommerce/plugins/woocommerce/templates/block-notices/success.php
### Admin ###
Enabled Features: activity-panels
analytics
product-block-editor
experimental-blocks
coupons
core-profiler
customize-store
customer-effort-score-tracks
import-products-task
experimental-fashion-sample-products
shipping-smart-defaults
shipping-setting-tour
homescreen
marketing
minified-js
mobile-app-banner
onboarding
onboarding-tasks
pattern-toolkit-full-composability
payment-gateway-suggestions
product-custom-fields
printful
remote-inbox-notifications
remote-free-extensions
shipping-label-banner
subscriptions
store-alerts
transient-notices
woo-mobile-welcome
wc-pay-promotion
wc-pay-welcome-page
async-product-editor-category-field
launch-your-store
experimental-wc-rest-api
Disabled Features: product-data-views
experimental-iapi-mini-cart
experimental-iapi-runtime
coming-soon-newsletter-template
product-pre-publish-modal
settings
product-editor-template-system
use-wp-horizon
Daily Cron: ✔ Next scheduled: 2025-08-05 10:10:56 +00:00
Options: ✔
Notes: 84
Onboarding: completed
### Action Scheduler ###
Complete: 91
Oldest: 2025-07-07 01:00:32 +0000
Newest: 2025-08-04 02:40:08 +0000
Failed: 4
Oldest: 2025-03-05 03:00:25 +0000
Newest: 2025-07-21 12:42:44 +0000
Pending: 3
Oldest: 2025-08-04 14:40:08 +0000
Newest: 2025-08-05 02:40:08 +0000
### Status report information ###
Generated at: 2025-08-04 12:08:43 +00:00
Submission Review Guidelines:
Changes proposed in this Pull Request:
Part of #60048
This PR migrates the product rating block to fetch product data via the @wordpress/core-data package.
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
Changelog entry
Changelog Entry Details
Significance
Type
Message
Migrate the product rating block to fetch product data via the
@wordpress/core-data
package.Changelog Entry Comment
Comment