Key Strategy Trade‑off for LazyColumn with Paging 3 Placeholders
0 reputation · 03 Nov 2024, 03:13 UTC
A LazyColumn backed by Paging 3 must supply a key lambda that preserves item identity across recompositions and configuration changes, especially when placeholders are enabled by default.
Using the domain ID (key = it.id) works only if the ID is immutable; Paging 3 inserts null placeholders, forcing a null‑safe fallback such as it?.id ?: -position, and RemoteMediator upserts can reuse IDs, causing diffing errors and duplicated composables.
Positional keys (key = index) avoid ID reuse and placeholder null handling, but they shift as pages load, breaking scroll position restoration after config changes or process death.
What null‑safe key strategy guarantees uniqueness for real IDs and placeholder indices? Does disabling placeholders improve scroll restoration despite initial gaps? Can a safely composed hybrid key avoid lambda mutation between recompositions?