From dd8a7d41e2d51381a5771bfef5edf071a00a0595 Mon Sep 17 00:00:00 2001 From: David Luzar <5153846+dwelle@users.noreply.github.com> Date: Fri, 24 Nov 2023 19:55:56 +0100 Subject: [PATCH] fix: bounds cached prematurely resulting in incorrectly rendered labels (#7339) --- src/element/bounds.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/element/bounds.ts b/src/element/bounds.ts index d0d0feba..eddd4083 100644 --- a/src/element/bounds.ts +++ b/src/element/bounds.ts @@ -22,6 +22,7 @@ import { getBoundTextElement, getContainerElement } from "./textElement"; import { LinearElementEditor } from "./linearElementEditor"; import { Mutable } from "../utility-types"; import { ShapeCache } from "../scene/ShapeCache"; +import Scene from "../scene/Scene"; export type RectangleBox = { x: number; @@ -59,10 +60,17 @@ export class ElementBounds { const bounds = ElementBounds.calculateBounds(element); - ElementBounds.boundsCache.set(element, { - version: element.version, - bounds, - }); + // hack to ensure that downstream checks could retrieve element Scene + // so as to have correctly calculated bounds + // FIXME remove when we get rid of all the id:Scene / element:Scene mapping + const shouldCache = Scene.getScene(element); + + if (shouldCache) { + ElementBounds.boundsCache.set(element, { + version: element.version, + bounds, + }); + } return bounds; }