Forms: fix form editor showing no block selected while the inserter is open - #51047
Open
enejb wants to merge 2 commits into
Open
Forms: fix form editor showing no block selected while the inserter is open#51047enejb wants to merge 2 commits into
enejb wants to merge 2 commits into
Conversation
Contributor
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Contributor
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
1 file is newly checked for coverage.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #
Proposed changes
jetpack_form) ending up with no block selected, which makes the form's settings unreachable — the Block tab just says "No block selected".Two things combined to cause this, both in
src/form-editor/index.tsx:1.
enforceBlockSelection()skipped its work whenever the inserter was open.That premise doesn't hold:
selectBlock()does not close the inserter, and it does not change where the inserter inserts (blocks still land inside the form). Since the inserter auto-opens on load in the form editor, this guard was disabled exactly when it mattered most — deselecting while the inserter was open left the form deselected and its settings unreachable, which is the state users actually hit.The guard is removed. The multi-selection guard is kept and is now explicit —
getSelectedBlockClientId()is null during a multi-selection, so force-selecting would discard the user's range.2. The caller latched the observed selection before enforcement could act.
A
nullselection arriving during any bail-out was consumed by the latch and never retried — on later ticksnull === state.lastSelectedBlockId, so enforcement never ran again. Enforcement now runs on every tick while the selection is empty, so it retries until it can act.Both decisions are extracted into pure helpers in
utils/selection-utils.ts(shouldRunSelectionEnforcement,shouldSelectFormBlock) with unit tests, matching the existinginserter-utils/block-nesting-logicpattern.The inserter guard was introduced in #47413, together with the auto-open-inserter behaviour.
Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions