Skip to content

Forms: fix form editor showing no block selected while the inserter is open - #51047

Open
enejb wants to merge 2 commits into
trunkfrom
fix/forms-editor-no-block-selected
Open

Forms: fix form editor showing no block selected while the inserter is open#51047
enejb wants to merge 2 commits into
trunkfrom
fix/forms-editor-no-block-selected

Conversation

@enejb

@enejb enejb commented Aug 4, 2026

Copy link
Copy Markdown
Member

Fixes #

Proposed changes

  • Fix the standalone form editor (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.

// Don't force-select when the inserter is open — selecting a block
// can close the inserter or change its context.
if ( isInserterOpened() ) {
    return;
}

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.

if ( currentSelectedBlockId !== state.lastSelectedBlockId ) {
    state.lastSelectedBlockId = currentSelectedBlockId;   // latched to null…
    enforceBlockSelection();                              // …which then bailed out
}

A null selection arriving during any bail-out was consumed by the latch and never retried — on later ticks null === 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 existing inserter-utils / block-nesting-logic pattern.

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

  • Open Jetpack → Forms and edit (or create) a form. The block inserter opens automatically on load — leave it open.
  • Click the empty canvas whitespace to the left or right of the form block.
  • Before this change: nothing is selected, the Block tab reads "No block selected", and there is no way back to the form's settings short of the List View. It stays that way even after closing the inserter.
  • After this change: the form block stays selected, and its settings remain reachable.
  • Confirm the inserter is not closed by this — it should stay open the whole time.
  • Confirm inserting a field from the open inserter still lands inside the form, not as a sibling.
  • Select two or more field blocks (click one, shift-click another) and confirm the multi-selection is preserved rather than being collapsed back to the form block.

@enejb enejb added Bug When a feature is broken and / or not performing as intended [Status] Needs Review This PR is ready for review. labels Aug 4, 2026
@enejb enejb self-assigned this Aug 4, 2026
@enejb enejb added Bug When a feature is broken and / or not performing as intended [Status] Needs Review This PR is ready for review. labels Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/forms-editor-no-block-selected branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/forms-editor-no-block-selected

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control

jp-launch-control Bot commented Aug 5, 2026

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/form-editor/index.tsx 0/238 (0.00%) 0.00% -6 💚

1 file is newly checked for coverage.

File Coverage
projects/packages/forms/src/form-editor/utils/selection-utils.ts 6/6 (100.00%) 💚

Full summary · PHP report · JS report

@enejb enejb changed the title Forms: fix form editor getting stuck with no block selected Forms: fix form editor showing no block selected while the inserter is open Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug When a feature is broken and / or not performing as intended [Feature] Contact Form [Package] Forms [Status] Needs Review This PR is ready for review. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant