-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Query Loop: Don't overwrite the 'query.inherit' attribute value #69698
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
Query Loop: Don't overwrite the 'query.inherit' attribute value #69698
Conversation
Size Change: +69 B (0%) Total Size: 1.85 MB
ℹ️ View Unchanged
|
] } | ||
> | ||
{ __( | ||
'Cannot inherit the global queries when placed inside the singular content' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This is just placeholder text for initial testing.
4afd85c
to
90be4ab
Compare
Flaky tests detected in 90be4ab. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/14193351177
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @genemma, @cheestudio. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically speaking this does work and the code does look good. However I think that this is quite a UX regression... The fact that every time a user inserts a query loop into content (which from my experience happens to many more users than building templates from scratch) they are now presented with an error screen...
CleanShot.2025-04-01.at.13.29.01.mp4
The inverse for when you actually want the inherit usecase is triggered very seldomly. Because when you create a new template file the first thing you get is the ability to copy an existing template. And that already has the query in it.... I know this is anecdotal but I cannot remember when the last time was where I manually needed to insert a query loop that should inherit the global query....
I would love to be able to just change the default value of inherit from true to false... And then maybe enhance the UX for users that are working on a template so that they get a notice / banner / tip bar that informs them that they are on a template where a global query is available asking them if they want to use that one...
Thanks for the feedback, @fabiankaegy! Are you suggesting that we revert #65067 and add a notice near the "Query type" control? I thought the original problem was people changing this setting and expecting default queries to work. I'm also thinking of updating the Query Loop placeholder logic so that the I personally prefer UX, when everything "just works", but that always gets complicated when block attributes are enforced during the page load. |
@Mamaduka what I am trying to say is that I am very open to which approach gets us there. And I don't know all the intricacies that make it difficult. So again if this is the best we can do with the constraints we have we can totally do this. For me the current behavior after #65067 was merged is really close to the ideal case from a UX perspective. (not saying that the way it accomplishes it code wise makes sense). I think what you are suggesting about the block automatically setting it's attribute based on the context where it gets inserted upon insertion makes sense to me. But I think that would build on the work in #65067 🤔 |
I took the PR for a test and I get the way you implemented it, but I have to agree with @fabiankaegy that this feels more confusing. What I had in mind was something like this:
With the current setup, the last step is not possible, as even setting |
Thank you, @luminuu!
I would like to avoid touching the block defaults in this PR. I think that's a separate discussion.
Great point. I'll adjust the logic accordingly. |
90be4ab
to
45310be
Compare
Changed the place where the warning is displayed. See the updated testing instructions and screenshot. |
As I was finishing up this comment I saw your recent update @Mamaduka, so I'll post this comment now and going to test your latest update!
This is the current default in 6.7, so this wouldn't change. In your PR, when adding the Query Loop to a post and selecting a layout, it's set to to CleanShot.2025-04-04.at.13.00.35.mp4What I've been pointed out to be a colleague is that with your current setup, it's not possible to create a pattern in the site editor, as the same things happen there too, making it impossible to create a pattern in the site editor with a query loop to be able to reuse it in multiple archive templates: CleanShot.2025-04-04.at.13.17.22.mp4Here's a mockup of what I'd like to see, having the Default/Custom toggle back and showing a warning message when selecting "Default" in the block editor: The wording in the message is random and is open for refinement. I have put together a small flowchart, so it may be easier for us to discuss this: |
@Mamaduka Follow-up for your latest commit, that looks great! I was basically too slow with my last comment 😅 One thing I've been thinking about writing my comment above was if for the Query Type option, the Default and Custom options should be swapped, but I'm aware that this would have effect everywhere. But I think that's out of the scope for this PR. |
The default value for
I'm not 100% sure what you mean here, but I'm happy to discuss it separately. |
My bad, I was too confused here with what is the "default". I agree that this change could cause more harm than good, so lets leave it as is.
What I was thinking about was swapping the position of Custom and Default: But looking at it, I'm not sure if this would make any difference because it depends on the context where the query loop is inserted to make sense (blog post vs. template). |
100%. It might cause more confusion if we flip labels based on context. @luminuu, @fabiankaegy, any other blockers here?
I've this one to-do item listed in the description, but I am thinking of working on it in a separate PR. I'm not sure how it will work out and don't want more blocks on this change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the PR and it works as expected, no blockers from my side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No blockers from me :)
Thank you both for fantastic feedback 🙇 I'm going to let this PR sit over the weekend and merge on Monday if there are no objections. |
@Mamaduka Added this to the 6.8.x Editor Tasks board as I'd like to see this change being included in one of the next updates. It needs the requirement of only editing existing files. |
Thanks, @luminuu!
Do you mean that it meets the requirement? |
Uhm yeah, that's a bad typo of mine, sorry! |
I am checking the PRs with the "Backport to WP Minor Release" label applied to clarify which PRs should be backported to the WordPress 6.8.2 release. As I understand it, this PR is just to show a small hint, so it can be included as a candidate for the 6.8.2 release. What do you think? |
Yes, please add this PR to 6.8.2. It would fix an issue on client sites we're having. |
* Query Loop: Don't overwrite the 'query.inherit' attribute value * A misc adjustments * Display warning next to 'Query Type' control Unlinked contributors: genemma, cheestudio. Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org> Co-authored-by: luminuu <luminuu@git.wordpress.org> Co-authored-by: jeflopodev <jeflopodev@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: rinkalpagdar <rinkalpagdar@git.wordpress.org>
…Press#69698) * Query Loop: Don't overwrite the 'query.inherit' attribute value * A misc adjustments * Display warning next to 'Query Type' control Unlinked contributors: genemma, cheestudio. Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org> Co-authored-by: luminuu <luminuu@git.wordpress.org> Co-authored-by: jeflopodev <jeflopodev@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: rinkalpagdar <rinkalpagdar@git.wordpress.org>
* Query Loop: Don't overwrite the 'query.inherit' attribute value * A misc adjustments * Display warning next to 'Query Type' control Unlinked contributors: genemma, cheestudio. Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org> Co-authored-by: luminuu <luminuu@git.wordpress.org> Co-authored-by: jeflopodev <jeflopodev@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: rinkalpagdar <rinkalpagdar@git.wordpress.org>
This PR was cherry-picked into the |
What?
Closes #67252
An alternative solution for #64746 reverts #65067.
PR updates a Query Loop block to display a warning when
inherited
queries aren't "allowed", instead of forcing this attribute value tofalse
.Why?
This allows developers to use inherited queries in templates/pages when working with custom rewrites.
Calling
setAttributes
in life-cycle events should be avoided in 99% of cases unless the block really needs to enforce that attribute value. Introducing more conditions in the setting of the attributes creates more variables and makes these life-cycle events flaky. It doesn't allow changing behavior when the consumer knows what they're doing. Additionally, it can cause excessive re-renders and degrade performance.Todos
getQueryContextFromTemplate
.Testing Instructions
inherit: true
).Testing Instructions for Keyboard
Same.
Screenshots or screencast