fix: conditionally deserialize b/w POJO and class instance for diff updates

This commit is contained in:
Smit 2025-06-28 04:43:00 +05:30
parent 692b17ffd3
commit d1e6d9a312
2 changed files with 9 additions and 12 deletions

View file

@ -1385,6 +1385,12 @@ export class Widget {
}
@Type(() => WidgetProps, { discriminator: { property: "kind", subTypes: [...widgetSubTypes] }, keepDiscriminatorProperty: true })
@Transform(({ value }) => {
if (value.kind === "PopoverButton") {
value.popoverLayout = value.popoverLayout.map(createLayoutGroup);
}
return value;
})
props!: WidgetPropsSet;
widgetId!: bigint;
@ -1396,10 +1402,6 @@ function hoistWidgetHolder(widgetHolder: any): Widget {
const props = widgetHolder.widget[kind];
props.kind = kind;
if (kind === "PopoverButton") {
props.popoverLayout = props.popoverLayout.map(createLayoutGroup);
}
const { widgetId } = widgetHolder;
return plainToClass(Widget, { props, widgetId });
@ -1476,13 +1478,9 @@ export function patchWidgetLayout(layout: /* &mut */ WidgetLayout, updates: Widg
Reflect.set(diffObject, "length", 0);
}
// Clear existing properties
// Remove all keys using Reflect.deleteProperty to ensure proxy notifications
Reflect.ownKeys(diffObject).forEach((key) => {
if (key !== "length") {
// Don't delete length property on arrays
Reflect.deleteProperty(diffObject, key);
}
// Remove all enumerable properties using Reflect.deleteProperty to ensure proxy notifications
Object.keys(diffObject).forEach((key) => {
Reflect.deleteProperty(diffObject, key);
});
// Assign new properties

View file

@ -17,7 +17,6 @@ import {
} from "@graphite/messages.svelte";
export const documentContextState = $state({
// Layouts - these are already $state objects from defaultWidgetLayout()
documentModeLayout: defaultWidgetLayout(),
toolOptionsLayout: defaultWidgetLayout(),
documentBarLayout: defaultWidgetLayout(),