Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List items don't render when listData changes #77

Open
stevengoldberg opened this issue Jan 20, 2025 · 8 comments
Open

List items don't render when listData changes #77

stevengoldberg opened this issue Jan 20, 2025 · 8 comments

Comments

@stevengoldberg
Copy link

I have a list of images that's filterable on the client side. It initially loads correctly and displays all items. When I set the filter, the data array changes and my list component renders with the updated data array length. However, no list items are visible.

I put console.log statements in the list component and in the item components. This is what I see when I set the filter to a tag string that returns 60 items:

action filter/setSelectedTags @ 16:16:41.864
filter.js:79 listData (60) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
filter.js:167 renderList
filter-image.js:22 render FilterImage 6E5DC793-C850-477F-A51A-5E338415C269/L0/001
filter-image.js:22 render FilterImage DDD99D4D-17B4-4399-BD73-A0B7F75439BD/L0/001
filter-image.js:22 render FilterImage B8F2CE28-6D4B-4302-9DE5-6E8295DA74D6/L0/001
filter-image.js:22 render FilterImage FB90EE44-EA81-47FF-A20E-D73236C6247E/L0/001
filter-image.js:22 render FilterImage 71EB3C5D-F1C1-4B33-987A-E97122E87653/L0/001
filter-image.js:22 render FilterImage BCA76E8A-C448-465B-9AEB-5C79388C39B0/L0/001
filter-image.js:22 render FilterImage F075271A-A3EF-4660-9572-96964FF8AAE5/L0/001
filter-image.js:22 render FilterImage 25A3587B-A2B6-4382-935D-2E53EB4B499E/L0/001
filter-image.js:22 render FilterImage 407E8C8A-3E84-4FC4-B573-E6335E645E02/L0/001
filter-image.js:22 render FilterImage 82FDE687-5B6D-4503-96AE-2698C70F67B6/L0/001
filter-image.js:22 render FilterImage 533A24EA-C0A3-4635-A6E3-D85054F98BE4/L0/001
filter-image.js:22 render FilterImage 2893B781-F96D-42B6-9431-1DAC763E5163/L0/001
filter-image.js:22 render FilterImage 9B148798-6352-4458-B48A-720EAD929ED3/L0/001
filter-image.js:22 render FilterImage 045EDE4E-D648-4A75-A2B5-147F5E2BF655/L0/001
filter-image.js:22 render FilterImage F3E84437-ACE9-4A88-895C-9274CF0E9A45/L0/001
filter-image.js:22 render FilterImage BCE185B7-7AD9-4F0F-9C80-67C5042FDD84/L0/001
filter-image.js:22 render FilterImage CC042A77-C273-4AD8-AC78-B71523724B97/L0/001
filter-image.js:22 render FilterImage B4766A52-3790-4823-B9E8-4460B39C5E6D/L0/001
filter-image.js:22 render FilterImage 90FB5C03-4C90-4E43-8203-82CF6746E0CA/L0/001
filter-image.js:22 render FilterImage 2AD1A28B-E354-4346-95F4-2E57B384C553/L0/001
filter-image.js:22 render FilterImage 8A48EC30-2CBE-445A-B09E-5393AF35FE4A/L0/001
filter-image.js:22 render FilterImage B70235B1-FEC5-4F22-8438-367AEC272766/L0/001
filter-image.js:22 render FilterImage 4FB599A5-A472-416B-91FB-0FE5D6F508F9/L0/001
filter-image.js:22 render FilterImage 1601856F-E972-4BF6-9EC4-91F30CE79762/L0/001
filter-image.js:22 render FilterImage 5CACAE51-82F2-4608-97B7-4D4C23BA23B6/L0/001
filter-image.js:22 render FilterImage 57CBE385-DDB0-43C2-8F7D-4B387650D241/L0/001
filter-image.js:22 render FilterImage 420386B4-0BCE-4287-87E6-E0E90342F7B2/L0/001
filter-image.js:22 render FilterImage A05D3D83-EC93-4C62-867E-05F8FEB9911A/L0/001
filter-image.js:22 render FilterImage E5EF060E-99F0-4DCE-B352-22E749C7E990/L0/001
filter-image.js:22 render FilterImage B6A73450-7A24-4A17-9DD5-B44EE8C83EB8/L0/001
filter-image.js:22 render FilterImage DB876F9A-0A75-421F-8E5C-F8E246CB5463/L0/001
filter-image.js:22 render FilterImage 515EE930-994C-4173-BCDA-C3CE1CA3536B/L0/001
filter-image.js:22 render FilterImage 52F20586-4B0C-4B01-ADDF-305352C985D0/L0/001
filter-image.js:22 render FilterImage 777D2523-847E-4B76-B789-A5E17928FA11/L0/001
filter-image.js:22 render FilterImage 8830AF60-A23C-4921-B9C8-0429DB633637/L0/001
filter-image.js:22 render FilterImage 8AF1C2EE-331D-4CCA-B8AD-83B310EC1FA1/L0/001
filter.js:79 listData (60) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
filter.js:167 renderList
filter.js:79 listData (60) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
filter.js:167 renderList

But nothing is displayed in the list:

Image

When I reset the filter and render all the items again, I see these logs:

action filter/setSelectedTags @ 16:18:15.491
filter.js:79 listData (1677) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
filter.js:167 renderList
filter-image.js:22 render FilterImage 7CA1F49C-7DD4-47A6-85C0-142B3D6CD4FC/L0/001
filter-image.js:22 render FilterImage 173B3920-55D3-4EA5-A35A-978B0D914805/L0/001
filter-image.js:22 render FilterImage 9F374F4B-9682-4B3B-AD88-FAD1F8BC9A88/L0/001
filter-image.js:22 render FilterImage D27A6C0A-5AD2-4890-A065-E2E1AC79220D/L0/001
filter-image.js:22 render FilterImage F24A8487-B578-42B4-88F2-CF599AED09C0/L0/001
filter-image.js:22 render FilterImage F7BD6302-BDDD-4700-80F0-0AC1C5DB04A4/L0/001
filter-image.js:22 render FilterImage B42C464B-8AD8-433E-86C7-B5B50AFAA475/L0/001
filter-image.js:22 render FilterImage DFEE954A-CC3D-4359-AAC3-196548EC0E1D/L0/001
filter-image.js:22 render FilterImage EF898A63-ED23-4CE9-B73D-01142A7C168E/L0/001
filter-image.js:22 render FilterImage E5BBF381-14DF-4E5F-8D73-3500B7F0F309/L0/001
filter-image.js:22 render FilterImage 1B628012-1C59-4C42-A974-C045DBA56C16/L0/001
filter-image.js:22 render FilterImage 727FBD93-2BA7-41B7-9521-3F38E9AE7AC7/L0/001
filter-image.js:22 render FilterImage 11BE7BD2-A3F2-4A39-BAF1-83369A2CC459/L0/001
filter-image.js:22 render FilterImage AEF76BE1-8DC0-4828-9B15-AB6C4D704CC3/L0/001
filter-image.js:22 render FilterImage 8CB87717-F54D-457C-A974-1D402BBCC819/L0/001
filter-image.js:22 render FilterImage 83CCA4CF-3115-4228-A496-CF8444514E92/L0/001
filter-image.js:22 render FilterImage BF38020E-6CF6-4A1A-BE94-104D3DF78F24/L0/001
filter-image.js:22 render FilterImage 4F4D5B9E-A124-4266-85EF-B8E38C1E844A/L0/001
filter-image.js:22 render FilterImage 940247C8-D11E-48FE-811D-15F4CB9D84F4/L0/001
filter-image.js:22 render FilterImage 863C04C2-47A4-479F-9EED-28A9F97A49D4/L0/001
filter-image.js:22 render FilterImage 815C984A-CC5F-4728-A834-CC095CF0CC26/L0/001
filter-image.js:22 render FilterImage DDBA0F6E-5D81-47D8-9A94-FF92D2B9BB58/L0/001
filter-image.js:22 render FilterImage DD03A33C-6D0C-46D1-BECA-E1A884B27AFE/L0/001
filter-image.js:22 render FilterImage E9F12C77-D3D8-4C51-A814-46D6444C3113/L0/001
filter-image.js:22 render FilterImage 1A4AA875-0588-4656-B548-83A8CDA72041/L0/001
filter-image.js:22 render FilterImage 72E4FBF3-FE10-4A8E-90C3-22D93375DE13/L0/001
filter-image.js:22 render FilterImage 9B9F2E04-6835-425A-BCB0-6F156645A40F/L0/001
filter-image.js:22 render FilterImage BBC22AB5-E89E-4F48-8D77-3C80831E20E9/L0/001
filter-image.js:22 render FilterImage 3B4BEEA6-CB6A-42CB-80F2-1BD4114ABBFB/L0/001
filter-image.js:22 render FilterImage D7D211F9-0E6D-4D4A-AD57-52C86FA15491/L0/001
filter-image.js:22 render FilterImage 606E4731-735B-4AA9-890B-E4282B48BBA1/L0/001
filter-image.js:22 render FilterImage 2DC1F2FD-5E32-45E9-8970-FF3EC38216FF/L0/001
filter-image.js:22 render FilterImage FFC64748-6EAA-4A2D-8AAE-8900ADA31659/L0/001
filter-image.js:22 render FilterImage EEAA3622-0C18-45F0-B5B3-F00C8E1D19D1/L0/001
filter-image.js:22 render FilterImage C2FF6EB6-3E2E-472E-B7B0-633570417FC6/L0/001
filter-image.js:22 render FilterImage 16A91B79-1FFA-4B1B-A670-3CE2CA6E35C0/L0/001
filter-image.js:22 render FilterImage 69640BC6-8D7F-41F7-88EE-EDD6FEE0C488/L0/001
filter-image.js:22 render FilterImage CE0BD991-E098-4C3A-A932-2590E23D1F6D/L0/001
filter-image.js:22 render FilterImage 6C0AD1F1-9C6F-40CE-B3EC-3BDF0306C977/L0/001
filter-image.js:22 render FilterImage 3C3FFAB1-1DE3-4241-B428-F521D4CB71C5/L0/001
filter-image.js:22 render FilterImage EE2A5082-E2CF-46C1-AB60-E3CC920CC1D7/L0/001
filter-image.js:22 render FilterImage 760AF805-D43C-4F6C-9304-901C6FE3E365/L0/001
filter-image.js:22 render FilterImage A8BAF5C1-4B74-4D1D-A322-D0E50D531F27/L0/001
filter-image.js:22 render FilterImage 269953C1-37CF-4A85-83A2-E181ED360B49/L0/001
filter-image.js:22 render FilterImage D652A837-DF42-4152-9748-49CB5CC3C3B7/L0/001
filter-image.js:22 render FilterImage 3201C2C5-4C48-4DAC-BADA-74714E0BFF81/L0/001
filter-image.js:22 render FilterImage E26DDB9B-83D2-443C-B620-06861253E280/L0/001
filter-image.js:22 render FilterImage DB99CA8A-07B4-49E9-A737-DD63689F9C5E/L0/001
filter-image.js:22 render FilterImage F97ACEDE-7A8B-449A-817A-9155221CD040/L0/001
filter-image.js:22 render FilterImage 0EEF34DB-E1DB-46CB-A107-6FBCF67140D5/L0/001
filter-image.js:22 render FilterImage 6E481C0D-068D-4AB5-8071-261973A86224/L0/001
filter-image.js:22 render FilterImage 660404C7-E948-4A72-A43B-A8F88350B673/L0/001
filter-image.js:22 render FilterImage 82493F14-00B9-42B7-95ED-BD85A9AE0276/L0/001
filter-image.js:22 render FilterImage 9897A140-1083-4E59-8C37-A82A6266245E/L0/001
filter-image.js:22 render FilterImage 4F2C32CB-71A5-40C4-B1EF-3418F2651D3D/L0/001
filter-image.js:22 render FilterImage 0CB7CD32-F1B4-4174-9501-F6DDC4AD00C1/L0/001
filter-image.js:22 render FilterImage 4FA75DCC-3C8C-4453-932E-BB5D7B220B6F/L0/001
filter-image.js:22 render FilterImage 26A90F37-6D46-4525-8548-0DCE68069D5B/L0/001
filter-image.js:22 render FilterImage 79729241-89D2-46EE-BA2D-24D57C7EED04/L0/001
filter-image.js:22 render FilterImage E50788D8-B41F-41CA-BA82-BD10E9546B32/L0/001
filter.js:79 listData (1677) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
filter.js:167 renderList
filter-image.js:22 render FilterImage 90FB5C03-4C90-4E43-8203-82CF6746E0CA/L0/001
filter-image.js:22 render FilterImage 2AD1A28B-E354-4346-95F4-2E57B384C553/L0/001
filter-image.js:22 render FilterImage 8A48EC30-2CBE-445A-B09E-5393AF35FE4A/L0/001
filter-image.js:22 render FilterImage BCE185B7-7AD9-4F0F-9C80-67C5042FDD84/L0/001
filter-image.js:22 render FilterImage CC042A77-C273-4AD8-AC78-B71523724B97/L0/001
filter-image.js:22 render FilterImage B4766A52-3790-4823-B9E8-4460B39C5E6D/L0/001
filter-image.js:22 render FilterImage 9B148798-6352-4458-B48A-720EAD929ED3/L0/001
filter-image.js:22 render FilterImage 045EDE4E-D648-4A75-A2B5-147F5E2BF655/L0/001
filter-image.js:22 render FilterImage F3E84437-ACE9-4A88-895C-9274CF0E9A45/L0/001
filter-image.js:22 render FilterImage 82FDE687-5B6D-4503-96AE-2698C70F67B6/L0/001
filter-image.js:22 render FilterImage 533A24EA-C0A3-4635-A6E3-D85054F98BE4/L0/001
filter-image.js:22 render FilterImage 2893B781-F96D-42B6-9431-1DAC763E5163/L0/001
filter-image.js:22 render FilterImage F075271A-A3EF-4660-9572-96964FF8AAE5/L0/001
filter-image.js:22 render FilterImage 25A3587B-A2B6-4382-935D-2E53EB4B499E/L0/001
filter-image.js:22 render FilterImage 407E8C8A-3E84-4FC4-B573-E6335E645E02/L0/001
filter-image.js:22 render FilterImage FB90EE44-EA81-47FF-A20E-D73236C6247E/L0/001
filter-image.js:22 render FilterImage 71EB3C5D-F1C1-4B33-987A-E97122E87653/L0/001
filter-image.js:22 render FilterImage BCA76E8A-C448-465B-9AEB-5C79388C39B0/L0/001
filter-image.js:22 render FilterImage B70235B1-FEC5-4F22-8438-367AEC272766/L0/001
filter-image.js:22 render FilterImage 4FB599A5-A472-416B-91FB-0FE5D6F508F9/L0/001
filter-image.js:22 render FilterImage 1601856F-E972-4BF6-9EC4-91F30CE79762/L0/001
filter-image.js:22 render FilterImage 5CACAE51-82F2-4608-97B7-4D4C23BA23B6/L0/001
filter-image.js:22 render FilterImage 57CBE385-DDB0-43C2-8F7D-4B387650D241/L0/001
filter-image.js:22 render FilterImage 420386B4-0BCE-4287-87E6-E0E90342F7B2/L0/001
filter-image.js:22 render FilterImage A05D3D83-EC93-4C62-867E-05F8FEB9911A/L0/001
filter-image.js:22 render FilterImage E5EF060E-99F0-4DCE-B352-22E749C7E990/L0/001
filter-image.js:22 render FilterImage B6A73450-7A24-4A17-9DD5-B44EE8C83EB8/L0/001
filter-image.js:22 render FilterImage DB876F9A-0A75-421F-8E5C-F8E246CB5463/L0/001
filter-image.js:22 render FilterImage 515EE930-994C-4173-BCDA-C3CE1CA3536B/L0/001
filter-image.js:22 render FilterImage 52F20586-4B0C-4B01-ADDF-305352C985D0/L0/001
filter-image.js:22 render FilterImage 777D2523-847E-4B76-B789-A5E17928FA11/L0/001
filter-image.js:22 render FilterImage 8830AF60-A23C-4921-B9C8-0429DB633637/L0/001
filter-image.js:22 render FilterImage 8AF1C2EE-331D-4CCA-B8AD-83B310EC1FA1/L0/001
filter-image.js:22 render FilterImage 6E5DC793-C850-477F-A51A-5E338415C269/L0/001
filter-image.js:22 render FilterImage DDD99D4D-17B4-4399-BD73-A0B7F75439BD/L0/001
filter-image.js:22 render FilterImage B8F2CE28-6D4B-4302-9DE5-6E8295DA74D6/L0/001
filter-image.js:22 render FilterImage 7CA4CE3A-2280-4014-B89C-6EC1DE59D0F3/L0/001
filter-image.js:22 render FilterImage 3896CE27-A2CB-4326-9E6E-C9BC08E923F1/L0/001
filter-image.js:22 render FilterImage 3CB41C02-62F0-480E-AA20-355D89DF9DF5/L0/001

