frame bg: treat non-boolean legacy flag as missing

This commit is contained in:
Ryan Di
2026-03-18 19:55:52 +11:00
parent 48bc930c09
commit c4925dc5b9
2 changed files with 24 additions and 5 deletions
+5 -5
View File
@@ -509,11 +509,11 @@ export const restoreElement = (
name: element.name ?? null, name: element.name ?? null,
}); });
case "frame": case "frame":
const hasBackgroundEnabled = Object.prototype.hasOwnProperty.call( const hasBackgroundEnabled =
element, typeof (element as any).backgroundEnabled === "boolean";
"backgroundEnabled", const backgroundEnabled = hasBackgroundEnabled
); ? (element as any).backgroundEnabled
const backgroundEnabled = (element as any).backgroundEnabled ?? false; : false;
return restoreElementWithProperties(element, { return restoreElementWithProperties(element, {
name: element.name ?? null, name: element.name ?? null,
backgroundEnabled, backgroundEnabled,
@@ -99,6 +99,25 @@ describe("restoreElements", () => {
expect(restoredFrame.backgroundEnabled).toBe(false); expect(restoredFrame.backgroundEnabled).toBe(false);
}); });
it("should disable frame background when legacy backgroundEnabled is non-boolean", () => {
const frame = API.createElement({
type: "frame",
backgroundColor: "#ffc9c9",
});
const legacyFrame = {
...frame,
backgroundEnabled: undefined,
} as any;
const restoredFrame = restore.restoreElements(
[legacyFrame],
null,
)[0] as ExcalidrawFrameElement;
expect(restoredFrame.backgroundColor).toBe("transparent");
expect(restoredFrame.backgroundEnabled).toBe(false);
});
it("should preserve frame backgroundEnabled when present", () => { it("should preserve frame backgroundEnabled when present", () => {
const frame = API.createElement({ const frame = API.createElement({
type: "frame", type: "frame",