Repository navigation
Description
Context: an open bug related to multi-entity saving
There is a hard-to-debug issue concerning the multi-entity save flow (#78989) which is currently being examined by several contributors. In a gist, the Site Editor is prone to showing untouched entities as dirty, and there is an ongoing search to determine whether something in the saving/dirtying machinery has changed, and/or whether certain block types are to blame.
Among the findings is the fact that the Query block may automatically set two of its own attributes, query and queryId upon mounting:
gutenberg/packages/block-library/src/query/edit/query-content.js
Lines 96 to 110 in 4429bf0
| useEffect( () => { | |
| const newQuery = {}; | |
| // When we inherit from global query always need to set the `perPage` | |
| // based on the reading settings. | |
| if ( inherit && query.perPage !== postsPerPage ) { | |
| newQuery.perPage = postsPerPage; | |
| } else if ( ! query.perPage && postsPerPage ) { | |
| newQuery.perPage = postsPerPage; | |
| } | |
| if ( !! Object.keys( newQuery ).length ) { | |
| __unstableMarkNextChangeAsNotPersistent(); | |
| updateQuery( newQuery ); | |
| } | |
| }, [ |
gutenberg/packages/block-library/src/query/edit/query-content.js
Lines 119 to 123 in 4429bf0
| useEffect( () => { | |
| if ( ! Number.isFinite( queryId ) ) { | |
| __unstableMarkNextChangeAsNotPersistent(); | |
| setAttributes( { queryId: instanceId } ); | |
| } |
Solutions
At the very least, we should mitigate these self-changing effects. For example, #79000 mitigated the Navigation block's self-changing behaviour by only triggering the effect if the block or its descendants are selected.
Ideally, though, we'd get rid of that behaviour altogether, but that requires ad-hoc solutions. For example, #79048 introduced a new attribute passed as context from Navigation Submenu to its Page List descendants.
/cc @ntsekouras
Activity
ntsekouras commentedon Jun 18, 2026
This shouldn't cause any dirtying state because both instances have
__unstableMarkNextChangeAsNotPersistent.That said, I'm not sure how we can avoid this unless we have an API for blocks to indicate something like
uniqueIdthat would have to handle such assignment in a lower level. The reason for setting this attribute like that is because there can be multiple Query Loop blocks in a page and the pagination for each block is tied to a unique id in order to work properly.It has been discussed in some places (quite a lot), among other similar cases for block attributes that shouldn't persist when duplicating blocks etc.. You've also participated in the main issue's discussions 😄 .
mcsf commentedon Jun 19, 2026
That's the thing: this marking is no longer reliable, and we don't know why yet.
See for yourself:
Details
mcsf commentedon Jun 19, 2026
Let's tackle the offending attributes one by one, starting with what looks like the easiest. It's possible I'm oversimplifying things, so feel free to call me out.
query.perPageFrom what I see, there seem to be different things we want to ensure:
posts_per_pagevalue fromgetEntityRecordEditstrumpsgetEntityRecord.posts_per_pageas a default but letting users override it... unless the query is inherited, in which case their preference is overridden.However, the desire for accuracy in the end means that now
query.perPageis frozen inside the block's attributes. So, if the admin changes the site's PPP setting globally, that behaviour won't apply to templates with query loops unless the admin opens them in the editor again and saves them. Correct?Wouldn't the following alternative work just as well, if not better?
queryattribute stays as is, withquery.perPagedefaulting tonulluseEffectcall is removedperPagecontrol ifinheritis truequery.perPagecan theoretically benullor a number regardless ofinherit(because we don't force the value usinguseEffect)query.perPageis greater than zero andinheritis false, then usequery.perPagequery.perPageis greater than zero andinheritis true, then usegetEntityRecordEdits || getEntityRecordquery.perPageis null, then usegetEntityRecordEdits || getEntityRecordget_option( 'posts_per_page' )ntsekouras commentedon Jun 19, 2026
I'm not really sure that the issue comes from the selector..
setAttributesis called (with breakpoints) and in code editor that the attribute is updated.paragraphblock and makes the post dirty.paragraphblock but chose to update thedropCapsprop and does not make the post dirtyIt seems something else is going on, right? Maybe something with specific attribute handling? If it was the selector, it should dirty the post in all cases, no?
ntsekouras commentedon Jun 19, 2026
Should we focus there though? Can you reproduce the dirty post with Query Loop block? I can't personally and that code is like that for many years.
As I noted above, I think the issue lies elsewhere and while we could try to find a different approach for
perPage, I'm not sure how we would handle queryId. If you find a good solution to remove this, I'm all for it of course.mcsf commentedon Jun 19, 2026
Sorry to bombard you with this :)
If I understood your steps correctly, that is to be expected: since you added the block manually, the attribute is automatically set once after that, then the post is saved, and upon reloading there is nothing else to do. The problem is when there are themes/templates involved: then it becomes likely that, upon loading a "page" in the site editor (or in the post editor with "Show template" on), the blocks are instantiated based on the template's blueprint, but then some of the attributes are automatically corrected.
In my case I didn't spot it with
query.perPage, but yesterday thequeryIdmutations were one of the attribute changes in my dev env that were dirtying the editor.That said, Jarda made a breakthrough in the real problem (#79350), so hopefully we can deescalate this whole matter across our block library and keep relying on
__unstableMarkNextChangeAsNotPersistentwhen need be. However, I do think it's a healthy exercise to think hard (and even revisit, sometimes years later) about the way we use self-setting attributes in our blocks. :)mcsf commentedon Jun 19, 2026
I've adjusted the labels on the expectation that Jarda's PR will fix the real issue soon.
Question, while we're here examining these attributes: won't
queryIdbe erroneously duplicated if a user duplicates a Query block? (edit: in my testing, yes.)Mamaduka commentedon Jun 19, 2026
@ellatrix, was also working to improve
per_pagesetter side-effect - #66532.Bingo 😄 Here's the issue - #55823.
ntsekouras commentedon Jun 19, 2026
Ah.. ok. I got the case where this can happen (probably template including Query Loop without a
queryId).Of course. My question about focusing on that was because I was quite confident it was something else than
__unstableMarkNextChangeAsNotPersistentselector.jsnajdr commentedon Jun 23, 2026
Now when #79350 is merged, I think this issue is resolved. The
QueryContentcomponent correctly marks thequeryIdandquery.perPageupdates as non-persistent.The only remaining issue I see here is copying
queryIdon duplication, but that's an unrelated bug?mcsf commentedon Jun 23, 2026
Correct. Per George's comment, there's one bug and one issue for improvement. :)