fix: discard unsaved HTML block changes on cancel#78580
Conversation
|
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: @at-ric. 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. |
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the PR.
It looks good at first glance, but can we remove the isOpen prop from the HTMLEditModal component?
5daf2a2 to
499e35f
Compare
|
Done! I've removed the redundant |
What?
Closes #78548
This PR conditionally renders the Custom HTML block's edit modal (
HTMLEditModal) so that it is unmounted when closed.Why?
Previously, the modal component remained mounted in the React tree even when closed, simply returning
nullinternally. This caused React to retain the local state variables (editedHtml,editedCss,editedJs) representing the user's edits.As a result, if a user modified the code in the modal, clicked "Cancel" to discard their changes, and reopened the modal, the modal still displayed their discarded changes.
How?
Updated
packages/block-library/src/html/edit.jsto conditionally render<HTMLEditModal>using the state flagisModalOpen:{ isModalOpen && <HTMLEditModal ... /> }This is done for both occurrences (the placeholder block view and the main edit block view).
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
Before
Custom-HTML-Block-Before.mov
After
Custom-HTML-Block-After.mov
Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini 3.5 Flash
Used for: Suggesting and implementing the fix. Final implementation was reviewed and edited by me.