Skip to content

Fix incorrect product data displayed in Product Collection in context of Single Product block - #44123

Merged
kmanijak merged 11 commits into
trunkfrom
43991-product-collection-displays-content-from-single-product-block-when-used-in-single-product-block
Feb 1, 2024
Merged

kmanijak merged 11 commits into
trunkfrom
43991-product-collection-displays-content-from-single-product-block-when-used-in-single-product-block

Conversation

@kmanijak

@kmanijak kmanijak commented Jan 26, 2024 •

Copy link
Copy Markdown
Contributor

The initial approach is more like POC. Unfortunately, it has an impact on the performance so won't be a way.

Submission Review Guidelines:

Changes proposed in this Pull Request:

Product Collection (or more technically Product Template) has been using BlockContextProvider to pass the product context to nested blocks. This was following the core's Query Loop block.

However, in Blocks world, many blocks are using ProductDataContextProvider along with withProduct HOC. That includes Single Product block and Product Elements (excluding Product Title and Product Summary that are variations of core blocks).

Problem:
The problem was that Product Collection displayed content from Single Product block when used in Single Product block (check Before/After below). This is due to:

  • most of Product Elements (e.g. Image, Price) read the ProductDataContextProvider set by Single Product parent and wouldn't care about BlockContextProvider
  • Title read the BlockContextProvider set by Product Template and wouldn't care about ProductDataContextProvider

Solution:
Considering we have inner blocks reacting on two separate contexts we need to pass both of them.

Closes #43991

How to test the changes in this Pull Request:

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

  1. Create new post
  2. Add Product Collection block
  3. Choose any collection
  4. Expected: Make sure all the products display correct data. Example of incorrect data:
  • "Title" as product name
  • Duplicated images
  • Duplicated prices
  1. Focus on different product elements (image, price, title) and make sure there's no blinking or images reloading
  2. Add Single Product block
  3. Add Product Collection block inside of Single Product block (note: make sure you're adding it inside some Column block. It's forbidden to add any block inside Columns block)
  4. Expected: Make sure all the products display correct data. Example of incorrect data:
  • "Title" as product name
  • Duplicated images or images taken from wrapping Single Product block
  • Duplicated prices or prices taken from wrapping Single Product block
  1. Focus on different product elements (image, price, title) and make sure there's no blinking or images reloading
Before After
image image

Changelog entry

  • Automatically create a changelog entry from the details below.
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

Comment

…ollection in context of Single Product block
@kmanijak kmanijak changed the title Initial approach to fix incorrect product data displayed in Product C… Initial approach to fix incorrect product data displayed in Product Collection in context of Single Product block Jan 26, 2024
@kmanijak kmanijak changed the title Initial approach to fix incorrect product data displayed in Product Collection in context of Single Product block Fix incorrect product data displayed in Product Collection in context of Single Product block Jan 26, 2024
@github-actions

github-actions Bot commented Jan 26, 2024 •

Copy link
Copy Markdown
Contributor

Test Results Summary

Commit SHA: ca30928

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 37s
E2E Tests1900011803084m 30s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@github-actions github-actions Bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jan 30, 2024
@kmanijak kmanijak added Kirigami WC Store Editing (FSE) block: product collection Issues related to the Product Collection block labels Jan 31, 2024
…rom-single-product-block-when-used-in-single-product-block
…rom-single-product-block-when-used-in-single-product-block
@kmanijak
kmanijak marked this pull request as ready for review January 31, 2024 15:26
@woocommercebot
woocommercebot requested review from a team and thealexandrelara and removed request for a team January 31, 2024 15:26
@kmanijak
kmanijak requested a review from imanish003 January 31, 2024 15:26
@github-actions

github-actions Bot commented Jan 31, 2024 •

Copy link
Copy Markdown
Contributor

Hi @imanish003, @thealexandrelara,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@thealexandrelara thealexandrelara left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great job! I left a comment with a minor improvement proposal, but I'm approving this PR.

✅ All the products are displayed correctly inside the Product Collection (Beta) block
✅ All the products are displayed correctly inside the Product Collection (Beta) block, when the block is included inside the Single Product block.

There are a few things I noticed while testing that I don't think are blockers for this PR, but I wanted to report them to you just in case they haven't been mapped already. I can create separate issues for these if you think it's necessary.

⚠️ During testing, I noticed that when switching the selection between product names, the products in the second row shift slightly. You can see this behavior in the video below.

⚠️ When I select a product name, it appears as a link and the cursor changes to a "pointer," even though the link isn't clickable in the editor. You can see this behavior in the video below.

CleanShot.2024-01-31.at.17.00.57.mp4

⚠️ There is no space to the right side of the Product Collection block:
CleanShot 2024-01-31 at 17 13 33@2x

@kmanijak

kmanijak commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

@thealexandrelara Appreciate the review! I'll double-check if this PR introduces the issues you spotted or if they are already on trunk. If the latter, I'll create followup issues not to block this fix.

PS. But great catches! I think we're too biased with @imanish003 by constantly working with this block and don't spot such stuff so really good to have fresh eyes looking at the Product Collection! 😅

@kmanijak

kmanijak commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

@thealexandrelara, I verified the issues you raised and they all exist in trunk so I went ahead and created issues for them:

During testing, I noticed that when switching the selection between product names, the products in the second row shift slightly. You can see this behavior in the video below.

It's been introduced with woocommerce/woocommerce-blocks#12041 while I think the original PR didn't account for Product Collection responsiveness which can break block into two rows.
Issue: #44253

When I select a product name, it appears as a link and the cursor changes to a "pointer," even though the link isn't clickable in the editor. You can see this behavior in the video below.

Product Title is a variation of Gutenberg's post title so that would have to be changed upstream. But personally, I'm not sure if that's a bug or not TBH.

There is no space to the right side of the Product Collection block:

Good spot, issue created: #44255

@thealexandrelara

Copy link
Copy Markdown
Contributor

Thank you for creating issues for these. Yeah, after testing, I noticed it wasn't something related to these changes, so thank you for double-checking this.

Product Title is a variation of Gutenberg's post title so that would have to be changed upstream. But personally, I'm not sure if that's a bug or not TBH.

I wonder if we can use the Disabled component in this case, WDYT?

@kmanijak
kmanijak merged commit 84f2de6 into trunk Feb 1, 2024
@kmanijak
kmanijak deleted the 43991-product-collection-displays-content-from-single-product-block-when-used-in-single-product-block branch February 1, 2024 16:55
@github-actions github-actions Bot added this to the 8.7.0 milestone Feb 1, 2024
@kmanijak

kmanijak commented Feb 1, 2024

Copy link
Copy Markdown
Contributor Author

I wonder if we can use the Disabled component in this case, WDYT?

@thealexandrelara , forgot such a component exists! Here's an issue: #44277. I may tackle those three soon to relax after heavier stuff! Again, appreciate the attention to detail! 🙌

thealexandrelara pushed a commit that referenced this pull request Feb 1, 2024
… of Single Product block (#44123)

* Initial approach to fix incorrect product data displayed in Product Collection in context of Single Product block

* Remove the BlockCOntextProvider

* Add Block context for title and summary

* Add changelog

* Improve typing

* Add E2E test with Product Collection inside Single Product block

* Improve insertBLock function description

* Make productPrices selector in Product Collectionmore specific

* Extract components props into a types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

block: product collection Issues related to the Product Collection block Kirigami WC Store Editing (FSE) plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Product Collection displays content from Single Product block when used in Single Product block

3 participants