sebaslogen / resaca

Compose Multiplatform library to scope ViewModels to a Composable, surviving configuration changes and navigation
MIT License
392 stars 9 forks source link

hiltViewModelScoped returns new viewModel with old bundle argument on key change #22

Closed LightningGem closed 1 year ago

LightningGem commented 1 year ago

i have following VM:

val viewModel: TorrentDetailsViewModel = hiltViewModelScoped(
        key = hash, defaultArguments = bundleOf(TorrentDetailsViewModel.HASH_KEY to hash)
    )

After composable is recomposed with new hash, new viewModel is returned, but bundle hash value is old. pic1 pic2

sebaslogen commented 1 year ago

Hi there, thanks for reporting it and adding enough details. I'll work on a fix next week

sebaslogen commented 1 year ago

Bug fixed in release https://github.com/sebaslogen/resaca/releases/tag/2.4.5

For reference: The bug was the key used in the ViewModelProvider, it was missing the key provided in hiltViewModelScoped. Since the ViewModel was correctly being removed and recreated by the library, the side effect was that the old Bundle from SavedStateHandle was restored. The fix was to use the provided key in the ViewModelProvider and add an automated test to cover this case.

Thanks again for reporting the issue 😃