And the list renders as expected again:

Image

Not sure what code to include as my components are complex, but I tried pulling things out one by one and couldn't find any props that made a difference. When I use FlashList the filtering works as expected.

@jmeistrich
Copy link
Contributor

jmeistrich commented Jan 21, 2025

Hmm, not sure what that could be...

We'll try making some examples with filtering like that and see if we can find a way to reproduce that. @michbil have you seen anything like this while testing your data changes?

@michbil
Copy link

michbil commented Jan 21, 2025

I can only suspect that when amount of items is drastically decreased, we can be stuck at the middle of the list(scroll position not updated), and that's why it seems that there are no elements.

Tried to add

 useEffect(() => {
        setTimeout(() => {
            setData([{id: "5"}])
        },5000);
    },[])

to the example/app/(tabs)card.tsx

if you don't scroll, everything looks fine, if you scroll list down, you will get this and there is no way to recover from this state.

Image

@stevengoldberg
Copy link
Author

stevengoldberg commented Jan 21, 2025

Thanks for looking into this. I'll try and create a proper minimal repro soon. I just did some more testing and I'm seeing inconsistent results, but I still can't quite pin down the logic behind it.

In the capture below, you can see I initially have 99 results. When I apply a filter ("test") that returns 9 results, they render correctly, but the top padding of the list is wrong. When I remove the filter it re-renders as expected.

