From 6ca55428b17b53fe22e643c1f67ae31be69bdafd Mon Sep 17 00:00:00 2001 From: Nguyen Van Nam Date: Mon, 30 Mar 2026 00:42:21 +0700 Subject: [PATCH] refactor: map equality treats missing keys as equal when mapped value is null `areMapsEqual` compares values via `next[key]` without verifying key presence. If `prev` has `{a: null}` and `next` has `{b: null}` (same size, different keys), `next[a]` returns `null`, the value comparison passes, and the method incorrectly returns `true`. This can cause silent diffing errors (e.g., skipping updates when maps actually changed), leading to stale UI/state. Affected files: MapDiffUtils.kt Signed-off-by: Nguyen Van Nam --- .../src/main/java/com/facebook/litho/utils/MapDiffUtils.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litho-core/src/main/java/com/facebook/litho/utils/MapDiffUtils.kt b/litho-core/src/main/java/com/facebook/litho/utils/MapDiffUtils.kt index 2e60f949736..948d15d8a23 100644 --- a/litho-core/src/main/java/com/facebook/litho/utils/MapDiffUtils.kt +++ b/litho-core/src/main/java/com/facebook/litho/utils/MapDiffUtils.kt @@ -31,6 +31,6 @@ object MapDiffUtils { if (prev.size != next.size) { return false } - return prev.none { (key, value) -> !equals(value, next[key]) } + return prev.all { (key, value) -> next.containsKey(key) && equals(value, next[key]) } } }