Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/plenty-kiwis-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react": patch
---

Should only recycle off-screen `list-item` in recursive hydration.
11 changes: 10 additions & 1 deletion packages/react/runtime/__test__/list.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,11 @@ describe('list reload', () => {
hydrate(b, bb);
b.unRenderElements();

// Should only update `list-item` in the recycling pool
// Should not add the on-screen `list-item` to the recycling pool,
expect([...recycleSignMap.keys()]).toStrictEqual([__GetElementUniqueID(d3.__element_root)]);
expect(recycleSignMap.get(__GetElementUniqueID(d3.__element_root))).not.toBe(d3);

// The one rendered <list-item/> should be removed
expect(root).toMatchInlineSnapshot(`
<view>
Expand Down Expand Up @@ -1940,7 +1945,11 @@ describe('list reload', () => {
expect(signMap.get(__GetElementUniqueID(d1.__element_root))).toBe(d2_); // note: d1 is reused by d2_
expect(signMap.get(__GetElementUniqueID(d2_.__element_root))).toBe(d2_);
expect(signMap.get(__GetElementUniqueID(d3_.__element_root))).toBe(d3_);
expect(recycleSignMap.get(__GetElementUniqueID(d3_.__element_root))).toBe(d3_);
Comment thread
gaoachao marked this conversation as resolved.
// d1 was enqueued as well, so it should be in the recycling pool
expect([...recycleSignMap.keys()]).toStrictEqual([
__GetElementUniqueID(d3.__element_root),
__GetElementUniqueID(d1.__element_root),
]);
});
});

Expand Down
7 changes: 6 additions & 1 deletion packages/react/runtime/src/hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,12 @@ export function hydrate(before: SnapshotInstance, after: SnapshotInstance, optio
}
if (recycleMap.has(a.type)) {
const recycleSignMap = recycleMap.get(a.type)!;
recycleSignMap.set(listItemID, b);
// Should only update `list-item` in the recycling pool
// Because if an on-screen `list-item` is added to the recycling pool,
// it could cause a blank screen when reused next time, as it may still be visible.
if (recycleSignMap.has(listItemID)) {
recycleSignMap.set(listItemID, b);
}
}
}
},
Expand Down
Loading