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

Remove site specific block attributes from theme export #3899

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

jffng
Copy link

@jffng jffng commented Jan 24, 2023

Trac ticket: https://core.trac.wordpress.org/ticket/57537


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@mikachan
Copy link
Member

Thanks so much for working on this, it looks great!

Do you think we should also remove the id attributes from the image and cover blocks? Both these blocks also include wp-image-[id] classes, which I think would be good to remove at the same time.

@jffng
Copy link
Author

jffng commented Jan 24, 2023

Do you think we should also remove the id attributes from the image and cover blocks?

Good idea, done in 76e1636. I also added a filter for the media & text block.

Copy link
Member

@mikachan mikachan left a 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, this will be a great improvement to the theme export.

if ( 'core/query' === $block['blockName'] && isset( $block['attrs']['queryId'] ) ) {
unset( $blocks[ $key ]['attrs']['queryId'] );
$has_updated_content = true;
}

Choose a reason for hiding this comment

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

Are you sure queryId is a site-specific attribute? WordPress/gutenberg#42730 talks about removing ID's from the query block but I think it may have been referring to other attributes.

Copy link
Author

Choose a reason for hiding this comment

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

@ntsekouras would you be able to weigh in here?

This PR is proposing to strip all query blocks of the queryId attribute if the theme is exported using the site editor. My understanding is that the attribute is site specific and shouldn't be set explicitly in theme templates.

Choose a reason for hiding this comment

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

Sorry for the late reply here. queryId is used for proper Query Pagination when we have multiple Query Loop blocks, and there are a few nuances here..

If queryId doesn't exist and a Query Loop block is inserterd in an editor, it will auto-generate one. We usually want to strip/omit this in block patterns, because we know it will be opened in editor and therefore created during insertion of the block.

In themes now, if a template has more than one Query Loop blocks and we strip them to both, the pagination will be broken for these blocks. So a better strategy might be to preserve them.

Copy link
Author

Choose a reason for hiding this comment

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

I see, thanks for the feedback, I agree in that case it's a better approach to leave the queryIds in. Updated in 642879b.

Copy link
Member

Choose a reason for hiding this comment

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

@carlomanf @ntsekouras How do you feel about unsetting taxQuery attribute on query block?
A query block with a tax query "taxQuery":{"category":[7]} might give empty results in the new site.

Do you see any issues removing it or setting it to null?

Choose a reason for hiding this comment

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

This makes sense. Similar props would be the parents, author and exclude(even if this one is not exposed in the UI.

@madhusudhand
Copy link
Member

madhusudhand commented Jun 14, 2023

Lets remove taxQuery?

unset( $blocks[ $key ]['attrs']['ref'] );
$has_updated_content = true;
}
if ( 'core/image' === $block['blockName'] || 'core/cover' === $block['blockName'] && isset( $block['attrs']['id'] ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ( 'core/image' === $block['blockName'] || 'core/cover' === $block['blockName'] && isset( $block['attrs']['id'] ) ) {
if ( ( 'core/image' === $block['blockName'] || 'core/cover' === $block['blockName'] ) && isset( $block['attrs']['id'] ) ) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants