Status Update
Comments
du...@google.com <du...@google.com>
ra...@gmail.com <ra...@gmail.com> #2
Hello, can you please attach a sample that reproduces your error?
du...@google.com <du...@google.com> #3
I’ve attached two screen recordings demonstrating the mediator's behavior during the first and second launches after installation. Additionally,
jb...@google.com <jb...@google.com>
th...@palringo.com <th...@palringo.com> #4
Based on first_launch_after_installation.mp4
, your paging state is indeed showing null
for nextKey, so it makes sense that Paging concluded there are no more items to load.
So I think the question is why the PagingState
contains only an empty page and null
values. My guess is either
- RemoteMediator REFRESH actually returned empty data - what is the returned
allNewsItems
value on initial REFRESH? - RemoteMediator REFRESH successfully loaded data and inserted it into database, but Paging hasn't processed that yet by the time Append is triggered, so PagingState is empty.
The second case doesn't seem likely though.
If you attach an executable app, I can look into this further.
Otherwise, you may gain more insight through Paging logs with adb shell setprop log.tag.Paging VERBOSE
. You can also try implementing RemoteKeys
in this
du...@google.com <du...@google.com> #5
Hey! I ran into this same issue. It is in fact the second case you mentioned and is documented
I've published a repo
th...@palringo.com <th...@palringo.com> #6
I am gonna try and report back, but I don't see the relevance at all. For reasons unrelated to this issue, I am not using Lazy components but instead I am loading a RecyclerView through an AndroidView inside a composable. So I believe this is a paging library bug and not a Compose one
du...@google.com <du...@google.com> #7
I am gonna try and report back, but I don't see the relevance at all. For reasons unrelated to this issue, I am not using Lazy components but instead I am loading a RecyclerView through an AndroidView inside a composable. So I believe this is a paging library bug and not a Compose one
It will not fix it for you if you are using RecyclerView. You'll need to provide a repro for your jumping issue and file it separately, so we can address your concerns there.
cl...@google.com <cl...@google.com> #8
The jump appears to be present even with 1.3.0-alpha03. Upon brief inspection it seems the get[index]
sent to Paging is out of sync with the data shown on the UI after subsequent REFRESH (i.e. when remote mediator appends items into Room db).
Going to have take a deeper look into this.
cl...@google.com <cl...@google.com> #9
Hi Andrey, it seems the problem is compose's index mismatching with paging's index, where paging's index is more reflective of where the user is actually scrolled to.
For example
1. screen scrolled to index[45]
2. refresh with key[28]
3. present on UI item[28-57]
4. compose sent get[18] ... get [26] <----- this seems a little suspicious
RE: #6 Can you file please a separate bug under Paging
with your repro on RecyclerView? Thanks.
an...@google.com <an...@google.com> #10
So I am logging when the firstVisibleItemIndex changes - the index we use as a scroll position
When we compose the item, which is essentially LazyPagingItems.get()
And when the item count in the LazyPagingItems changes
```
here we scroll so the firstVisibleItemIndex is increasing
2022-09-15 06:39:29.179 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest new firstVisibleItemIndex=37
2022-09-15 06:39:29.249 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest new firstVisibleItemIndex=38
2022-09-15 06:39:29.296 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=42 with key=221809776 and text=47_Kr328/ClashForAndroid
2022-09-15 06:39:29.315 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=43 with key=45261969 and text=48_nickbutcher/plaid
2022-09-15 06:39:29.348 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest new firstVisibleItemIndex=39
not sure why, but items count changes, however id doesn't seem to change anything and we scroll correctly
2022-09-15 06:39:29.377 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest paging item count=55
2022-09-15 06:39:29.431 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=44 with key=134505361 and text=49_android/sunflower
2022-09-15 06:39:29.449 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest new firstVisibleItemIndex=40
2022-09-15 06:39:29.505 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=45 with key=24186761 and text=50_Kotlin/anko
2022-09-15 06:39:29.571 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest new firstVisibleItemIndex=41
2022-09-15 06:39:29.707 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=46 with key=44804216 and text=51_termux/termux-app
2022-09-15 06:39:29.782 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest new firstVisibleItemIndex=42
2022-09-15 06:39:30.072 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=47 with key=23112526 and text=52_android10/Android-CleanArchitecture
here we now have less items, seems like the items in the start of the list were removed. and we automatically detected that the previous first item "47_Kr328/ClashForAndroid" was moved from position 42 to 18 so we adjust firstVisibleItemIndex accordingly
2022-09-15 06:39:31.588 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest paging item count=31
2022-09-15 06:39:31.591 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=23 with key=23112526 and text=52_android10/Android-CleanArchitecture
2022-09-15 06:39:31.592 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=18 with key=221809776 and text=47_Kr328/ClashForAndroid
2022-09-15 06:39:31.594 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=20 with key=134505361 and text=49_android/sunflower
2022-09-15 06:39:31.595 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=19 with key=45261969 and text=48_nickbutcher/plaid
2022-09-15 06:39:31.596 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=21 with key=24186761 and text=50_Kotlin/anko
2022-09-15 06:39:31.597 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=22 with key=44804216 and text=51_termux/termux-app
2022-09-15 06:39:31.601 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest new firstVisibleItemIndex=18
but then the items count changes two times again and seems like after that we can't find this item "47_Kr328/ClashForAndroid" anymore in the new list so we can't adjust the index so we stay on the same index, but now we have "23_greenrobot/EventBus" at index 18
2022-09-15 06:39:31.605 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest paging item count=40
2022-09-15 06:39:32.238 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest paging item count=32
2022-09-15 06:39:32.247 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=18 with key=5070389 and text=23_greenrobot/EventBus
2022-09-15 06:39:32.252 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=19 with key=93152223 and text=24_scwang90/SmartRefreshLayout
2022-09-15 06:39:32.258 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=20 with key=2990192 and text=25_signalapp/Signal-Android
2022-09-15 06:39:32.262 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=21 with key=90792131 and text=26_android/architecture-components-samples
2022-09-15 06:39:32.268 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest composed item at index=22 with key=18347476 and text=27_google/iosched
```
how the paging logic works in this condition? when and how it adds/removes items?
cl...@google.com <cl...@google.com> #11
Hi Andrey thanks for looking into this.
So the app loads data from both a local Room database and RemoteMediator (online database). RoomDb starts off empty which triggers RemoteMediator to load data and insert into Room. Essentially everytime Room runs out of data, RemoteMediator will load more to insert into Room, and every insertion will cause Paging to REFRESH the page. Whats happening is likely:
1. initial load 30 items
2. `2022-09-15 06:39:29.377 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest paging item count=55` -- scrolling down causes paging to load more, hence itemCount = 55
3. The insertion into room invalidates Paging, which triggers a REFRESH to reload around where user was last scrolled to
4. While paging was loading, user keeps scrolling
6. `2022-09-15 06:39:31.588 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest paging item count=31` -- paging has refreshed again with initial 30 items
7. `2022-09-15 06:39:31.605 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest paging item count=40` -- loaded more data due to scrolling
8. The insertion into Room invalidates Paging, which triggers a REFRESH to reload around where user was last scrolled to
9. `2022-09-15 06:39:32.238 13418-13418/com.example.android.codelabs.paging I/System.out: PagingTest paging item count=32` paging has refreshed again with initial 30 items
And the reason the itemCount drops to 30 everytime Paging REFRESH is because the logic in GithubRemoteMediator#load
clears the room db if its a REFRESh load before inserting newly loaded items.
Hope this helps. Alternatively if you can tell me how / where exactly you logged firstVisibleItemIndex
and item count
, I can see if this is indeed whats happening.
an...@google.com <an...@google.com> #12
cl...@google.com <cl...@google.com> #13
Seems like my initial guess is correct. Essentially within paging itself:
1. Paging load items [0 - 29]
2. present items [0-29]
3. user scrolls down
4. PagingTest new firstVisibleItemIndex=18
5. but actually its LazyPagingItems.get(24)
6. PagingTest composed item at index=24
7. Paging preemptively load items [30-39]
8. itemSnapshotList.size:34 <----- first read, still based on items[0-29] + separators = 34 items
9. itemSnapshotList.size:45 <----- read immediately again, now based on items [0 - 39] + separators = 45 items
10. PagingTest new firstVisibleItemIndex=20
11. .... after a bit PagingTest composed item at index=26
12. RemoteMediator preemptively load items [40-49] and insert into Room db
13. Room insertion invalidates paging causing screen refresh
14. Paging loads and displays items [7-36] upon refresh
15. itemSnapshotList.size:45 <------ first read after refresh, still based on items in step 9.
16. itemSnapshotList.size:32 <------ read immediately again, now correctly based on items [7-36] + separators
cl...@google.com <cl...@google.com> #14
So items are added as users scroll more. It decreases when more data is inserted into room, Paging invalidates and starts refresh with a new snapshot containing the refreshed 30 items (30 is refresh load size).
I'm not sure but it seems like the read on stale snapshot in step 8 and 15 could be the cause of issue?
ar...@gmail.com <ar...@gmail.com> #15
se...@gmail.com <se...@gmail.com> #16
do...@ekohealth.com <do...@ekohealth.com> #17
te...@gmail.com <te...@gmail.com> #18
Paging library looks abandoned (and RemoteMediator is still experimental after more than 2 years), so it's better to manually implement pagination I guess
be...@gmail.com <be...@gmail.com> #19
cl...@google.com <cl...@google.com> #20
The issue happens when placeholders are off due to compose/paging not aware of the real index of an item within the database .
For example, if compose only loaded part of the data from database
LazyPagingItems = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
item 10 = index 0
But within the database
Database [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
item 10 = index 10
So the jumping is due to scroll index being out of sync with datasource index. With remote mediator triggering constant refreshes, this problem becomes exacerbated.
Turning placeholders on resolves the issue because paging/compose is now aware that there are items [0...9] prior to item 10 and now knows that item 10 = index 10.
A proper fix for when placeholders are off would require some time.
I would recommend turning on placeholders in the meantime. That said, please file a ticket / upload sample project if you come across this issue with placeholders on.
de...@gmail.com <de...@gmail.com> #21
What would be the proposed solution for separators use case?
UPDATE
Quick update on insertSeparators-related bug: a call to insertSeparators is buggy itself (even if generator always returns null). Jump happens just when placeholders start popping up, roughly to the position of initial load middle.
cl...@google.com <cl...@google.com> #22
Re:
[Deleted User] <[Deleted User]> #24
any update on this issue?
I'm encountering the same problem.
List is jumping when using insertSeparator
.
I think there is a jump between the items inserted via separator and the items from the DB.
cl...@google.com <cl...@google.com> #25
Re
[Deleted User] <[Deleted User]> #26
cl...@google.com <cl...@google.com> #27
su...@gmail.com <su...@gmail.com> #28
Any updates on above issue?
Description
Version used: 1.0.0-alpha15
Devices/Android versions reproduced on: Pixel 4a
I'm developing an application with Compose and I need to add Paging functionality.
As you can see in the attached video, while scrolling (and the remote mediator is adding items to the database table, I guess) it happens that the scroll jumps back of some positions. This behavior is not casual, it's systematic.
I found the problem in my app so I started wondering if the problem was my implemention or not.
So I downloaded and run the final version of the advanced codelab on Paging 3 (
Even if the codelab code is bugged, due to the fact I'm gonna use Compose I decided to modify the codelab project adding Compose support and focusing on the fullname only of the Github Repo DTO, conveniently altered with an incremental prefix.