-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}, [ clientId, ref ] ); | |
}, [ clientId, ref, innerBlocks ] ); |
Do we now need to add innerBlocks
to the deps?
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, as the comment above states :-)
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.
Oops, looks like it was added anyway in 793ff2a
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 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 new
buttons within the Nav block UI to create a new Menu you can end up causing edits to the wrongwp_navigation
entity.How does this happen? Scenario:
Create new
drop theSelect menu
dropdown on the blockwp_navigation
entity for editing.replaceInnerBlocks
but 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"Save
in 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
ref
to thewp_navigation
Post 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.js
files for terms that need renaming or removal).