Next, I apply a different filter ("filtered") that returns 5 results, and it works as expected.

Last, I apply a filter ("foo") that returns 20 results. This time nothing renders. Then when I remove the filter, the list doesn't correctly re-render until I scroll.

Image

@stevengoldberg
Copy link
Author

Ok, I was able to get a little more specific with the behavior. Previously, I was using initialScrollIndex={listData.length - 1} and maintainScrollAtEnd, because that's the behavior I need. But if I remove those props and filter the list without scrolling down first, it re-renders as expected. However, if I scroll too far down the list and then apply the filter, I get a blank list. If I then reset the filter, scroll back up, and filter again, the list remains blank.

@michbil
Copy link

michbil commented Jan 22, 2025

@stevengoldberg Thanks, that agrees with my observations, I will try take a look tonight, if somebody wouldn't fix if faster :)

@jmeistrich
Copy link
Contributor

@michbil Great! I'm catching up on my day job for a bit so I'm wouldn't be able to get to it for a couple days.

@michbil
Copy link

michbil commented Jan 23, 2025

Preliminary investigation showed that we don't reset container positions upon data change, which causes old invalid container positions being used.
I'm investigating if resetting positions each time will bring additional issues, or it's just fine.

UPD: just resetting positions degrades "Mutable elements" example very much, we need something more smarter.

@jmeistrich
Copy link
Contributor

I believe resetting positions would trigger a render of all containers, followed by another render when their positions are set again. So that's probably not a good way to go 😅

Maybe we can set a flag for calculateItemsInView to force it to set positions on everything? But I'm not sure what the actual problem is so I'm just throwing that out... @michbil Let me know if I can help with any ideas, otherwise I'll leave this to you 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants