Skip to content
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

Possible unintended interaction with duplicating a query loop block. #46079

Closed
albanyacademy opened this issue Nov 25, 2022 · 5 comments
Closed
Labels
[Block] Query Loop Affects the Query Loop Block [Type] Bug An existing feature does not function as intended

Comments

@albanyacademy
Copy link

albanyacademy commented Nov 25, 2022

Description

When duplicating a query loop block, a query ID is also duplicated along with it.

This means that on the page, things like pagination or taxonomy filtering gets applied to all of the duplicated blocks.

The average (re: lazy) user will likely want to duplicate a block they've spent time carefully crafting, so this interaction may not be what they have in mind when they do this. There's also zero feedback to the user that this linked effect is taking place, they can only observe it on the front end.

This behaviour is also true when copying and pasting, or when converting a query block stored as a Reusable block back into a regular block.

There's definitely a use case for having multiple query blocks respond to the same query, though for the most part I would suggest that this shouldn't be the default behaviour - that should be an explicit user action, and they should be allowed to specify which Query Blocks are linked (i.e. share the same query).

Something like this would address it:

At query-block/edit/query-content.js

useEffect( () => {
  if ( ! Number.isFinite( queryId ) || instanceId !== queryId ) {
          __unstableMarkNextChangeAsNotPersistent();
	  setAttributes( { queryId: instanceId } );
  }
}, [ queryId, instanceId ] );

As an aside, outside of the query block afaik there's not really any support for the concept of a "unique" attribute either - such as auto-generating an element ID in a custom block - within the context of editing a page. It would be good to have this set to an attribute property, ala:
"blockId": { "type":"string", "isUnique": true }

I'm not sure how much of a valid use case there is with the builtin blocks beyond query block for such a feature, and for customizing blocks it's easy enough to add it yourself, but food for thought.

Step-by-step reproduction instructions

  • Add a query block
  • Duplicate, copy and paste, or convert to a reusable block, duplicate and convert the duplicate back to normal blocks

observe on the front end that pagination is applied to all query blocks added via the above method.

Screenshots, screen recording, code snippet

No response

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@albanyacademy
Copy link
Author

The full-site editor would likely prove using instanceId as unreliable for requiring a truly unique queryId. Perhaps prefixing it based on edit context (edit-post vs edit-site) could help.

@Thelmachido Thelmachido added the [Type] Bug An existing feature does not function as intended label Dec 6, 2022
@skorasaurus skorasaurus added [Block] Query Loop Affects the Query Loop Block Needs Testing Needs further testing to be confirmed. labels Dec 6, 2022
@ndiego
Copy link
Member

ndiego commented Dec 13, 2022

This issue was reviewed in today's Editor Bug Scrub. We were able to replicate and also confirmed that manually changing the queryId allows pagination to work independently on the copy and the original.

@ndiego ndiego removed the Needs Testing Needs further testing to be confirmed. label Dec 13, 2022
@ntsekouras
Copy link
Contributor

Thanks for the issue @albanyacademy!

As an aside, outside of the query block afaik there's not really any support for the concept of a "unique" attribute either - such as auto-generating an element ID in a custom block - within the context of editing a page. It would be good to have this set to an attribute property, ala:
"blockId": { "type":"string", "isUnique": true }

I'm not sure how much of a valid use case there is with the builtin blocks beyond query block for such a feature, and for customizing blocks it's easy enough to add it yourself, but food for thought.

There is an issue about this here with lots of discussions and explorations, but haven't made it to the finish line. We'd have to revisit this.

@albanyacademy
Copy link
Author

Just getting back to this, __experimentalRole:"internal" is a great idea.

@skorasaurus
Copy link
Member

Thanks for reporting and your thorough work; there's additional context and work on this at #55823 so I'm closing this issue to consolidate reports and efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Loop Affects the Query Loop Block [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

5 participants