Route editor: stale track on anchor removal + undo removes all points #16

Closed
opened 2026-07-27 14:35:04 +00:00 by jmz · 1 comment
Owner

Found while click-testing the smart-insertion build; all fixed on feat/smart-insertion (commit 5e20f773, deployed). Root causes confirmed by static trace of the render pipeline.

Bugs

  1. Deleting down to a single anchor left a dangling track; deleting all anchors left the route line drawn.
  2. Deleting the end anchor (≥3 anchors) left the penultimate→former-end segment dangling.
  3. removeAnchor's anchorIndex==0 branch gated the map refresh behind $formData.expand.gpx_data (always undefined while drawing a new trail) → no refresh.
  4. Undo of point-adds removed all points: add actions never tagged anchorsBefore/anchorsAfter, so undoRouteEdit rebuilt anchors from the emptied route.
  5. deleteFromRoute computed totals from the pre-delete route (valhallaStore.route.getTotals()) → stale distance/elevation.

Fixes

  • removeAnchor: clear the track when <2 anchors remain (mirrors recalculateRouteFromAnchors's N<2 path); drop the gpx_data gate; rebuild via setRoute when removing the end anchor.
  • Add tagLastRouteUndo(...) and tag append/prepend/mid-insert actions so undo/redo restore the anchor list.
  • New insertAnchorSplit() store fn so a mid-route insert is one undo entry.
  • deleteFromRoute: totals from the reduced snapshot.

Noted latent issue (not fixed): valhallaStore.route = applyChangeset(route, delta) is a Svelte $state no-op — applyChangeset mutates in place and returns the same reference, so any future $effect/$derived reading route directly won't react. Consumers currently go through fresh mapTrail/routeSegments literals so it's latent. Worth a separate fix.

Upstream: these are pre-existing upstream bugs — split into atomic PRs when upstreaming (separate from the smart-insertion feature PR).

Found while click-testing the smart-insertion build; all fixed on `feat/smart-insertion` (commit `5e20f773`, deployed). Root causes confirmed by static trace of the render pipeline. **Bugs** 1. Deleting down to a single anchor left a dangling track; deleting all anchors left the route line drawn. 2. Deleting the **end** anchor (≥3 anchors) left the penultimate→former-end segment dangling. 3. `removeAnchor`'s `anchorIndex==0` branch gated the map refresh behind `$formData.expand.gpx_data` (always undefined while drawing a new trail) → no refresh. 4. Undo of point-adds removed **all** points: add actions never tagged `anchorsBefore/anchorsAfter`, so `undoRouteEdit` rebuilt anchors from the emptied route. 5. `deleteFromRoute` computed totals from the pre-delete route (`valhallaStore.route.getTotals()`) → stale distance/elevation. **Fixes** - `removeAnchor`: clear the track when `<2` anchors remain (mirrors `recalculateRouteFromAnchors`'s `N<2` path); drop the `gpx_data` gate; rebuild via `setRoute` when removing the end anchor. - Add `tagLastRouteUndo(...)` and tag append/prepend/mid-insert actions so undo/redo restore the anchor list. - New `insertAnchorSplit()` store fn so a mid-route insert is **one** undo entry. - `deleteFromRoute`: totals from the reduced snapshot. **Noted latent issue (not fixed):** `valhallaStore.route = applyChangeset(route, delta)` is a Svelte `$state` no-op — `applyChangeset` mutates in place and returns the same reference, so any future `$effect`/`$derived` reading `route` directly won't react. Consumers currently go through fresh `mapTrail`/`routeSegments` literals so it's latent. Worth a separate fix. **Upstream:** these are pre-existing upstream bugs — split into atomic PRs when upstreaming (separate from the smart-insertion feature PR).
Author
Owner

Fixed earlier this session (5e20f773/597185c4): removeAnchor clears the track + rebuilds endpoints, undo no longer removes all points, marker/undo sync, first-anchor undoable. Live. Closing.

Fixed earlier this session (`5e20f773`/`597185c4`): removeAnchor clears the track + rebuilds endpoints, undo no longer removes all points, marker/undo sync, first-anchor undoable. Live. Closing.
jmz closed this issue 2026-07-27 22:31:29 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/wanderer#16
No description provided.