Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Only allow one instance of the All Products block per page/post. #1383

Merged
merged 2 commits into from
Dec 16, 2019

Conversation

nerrad
Copy link
Contributor

@nerrad nerrad commented Dec 14, 2019

Fixes: #1376

For background, see #1376. One problem we face in fixing this, is currently our implementation of All Products (and related filter blocks) doesn't really support multiple instances at the top level of the post_content. While we do have support for multiple instances, that must happen within a container block level otherwise there is no way to link various filter blocks to controlling the request for the All Products block. So currently, any blocks added to the top level context will inherit the same query context (which is "page") for all blocks added on the page. So if setting changes are made to one block, it will apply to all blocks linked to the same client data store (+ related requests for that specific data store) and context.

So, the only way we can have isolated settings per All Products block and Filter Block variations is to have them within a container that defines the context (see #1261). That is something I don't think would be too hard to implement, and we will want to do it in a future iteration, but it'd be good to see if this is something even needed right away (by gauging response/feedback to the current blocks)?

As a result, I think the short term fix here is to simply only allow one All Products block to be inserted at the top level page (and the same for filter blocks). The exception will be the attribute filter blocks because there may be more than one of them (for multiple attributes).

To Test

Verify there can only be one instance of the following blocks added to a page/post:

  • All Products
  • Price Filter
  • Active Filter

Attribute Filter blocks can still have multiple instances added.

cc @pmcpinto, @jwold, @garymurray for your input on this solution for the WC 3.9 release. Do you have any concerns about this approach?

@nerrad nerrad requested a review from a team December 14, 2019 15:50
@nerrad nerrad self-assigned this Dec 14, 2019
@nerrad nerrad added the type: bug The issue/PR concerns a confirmed bug. label Dec 14, 2019
@nerrad nerrad added this to the 2.5.5 milestone Dec 14, 2019
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

As a result, I think the short term fix here is to simply only allow one All Products block to be inserted at the top level page (and the same for filter blocks).

Agree with you, this seems to be the best solution for WooCommerce 3.9, after that we could explore other ideas like the container block.

LGTM

@garymurray
Copy link

garymurray commented Dec 16, 2019

Agree that the short term fix sounds best here while we determine if there is a need/use case of having more than one of these blocks on a page.

@nerrad nerrad merged commit d0fa7dc into master Dec 16, 2019
@nerrad nerrad deleted the fix/preserve-settings-across-multiple-blocks branch December 16, 2019 12:31
@jwold
Copy link

jwold commented Dec 16, 2019

Agree that the short term fix sound best here while we determine if there is a need/use case of having more than one of these blocks on a page.

Agreed with Gary! Thanks for checking into this and calling this out @nerrad

@senadir senadir added the release: cherry-pick Cherry picked into the relevant release branch. label Dec 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release: cherry-pick Cherry picked into the relevant release branch. type: bug The issue/PR concerns a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[WC 3.9 beta1]: All Product Block - when 2 All Product Blocks added, settings of the 1st block get lost
6 participants