mapbox / mapbox/mapbox-maps-ios
`MapContent` ignores `@Observable` updates – not aligned with SwiftUI expectations
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 601
- Forks
- 196
- PR merge metrics
- No merged PRs in 30d
Description
## Environment
- Xcode version: 16.4
- iOS version: 18.6
- Devices affected: any
- Maps SDK Version: 11.14.0
## Observed behavior and steps to reproduce
MapContent does not react to `@Observable` state updates. Here's the minimal test case:
```swift
@Observable
class TestViewModel {
var pluckBearing = false
}
struct MapTestContent: MapContent {
let viewModel: TestViewModel
var body: some MapContent {
if viewModel.pluckBearing {
Puck2D(bearing: .heading)
} else {
Puck2D(bearing: .none)
}
}
}
struct MapTest: View {
let viewModel = TestViewModel()
var body: some View {
VStack {
Map {
MapTestContent(viewModel: viewModel)
}
Button("Toggle Puck Bearing") {
viewModel.pluckBearing.toggle()
}
}
}
}
```
Tapping the button has currently no effect.
## Expected behavior
Tapping the button should update pluck style. So, I'd expect `MapContent` get re-evaluated when `@Observable` state is updated.
## Notes / preliminary analysis
The ability to update only the leaf nodes of the map declaration tree could lead to significant performance improvements.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal MapTestContent reproduction in the issue and inspect the MapContent evaluation and observation entry points. Confirm the behavior on the stated Xcode 16.4, iOS 18.6, and Maps SDK 11.14.0 environment; done means toggling pluckBearing updates the Puck2D style without rebuilding unrelated map content.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100