Skip to content

Fix editor map opening at the wrong zoom, and zoom 0 being reset, in WordPress 7 #3

Closed

Description

@svandragt

The editor map can open at the wrong zoom in the WordPress 7 iframed editor, and a saved zoom of 0 is changed to 1.

Evidence

  • src/blocks/map/edit.js:163 and :258 use zoom || 1, so a saved zoom of 0 becomes 1.
  • The map container has minHeight: 250px and no fixed height (edit.js:148, :276). In the iframed editor, the container's height when the map is created can differ from its height after layout. Mapbox then raises the zoom so that the world fills the container, and the saved view is lost. The map is resized only when the aspect ratio changes (edit.js:265) and 250 ms after a selection change (edit.js:563), never after its first load. This cause is unconfirmed and needs a check in a WordPress 7 editor.
  • edit.js:13 imports __experimentalNumberControl. A WordPress 7.0 test should confirm that the inspector still renders.

Fix approach

  1. Use zoom ?? 1 in both places.
  2. On the map's first load event, call map.resize(), then map.jumpTo() with the saved centre and zoom.
  3. Give the map container height: 100%, so that it follows its parent.
  4. Check that dragging the map background doesn't jump in the WordPress 7.0 iframe. If it does, drive panning from pointer events on the iframe document.

Done when

  • A block with a saved view opens on that view in WordPress 7.0 and 7.1, including at zoom 0.
  • The block inspector opens without console errors.
  • Dragging the map background moves the map smoothly.

Thanks to @kadamwhite for asking us to check map-block after the WordPress 7 map fixes.

Activity

  1. self-assigned this
    on Oct 19, 2026
  2. svandragt commented on Oct 19, 2026

    @svandragt
    ContributorAuthor

    Dragging the map background in the editor does not follow the pointer in WordPress 7.1.3. The zoom fix for this issue does not change this, so it needs its own change.

    Evidence (wp-env, WordPress 7.1.3, Playwright, map at zoom 0, block selected, 200px horizontal drag)

    Editor layout Canvas iframe offset in the page Pin movement
    Inserter closed left 0, top 96 x +200, y +96
    Inserter open left 350, top 96 x −37, y +96
    • The vertical jump equals the iframe's top offset, and the pointer did not move vertically.
    • With the iframe offset to the left, the horizontal pan no longer follows the pointer either.

    Likely cause

    mapbox-gl is bundled into the editor script, which runs in the parent window, while the map renders inside the canvas iframe. The drag handler appears to compare pointer positions from the two documents, which differ by the iframe's offset. This matches the vertical numbers exactly. The −37px horizontal value is not explained yet.

    Fix approach

    Drive background panning from pointer events on the iframe document (map.getCanvasContainer().ownerDocument), as the marker drag in src/blocks/map/edit.js already does, and disable Mapbox's own dragPan in the editor.

    Done when

    A 200px drag in the editor moves the map 200px in the drag direction and 0px across it, with the inserter both open and closed.

  3. added a commit that references this issue on Oct 19, 2026
    b284796
  4. svandragt commented on Oct 19, 2026

    @svandragt
    ContributorAuthor

    Update: #4 (Keep the saved view and fix background dragging in the WordPress 7 editor map) now fixes the background drag jump as well, so it covers this whole issue. The editor pans the map from pointer events in the iframe's document instead of using Mapbox's drag handling. We're checking the drag in the browser on WordPress 7.1.3, then running the full set of checks on WordPress 7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions