The shallow function does not correctly compare Set type data. #2975
Unanswered
qingzhoufeihu
asked this question in
Bug report
Replies: 1 comment 1 reply
-
It's because |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Bug Description
`const Set1 = new Set([{ a: 1 }]);
const Set2 = new Set([{ a: 1 }]);
console.log(shallow(Set1, Set2));`
The reason it returns false here is that one of the values is undefined, not because the values are different or the references are different.
const compareEntries = (valueA, valueB) => {
const mapA = valueA instanceof Map ? valueA : new Map(valueA.entries());
const mapB = valueB instanceof Map ? valueB : new Map(valueB.entries());
if (mapA.size !== mapB.size) return false;
for (const [key, value] of mapA) {
console.log("mapB.get(key)", mapB.get(key));// undefined
if (!Object.is(value, mapB.get(key))) return false;
}
return true;
};
Reproduction Link
https://stackblitz.com/edit/vitejs-vite-hbcg6a?file=src%2Fcounter.js
Beta Was this translation helpful? Give feedback.
All reactions