title: Android Paging 3 leading to duplicate rows
body: <p>I was trying out the Paging 3.0.1 version. The API calls are happening right when I printed the log. But the data shown is duplicate. Could someone tell me where I went wrong?</p>
  <p>Page data source class</p>
  <pre><code>class MyPageDataSource(private val api: RetrofitInstance) :
  PagingSource&lt;Int, APIDataResponse&gt;() {
  
  override suspend fun load(params: LoadParams&lt;Int&gt;): LoadResult&lt;Int, APIDataResponse&gt; {
      return try {
          val nextPageNumber = params.key ?: FIRST_PAGE_NUMBER
          val response = api.getData(nextPageNumber, PAGE_SIZE)
          LoadResult.Page(
              data = response.APIS!!,
              prevKey = if (nextPageNumber &gt; FIRST_PAGE_NUMBER) nextPageNumber - 1 else null,
              nextKey = if (nextPageNumber * PAGE_SIZE &lt; response.total!!) nextPageNumber + 1 else null
          )
      } catch (e: Exception) {
          LoadResult.Error(e)
      }
  }
  
  override fun getRefreshKey(state: PagingState&lt;Int, APIDataResponse&gt;): Int? {
      return state.anchorPosition
  }
  
  companion object {
      const val FIRST_PAGE_NUMBER = 1
      const val PAGE_SIZE = 20
  }
  }
  </code></pre>
  <p>Adapter:</p>
  <pre><code>class MyListingAdapter() : PagingDataAdapter&lt;APIDataResponse, MyListingAdapter.MyViewHolder&gt;(MyComparator) {
  
  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
      return MyViewHolder(
          FragmentItemBinding.inflate(
              LayoutInflater.from(parent.context),
              parent,
              false
          )
      )
  }
  
  override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
      holder.bind(item = getItem(position))
  }
  
  inner class MyViewHolder(binding: FragmentItemBinding) :
      RecyclerView.ViewHolder(binding.root) {
      private val title: TextView = binding.title
  
      fun bind(item: APIDataResponse?) {
          if(item != null) {
              title.text = item.title
          }
      }
  }
  
  object MyComparator : DiffUtil.ItemCallback&lt;APIDataResponse&gt;() {
      override fun areItemsTheSame(
          oldItem: APIDataResponse,
          newItem: APIDataResponse
      ): Boolean {
          return oldItem.id == newItem.id
      }
  
      override fun areContentsTheSame(
          oldItem: APIDataResponse,
          newItem: APIDataResponse
      ): Boolean {
          return oldItem == newItem
      }
  }
  }
  </code></pre>
  <p>View Model:</p>
  <pre><code>class PagingViewModel : ViewModel() {
  
  fun getData() : Flow&lt;PagingData&lt;APIDataResponse&gt;&gt; {
      return Pager(
          PagingConfig(
              pageSize = 20,
              enablePlaceholders = false,
              maxSize = 40,
              initialLoadSize = 20,
              prefetchDistance = 10
          )
      ) {
          MyPageDataSource(RetrofitInstance())
      }.flow.cachedIn(viewModelScope)
  }
  }
  </code></pre>
  <p>Recycler view setting up in the fragment:</p>
  <pre><code>val myAdapter = MyListingAdapter(myActivity)
  
      //Setup the recyclerview
      binding.myList.apply {
          layoutManager = when {
              columnCount &lt;= 1 -&gt; LinearLayoutManager(context)
              else -&gt; GridLayoutManager(context, columnCount)
          }
          myAdapter.stateRestorationPolicy = RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY
          val decoration =
              DividerItemDecoration(myActivity, DividerItemDecoration.VERTICAL)
          addItemDecoration(decoration)
          setHasFixedSize(true)
          adapter = myAdapter
      }
      lifecycleScope.launch {
          viewModel.getData().distinctUntilChanged().collectLatest { pagedData -&gt;
              myAdapter.submitData(pagedData)
          }
      }
  </code></pre>