frame bg: treat non-boolean legacy flag as missing
This commit is contained in:
@@ -509,11 +509,11 @@ export const restoreElement = (
|
||||
name: element.name ?? null,
|
||||
});
|
||||
case "frame":
|
||||
const hasBackgroundEnabled = Object.prototype.hasOwnProperty.call(
|
||||
element,
|
||||
"backgroundEnabled",
|
||||
);
|
||||
const backgroundEnabled = (element as any).backgroundEnabled ?? false;
|
||||
const hasBackgroundEnabled =
|
||||
typeof (element as any).backgroundEnabled === "boolean";
|
||||
const backgroundEnabled = hasBackgroundEnabled
|
||||
? (element as any).backgroundEnabled
|
||||
: false;
|
||||
return restoreElementWithProperties(element, {
|
||||
name: element.name ?? null,
|
||||
backgroundEnabled,
|
||||
|
||||
@@ -99,6 +99,25 @@ describe("restoreElements", () => {
|
||||
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", () => {
|
||||
const frame = API.createElement({
|
||||
type: "frame",
|
||||
|
||||
Reference in New Issue
Block a user