Skip to content

Conversation

@dinhtungdu
Copy link
Member

Submission Review Guidelines:

Changes proposed in this Pull Request:

In #60223, we disabled the legacy single script for block themes. However, we overlooked a case where classic themes support block-template-parts. This causes issues with the Product Image Gallery in classic themes that have this support. This PR addresses the problem by ensuring we only dequeue the legacy script for block themes.

Closes #60750

(For Bug Fixes) Bug introduced in PR #60223

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Use a classic theme with block-template-parts support, like Bootstore provided by @crftwrk in `add_theme_support('woocommerce') breaks Product Image Gallery in single product page (WC 10.2) #60750.
  2. Visit a product that has image gallery on the frontend, see the gallery work as expected.

Testing that has already taken place:

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

Fix: ensure we only dequeue legacy assets for block themes.

Changelog Entry Comment

Comment

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Sep 4, 2025
@woocommercebot woocommercebot requested review from a team and gigitux and removed request for a team September 4, 2025 09:14
@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2025

Testing Guidelines

Hi @gigitux @kmanijak ,

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 4, 2025

📝 Walkthrough

Walkthrough

Adds a changelog entry and updates BlockTemplatesController to early-return from dequeue_legacy_scripts when wp_is_block_theme() is false, so legacy single-product scripts are only dequeued for block themes.

Changes

Cohort / File(s) Summary of changes
Changelog entry
plugins/woocommerce/changelog/60758-wooplug-5478-add_theme_supportwoocommerce-breaks-product-image-gallery-in:
Added a new changelog item documenting a patch-level fix that limits dequeuing of legacy assets to block themes.
Block templates controller
plugins/woocommerce/src/Blocks/BlockTemplatesController.php
Added an early-return in dequeue_legacy_scripts when wp_is_block_theme() is false; existing dequeue behavior remains for block themes on product pages.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant WP as WordPress Theme
  participant BTC as BlockTemplatesController
  participant Assets as Legacy Scripts

  User->>WP: Request single product page
  WP->>BTC: dequeue_legacy_scripts()
  alt Non-block theme
    BTC->>BTC: wp_is_block_theme() == false
    note right of BTC #F8ECD1: Early return — no dequeue
    BTC-->>WP: Return
  else Block theme
    BTC->>BTC: wp_is_block_theme() == true
    BTC->>Assets: Dequeue `wc-single-product` (legacy)
    Assets-->>BTC: Script dequeued
    BTC-->>WP: Return
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs


📜 Recent review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 614da8b and c788871.

📒 Files selected for processing (1)
  • plugins/woocommerce/src/Blocks/BlockTemplatesController.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/woocommerce/src/Blocks/BlockTemplatesController.php
⏰ 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). (24)
  • GitHub Check: Blocks e2e tests 10/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 1/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 7/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 8/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 9/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 3/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 4/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core API tests - @woocommerce/plugin-woocommerce [api]
  • GitHub Check: Blocks e2e tests 2/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 6/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
  • GitHub Check: Core e2e tests 6/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 5/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.3] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 7.4 WP: latest - 1 [WP 6.7.3] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: PHP: 8.4 WP: latest [WP latest] 1/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: PHP: 8.4 WP: latest [WP latest] 2/2 - @woocommerce/plugin-woocommerce [unit:php]
  • GitHub Check: Core e2e tests 2/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Lint - @woocommerce/plugin-woocommerce
  • GitHub Check: build
✨ 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-5478-add_theme_supportwoocommerce-breaks-product-image-gallery-in

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.
    • 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.
  • 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 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/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
plugins/woocommerce/src/Blocks/BlockTemplatesController.php (2)

41-43: Style nit: add space after if per WP coding standards.

Keeps consistency with the rest of the file.

-        if( ! wp_is_block_theme() ) {
+        if ( ! wp_is_block_theme() ) {

41-43: Add regression coverage for both theme types.

  • Classic theme with block-template-parts support: ensure wc-single-product remains enqueued and the gallery initializes.
  • Block theme: ensure the script is dequeued on product pages.

Note: Based on retrieved learnings, keep any existing hard-coded “woocommerce/woocommerce//” template IDs/slugs in e2e tests as-is for backwards-compat checks.

I can draft a minimal e2e test pair exercising these paths. Want me to open a follow-up PR with the tests?

📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ae73072 and 614da8b.

📒 Files selected for processing (2)
  • plugins/woocommerce/changelog/60758-wooplug-5478-add_theme_supportwoocommerce-breaks-product-image-gallery-in (1 hunks)
  • plugins/woocommerce/src/Blocks/BlockTemplatesController.php (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/src/Blocks/BlockTemplatesController.php
**/*.{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/src/Blocks/BlockTemplatesController.php
🧠 Learnings (3)
📚 Learning: 2025-08-14T08:19:54.208Z
Learnt from: Aljullu
PR: woocommerce/woocommerce#60191
File: plugins/woocommerce/src/Blocks/BlockTemplatesRegistry.php:93-111
Timestamp: 2025-08-14T08:19:54.208Z
Learning: WooCommerce core template files (.html files in src/Blocks/templates/wp_template/) are guaranteed to exist as they are provided by WC core, so defensive file_exists() checks are not necessary when loading these templates in BlockTemplatesRegistry.php.

Applied to files:

  • plugins/woocommerce/src/Blocks/BlockTemplatesController.php
📚 Learning: 2025-08-14T08:20:36.357Z
Learnt from: Aljullu
PR: woocommerce/woocommerce#60191
File: plugins/woocommerce/client/blocks/tests/e2e/tests/single-product-template/single-product-template-compatibility-layer.spec.ts:4-4
Timestamp: 2025-08-14T08:20:36.357Z
Learning: In WooCommerce e2e tests, some test files intentionally use hard-coded "woocommerce/woocommerce//" template IDs instead of BLOCK_THEME_SLUG to test backwards compatibility with the legacy plugin-scoped template ID format. These should not be updated to use the dynamic slug constant as they serve a specific testing purpose.

Applied to files:

  • plugins/woocommerce/src/Blocks/BlockTemplatesController.php
📚 Learning: 2025-08-14T08:22:34.886Z
Learnt from: Aljullu
PR: woocommerce/woocommerce#60191
File: plugins/woocommerce/client/blocks/tests/e2e/tests/product-filters/rating-filter-editor.block_theme.spec.ts:36-36
Timestamp: 2025-08-14T08:22:34.886Z
Learning: In WooCommerce e2e tests, some test files intentionally use hard-coded "woocommerce/woocommerce//" template slugs (not just template IDs) instead of BLOCK_THEME_SLUG to test backwards compatibility with the legacy plugin-scoped template slug format. These should not be updated to use the dynamic slug constant as they serve a specific backwards compatibility testing purpose.

Applied to files:

  • plugins/woocommerce/src/Blocks/BlockTemplatesController.php
🔇 Additional comments (2)
plugins/woocommerce/changelog/60758-wooplug-5478-add_theme_supportwoocommerce-breaks-product-image-gallery-in (1)

1-4: Changelog entry reads well and matches the fix scope.

Accurately describes the patch and impact. Nothing else to do.

plugins/woocommerce/src/Blocks/BlockTemplatesController.php (1)

41-43: LGTM: Correctly gate dequeuing to block themes.

This early return prevents breaking classic themes that only support block-template-parts. This should resolve the gallery regression while preserving the intended behavior for block themes.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 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.

@dinhtungdu dinhtungdu requested review from kmanijak and removed request for gigitux September 4, 2025 09:51
@dinhtungdu dinhtungdu closed this Sep 4, 2025
@dinhtungdu dinhtungdu reopened this Sep 4, 2025
Copy link
Contributor

@kmanijak kmanijak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dinhtungdu, works as expected! Appreciate you responded in the original issue and provided a fix so quickly! 🙏

I think this requires backporting to 10.2 so please add 10.2 milestone before merging!

@dinhtungdu dinhtungdu added this to the 10.2.0 milestone Sep 5, 2025
@dinhtungdu dinhtungdu merged commit ad2f680 into trunk Sep 5, 2025
44 checks passed
@dinhtungdu dinhtungdu deleted the wooplug-5478-add_theme_supportwoocommerce-breaks-product-image-gallery-in branch September 5, 2025 07:27
github-actions bot pushed a commit that referenced this pull request Sep 5, 2025
* fix: only dequeue legacy assets for block themes

* Add changefile(s) from automation for the following project(s): woocommerce

* chore: lint

---------

Co-authored-by: github-actions <github-actions@github.com>
@woocommercebot
Copy link
Collaborator

IMPORTANT: Merging this PR to the appropriate branches is critical to the release process and ensures that the bug does not cause regressions in the future releases.

Cherry picking was successful for release/10.2. Please merge the following PR: [Backport to release/10.2] Fix: only dequeue legacy assets for block themes

dinhtungdu added a commit that referenced this pull request Sep 5, 2025
…themes (#60781)

* Fix: only dequeue legacy assets for block themes (#60758)

* fix: only dequeue legacy assets for block themes

* Add changefile(s) from automation for the following project(s): woocommerce

* chore: lint

---------

Co-authored-by: github-actions <github-actions@github.com>

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: Tung Du <dinhtungdu@gmail.com>
Co-authored-by: github-actions <github-actions@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

`add_theme_support('woocommerce') breaks Product Image Gallery in single product page (WC 10.2)

4 participants