I'm having a crash caused by navigating from a scr...
# compose
z
I'm having a crash caused by navigating from a screen containing a lazy column to another one, then navigating back. The stack trace doesn't point to any of my code so I'm not sure what's going on
b
Which version of Compose are you running?
z
I'm using 1.2.0-beta01
b
It's hard to say without seeing any code but I would guess thats a bug that needs to be filed
z
Maybe this will help
a
it is not a know bug. if you can provide a reproducible sample we can try to fix that
z
I might have narrowed the issue down, the way I'm doing search is by setting the paging source to a new instance, which I doubt is the best way of doing it. Testing with it set already to an instance of a paging source seems to fix the bug. I'm not really sure how else to create a source for paging data when the search button is pressed though
It looks like this in my viewmodel
Copy code
var results by mutableStateOf<Flow<PagingData<DomainSearch.Result>>>(emptyFlow())
    private set
Copy code
fun getResults() {
    results = Pager(PagingConfig(10)) {
        object : PagingSource<String, DomainSearch.Result>() {
            override suspend fun load(params: LoadParams<String>): LoadResult<String, DomainSearch.Result> {
                return try {
                    val searchResults = repository.getSearchResults(search, params.key)

                    LoadResult.Page(
                        data = searchResults.items,
                        prevKey = null,
                        nextKey = searchResults.continuation
                    )
                } catch (e: Exception) {
                    e.printStackTrace()
                    LoadResult.Error(e)
                }
            }

            override fun getRefreshKey(state: PagingState<String, DomainSearch.Result>): String? =
                null
        }
    }.flow.cachedIn(viewModelScope)
}