Question
Can OnPush cause stale UI when mutating @Input objects?
Lax Finch
0 reputation · 03 Nov 2020, 06:22 UTC
17.1K views0
Goal
Determine how Angular’s OnPush change‑detection strategy can lead to a component’s view not reflecting state changes when the parent mutates an @Input object without changing its reference.
Constraints & Uncertainty
- OnPush only runs change detection when a reference‐changing input, a component event, or an async pipe emits.
- In-place mutations (e.g., array.push, object.property = value) do not trigger detection, potentially leaving the UI stale.
- Third‑party libraries may internally mutate data structures without emitting events, further risking UI staleness.
Specific Questions
- Which mutation patterns on @Input objects are most likely to be ignored by OnPush?
- How can we programmatically detect when a library’s internal state changes violate immutability expectations?
- What best‑practice patterns (e.g., immutable updates, markForCheck, detach) mitigate the risk of stale UI in OnPush components?