fix: maplibre reactive signal bugs and stale signal re-push #3

Merged
ryan merged 3 commits from worktree-datastar-research into main 2026-02-20 18:31:27 +00:00
Owner

Summary

  • Fix draggable pin coordinates not updating by rendering hidden inputs for marker signal writeback
  • Fix click-to-place marker not appearing until moveend by removing redundant internal event inputs that collided with user-provided action inputs
  • Fix moveend handler dispatching input events on non-viewport signals by adding an early return
  • Fix data-effect dependency tracking for signal-backed markers by reading signals before the map/marker guard
  • Fix stale signal re-push by resetting changed flag after patching regular signals (matching computed signal behavior)

Test plan

  • go build ./... compiles
  • go test ./... passes
  • Drag the blue pin → coordinates update in real-time
  • Click the map → orange marker appears immediately
  • Purple vehicle marker wanders every second
  • Dragging pin is not reset when vehicle updates
  • Viewport zoom/center still display correctly
## Summary - Fix draggable pin coordinates not updating by rendering hidden inputs for marker signal writeback - Fix click-to-place marker not appearing until moveend by removing redundant internal event inputs that collided with user-provided action inputs - Fix moveend handler dispatching input events on non-viewport signals by adding an early return - Fix data-effect dependency tracking for signal-backed markers by reading signals before the map/marker guard - Fix stale signal re-push by resetting `changed` flag after patching regular signals (matching computed signal behavior) ## Test plan - [x] `go build ./...` compiles - [x] `go test ./...` passes - [ ] Drag the blue pin → coordinates update in real-time - [ ] Click the map → orange marker appears immediately - [ ] Purple vehicle marker wanders every second - [ ] Dragging pin is not reset when vehicle updates - [ ] Viewport zoom/center still display correctly
ryan added 3 commits 2026-02-20 18:30:27 +00:00
- Export Signal type (signal → Signal) so subpackages can reference it
- Expose viewport signals as public fields (CenterLng, CenterLat, Zoom,
  Bearing, Pitch) for .Text() display and .Bind() usage
- Add signal-backed marker positions (LngSignal/LatSignal) with
  data-effect reactivity for server push and dragend writeback
- Add event system (MapEvent, OnClick, OnLayerClick, OnMouseMove,
  OnContextMenu) using hidden inputs + action triggers
- Add Source interface replacing type-switch, with RawSource escape hatch
- Add CameraOptions for FlyTo/EaseTo/JumpTo/FitBounds/Stop
- Add Control interface with NavigationControl, ScaleControl,
  GeolocateControl, FullscreenControl
- Expand Options with interaction toggles, MaxBounds, and Extra map
- Add effectspike example to validate data-effect with server-pushed signals
- Update maplibre example to showcase all new features
Three related bugs in the maplibre reactive signal plumbing:

1. Draggable marker coordinates never updated because dragendHandlerJS
   queries for hidden inputs matching LngSignal/LatSignal IDs, but
   Element() never rendered those inputs. Add them after the marker
   data-effect divs.

2. Click-to-place marker didn't appear until moveend because Element()
   rendered a bare hidden input for each event signal, colliding with
   the user's action-bearing input (same data-bind, querySelector finds
   the bare one first). Remove the internal event inputs — the user
   provides their own via MapEvent.Input().

3. The moveend handler dispatched 'input' on ALL data-bind inputs in
   the wrapper, accidentally triggering event inputs. Add an else-return
   so only the 5 viewport signal inputs get dispatched.
fix: signal-backed marker reactivity and stale signal re-push
Some checks failed
CI / Build and Test (push) Failing after 35s
CI / Build and Test (pull_request) Failing after 31s
3c3ce57055
Two issues discovered during testing:

1. data-effect expressions for signal-backed markers short-circuited
   before reading $signalID when the map hadn't loaded yet. Datastar
   never tracked those signals as dependencies, so the effect never
   re-ran. Fix: read signal values unconditionally before the guard.

2. prepareSignalsForPatch never reset changed=false on regular signals
   (only computed ones), causing every SyncSignals() call to re-push
   all signals — including stale server-side values for the draggable
   pin, overwriting the client-side drag position.
ryan merged commit c0f4782f2b into main 2026-02-20 18:31:27 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ryan/via#3