Repository navigation
Conversation
A saved zoom of 0 was replaced by 1, and in the iframed WordPress 7 editor the map could open at a different zoom because it was never resized after its first load. Use `?? 1` for the zoom fallback, resize and jump to the saved view on the first load, and let the map container follow its parent's height. Add a test:unit script and a Jest test for MapPreview with mapbox-gl mocked. Refs #3 Co-Authored-By: Claude <noreply@anthropic.com>
In the WordPress 7 editor the canvas is an iframe, while the bundled mapbox-gl runs in the parent window. Mapbox's drag pan then mixed pointer coordinates from both documents, so dragging the map background jumped by the iframe's offset. Turn off dragPan in the editor and pan by the distance between pointer events read from the canvas's own document. Fixes #3 Co-Authored-By: Claude <noreply@anthropic.com>
svandragt
marked this pull request as draft
October 19, 2026 17:13
Co-Authored-By: Claude <noreply@anthropic.com>
svandragt
marked this pull request as ready for review
October 19, 2026 17:39
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.
In the WordPress 7 block editor, which shows content in an iframe, the map block had three faults. A saved zoom of 0 changed to 1. The map could open at a different view from the saved one. Dragging the map background made the map jump by the iframe's offset: 96px down on every drag, and the wrong way horizontally when the inserter was open.
What changed
The frontend map is unchanged.
Separately, the
PLUGIN_VERSIONconstant inplugin.phpnow says 0.1.1, to match the plugin header. Nothing reads the constant, so this has no effect at runtime.Test plan
dragPanto be off and found it on.main. With the inserter open, it moved −37px instead of +200px.Lint and build
npm run lint:jsandnpm run buildpass.npm run lint:pkg-jsonreports five errors that also fail onmain.Not checked
main.Why this shape
The drag fix pans by the distance between two pointer events read from the iframe's document, so the iframe's offset cancels out. Correcting Mapbox's absolute coordinates by the offset would break whenever the editor layout moves the iframe. The marker drag in the same file already listens to the iframe's document.
Fixes #3 (Fix editor map opening at the wrong zoom, and zoom 0 being reset, in WordPress 7).
Footnotes
zoom || 1becamezoom ?? 1insrc/blocks/map/edit.js, in theMapoptions and insetZoom. ↩The
loadhandler callsmap.resize()thenmap.jumpTo( viewRef.current ).viewRefholds the latest centre and zoom, so a change made before the map finishes loading is kept. ↩The map container gets
height: 100%. ↩The editor
MapgetsdragPan: false. Apointerdownlistener onmap.getCanvasContainer()bindspointermoveandpointerupon itsownerDocumentand callsmap.panBy( [ dx, dy ], { animate: false } ). ↩npm run test:unitrunswp-scripts test-unit-js. The tests are insrc/blocks/map/edit.test.jsand mockmapbox-gland the externalised@wordpress/*packages. ↩