ToolsPanelItem: Add panelId check before calling toggle methods #35375
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
While testing a couple of different blockGap PRs (#34630 and #34546), I noticed that if I select a block and update its block spacing value, then select the same type of block and then back to the original block, the value I set would be cleared out. After adding some
console.log()
s, it appears that theonSelect
andonDeselect
functions in the Tools Panel Item were being called (effectively as though we'd toggled the blockGap control).This PR adds a check before calling the
onSelect
andonDeselect
functions to ensure that the current panel id hasn't changed before calling the functions. This appears to fix the issue of the blockGap value unexpectedly being cleared.How has this been tested?
Manually in the editor.
Before testing, switch to an FSE-capable theme (e.g. TT1-Blocks) and enable the
blockGap
feature by updating thesettings.spacing.blockGap
setting in thetheme.json
file. For example, here's how that section of mytheme.json
file looks:To replicate, we need to click directly between two blocks with the same dimensions panel, so one way to do this is to add two columns blocks to your post content, and set them to use a background color so that you can click between them. To make it easier for testing, here's a gist of post content with two columns blocks. Copy and paste it in the code editor view for testing.
Before applying this PR:
It may take clicking back and forth a couple of times before you see the issue.
With this PR applied, the values should not be unexpectedly removed. Also test to make sure that toggling tools panel items in the ToolsPanel menu still works as expected.
Screenshots
Note that in the Before screengrab the block spacing value is cleared unexpectedly when clicking between Columns blocks. In the After screengrab the value is not cleared.
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).