Skip to content

Commit 6bf580a

Browse files
authored
Flatten undefined properties correctly (#2276)
1 parent 3ad4b8b commit 6bf580a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

packages/core/src/v3/utils/flattenAttributes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ class AttributeFlattener {
209209
return;
210210
}
211211

212+
if (value === undefined) {
213+
return;
214+
}
215+
212216
// Handle primitive values directly
213217
if (value === null) {
214218
this.addAttribute(prefix, NULL_SENTINEL);

packages/core/test/flattenAttributes.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ describe("flattenAttributes", () => {
6161
expect(unflattenAttributes(result)).toEqual(input);
6262
});
6363

64+
it("flattens properties that are undefined correctly", () => {
65+
const result = flattenAttributes({ foo: undefined, bar: "baz" });
66+
expect(result).toEqual({ bar: "baz" });
67+
});
68+
6469
it("flattens complex objects correctly", () => {
6570
const obj = {
6671
level1: {

0 commit comments

Comments
 (0)