Skip to content

Commit

Permalink
fix: improper cloning of custom fields (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
shmishtopher committed Feb 6, 2024
1 parent ca325f5 commit 4981da7
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/core/src/meta/ObjectMetaField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,28 @@ class ObjectMetaFieldInternal<
}

public override serialize(): ValueOf<T> {
return this.transform('serialize');
return {
...this.transform('serialize'),
...this.customFields,
};
}

public override clone(): this {
return new (<any>this.constructor)(this.name, this.transform('clone'));
const cloned = new (<any>this.constructor)(
this.name,
this.transform('clone'),
);
cloned.set(structuredClone(this.customFields));

return cloned;
}

protected handleChange = () => {
if (this.ignoreChange) return;
this.value.current = this.transform('get');
this.value.current = {
...this.transform('get'),
...this.customFields,
};
};

protected transform<TKey extends CallableKeys<MetaField<any>>>(
Expand All @@ -91,10 +103,7 @@ class ObjectMetaFieldInternal<
Array.from(this.fields, ([name, field]) => [name, field[fn]()]),
) as TransformationOf<T, TKey>;

return {
...transformed,
...this.customFields,
};
return transformed;
}
}

Expand Down

0 comments on commit 4981da7

Please sign in to comment.