Fix Nav block editing wrong entity on creation of new Menu#36880
Fix Nav block editing wrong entity on creation of new Menu#36880
Conversation
|
Size Change: -21 B (0%) Total Size: 1.1 MB
ℹ️ View Unchanged
|
259db3b to
93246ac
Compare
|
Failing e2e test appears to be around dirty entities which worries me. I'll run locally to check... |
I think we've introduced a bug here with dirty entity states as the test is failing because the |
|
I added an additional check for |
| } | ||
| // innerBlocks are intentionally not listed as deps. This function is only concerned | ||
| // with the snapshot from the time when ref became undefined. | ||
| }, [ clientId, ref ] ); |
There was a problem hiding this comment.
| }, [ clientId, ref ] ); | |
| }, [ clientId, ref, innerBlocks ] ); |
Do we now need to add innerBlocks to the deps?
There was a problem hiding this comment.
No, as the comment above states :-)
There was a problem hiding this comment.
Oops, looks like it was added anyway in 793ff2a
There was a problem hiding this comment.
I don't even know what happened here 😕
|
@adamziel this now looks good. e2e passes. Needs a 👍 pending one final query in #36880 (comment) |
* Move reset of innerblocks to effect * Add e2e test that checks for updating the wrong entity record * Formatting * Unfocus focused test * Only replace innerBlocks with an empty list, if it's not already empty * Update useEffect dependencies Co-authored-by: Adam Zieliński <adam@adamziel.com> Co-authored-by: Daniel Richards <daniel.richards@automattic.com>
Description
In #36862 we learnt that if you use the
Create newbuttons within the Nav block UI to create a new Menu you can end up causing edits to the wrongwp_navigationentity.How does this happen? Scenario:
Create newdrop theSelect menudropdown on the blockwp_navigationentity for editing.replaceInnerBlocksbut it does this before the entity is set to the freshly created one. Instead it ends up calling replaceBlocks and the existing entity picks up the changes and gets marked as "dirty"Savein the Site Editor only to find they now have to save both the new and the original Nav Post entitiesThis PR fixes that by moving the reseting of the inner blocks to an effect which runs if the
refto thewp_navigationPost is reset. This way we ensure we have completely "unloaded" the current entity before we reset the blocks in the UI.Closes #36862
How has this been tested?
Select menu -> Create new.Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.jsfiles for terms that need renaming or removal).