mapbox / mapbox/mapbox-maps-android
[compose] Usage of rememberRasterSourceState does not reset remembered value when key changes
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 578
- Forks
- 161
- PR merge metrics
- No merged PRs in 30d
Description
## Environment
- Android OS version: Android 16, Compose (Multiplatform) 1.10.0 alpha 01
- Devices affected: (Tested on) Samsung Galaxy S25
- Maps SDK Version: 11.14.6
## Observed behavior and steps to reproduce
In the following code, when `mapLayer` changes, the content of `myCustomSourceState` is not reset, even if re-composition is triggered due to a change of instance of the `mapLayer`. So the tiles URL cannot be changed even if map layer is different.
@Composable
fun rasterSourceExample(
mapLayer: MapLayer,
) {
val myCustomSourceState = rememberRasterSourceState(
key = mapLayer.toString(), // if this changes, the myCustomSourceState does not reset
sourceId = MAPBOX_SOURCE_CUSTOM_ID,
) {
tileSize = LongValue(MAPBOX_SOURCE_TILE_SIZE)
tiles = StringListValue(mapLayer.rasterLayerSourceUrl)
}
}
## Expected behavior
`myCustomSourceState` should be updated with the new `tiles` URL from the new value of `mapLayer`
## Notes / preliminary analysis
One can say the reason is that the value passed as key argument is the same, but is not, since `mapLayer` is a data class. After doing some manual implementations, seems like the Mapbox implementation of `rememberRasterSourceState` makes use of a deprecated overload. Instead of using `key` argument, `inputs` argument should be used to check for the remembered value invalidation. The following code works and could be the fix for the Mapbox implementation
## Additional links and references
The problem:
The solution
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 at the rememberRasterSourceState implementation and compare its deprecated overload usage with the key/inputs behavior described in the report. Reproduce the case with a changing mapLayer, then verify that myCustomSourceState uses the new rasterLayerSourceUrl after recomposition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 63/100