Skip to content

Fix LeafletEditor.remove() crash when no edits were made#889

Draft
JeroenDeDauw wants to merge 1 commit intomasterfrom
fix/leaflet-editor-remove-null-safety
Draft

Fix LeafletEditor.remove() crash when no edits were made#889
JeroenDeDauw wants to merge 1 commit intomasterfrom
fix/leaflet-editor-remove-null-safety

Conversation

@JeroenDeDauw
Copy link
Copy Markdown
Member

Summary

  • LeafletEditor.remove() calls self.saveButton.remove() unconditionally, but saveButton is only created after the user makes an edit
  • Calling remove() before any edits crashes with TypeError, preventing cleanup of draw controls and GeoJSON layer
  • Fix: add null guard if (self.saveButton) before calling .remove()

Closes #888

Test plan

  • All 247 PHPUnit tests pass
  • QUnit test added: remove() without edits completes without error
  • QUnit test added: remove() after edits completes without error
  • Verified bug exists on master (no null guard on line 234)
  • CI passes

🤖 Generated with Claude Code

self.saveButton is only created after the user makes a change
(via _showSaveButton). Calling remove() before any edits crashes
with TypeError because self.saveButton is undefined, which also
prevents geoJsonLayer cleanup from running.

Add null guard and QUnit tests that verify actual layer cleanup
(layerCount decreases), which also serves as mutation verification:
without the fix, the TypeError prevents geoJsonLayer.remove() from
executing, so layer count stays the same and the test fails.

Closes #888

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JeroenDeDauw JeroenDeDauw force-pushed the fix/leaflet-editor-remove-null-safety branch from 1f0d688 to 388cf15 Compare April 6, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LeafletEditor.remove() crashes if no edits were made

1 participant