From 26f02bebeae1d422a11a0ca9e7a96752c9926881 Mon Sep 17 00:00:00 2001 From: David Luzar <5153846+dwelle@users.noreply.github.com> Date: Wed, 12 Feb 2025 13:02:53 +0100 Subject: [PATCH] fix: stop using structuredClone (#9128) fix: stop using `structuredClone` --- packages/excalidraw/element/elbowArrow.ts | 16 ++++++++-------- packages/excalidraw/element/types.ts | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/excalidraw/element/elbowArrow.ts b/packages/excalidraw/element/elbowArrow.ts index 498e59d71a..a2762adfa6 100644 --- a/packages/excalidraw/element/elbowArrow.ts +++ b/packages/excalidraw/element/elbowArrow.ts @@ -104,7 +104,7 @@ const handleSegmentRenormalization = ( elementsMap: NonDeletedSceneElementsMap | SceneElementsMap, ) => { const nextFixedSegments: FixedSegment[] | null = arrow.fixedSegments - ? structuredClone(arrow.fixedSegments) + ? arrow.fixedSegments.slice() : null; if (nextFixedSegments) { @@ -270,7 +270,7 @@ const handleSegmentRenormalization = ( const handleSegmentRelease = ( arrow: ExcalidrawElbowArrowElement, - fixedSegments: FixedSegment[], + fixedSegments: readonly FixedSegment[], elementsMap: NonDeletedSceneElementsMap | SceneElementsMap, ) => { const newFixedSegmentIndices = fixedSegments.map((segment) => segment.index); @@ -444,7 +444,7 @@ const handleSegmentRelease = ( */ const handleSegmentMove = ( arrow: ExcalidrawElbowArrowElement, - fixedSegments: FixedSegment[], + fixedSegments: readonly FixedSegment[], startHeading: Heading, endHeading: Heading, hoveredStartElement: ExcalidrawBindableElement | null, @@ -686,7 +686,7 @@ const handleSegmentMove = ( const handleEndpointDrag = ( arrow: ExcalidrawElbowArrowElement, updatedPoints: readonly LocalPoint[], - fixedSegments: FixedSegment[], + fixedSegments: readonly FixedSegment[], startHeading: Heading, endHeading: Heading, startGlobalPoint: GlobalPoint, @@ -944,8 +944,8 @@ export const updateElbowArrowPoints = ( ? updates.points![1] : p, ) - : structuredClone(updates.points) - : structuredClone(arrow.points); + : updates.points.slice() + : arrow.points.slice(); const { startHeading, @@ -1965,7 +1965,7 @@ const getBindableElementForId = ( const normalizeArrowElementUpdate = ( global: GlobalPoint[], - nextFixedSegments: FixedSegment[] | null, + nextFixedSegments: readonly FixedSegment[] | null, startIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"], endIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"], ): { @@ -1974,7 +1974,7 @@ const normalizeArrowElementUpdate = ( y: number; width: number; height: number; - fixedSegments: FixedSegment[] | null; + fixedSegments: readonly FixedSegment[] | null; startIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"]; endIsSpecial?: ExcalidrawElbowArrowElement["startIsSpecial"]; } => { diff --git a/packages/excalidraw/element/types.ts b/packages/excalidraw/element/types.ts index 0ab88358d8..ecd5ffecdd 100644 --- a/packages/excalidraw/element/types.ts +++ b/packages/excalidraw/element/types.ts @@ -337,7 +337,7 @@ export type ExcalidrawElbowArrowElement = Merge< elbowed: true; startBinding: FixedPointBinding | null; endBinding: FixedPointBinding | null; - fixedSegments: FixedSegment[] | null; + fixedSegments: readonly FixedSegment[] | null; /** * Marks that the 3rd point should be used as the 2nd point of the arrow in * order to temporarily hide the first segment of the arrow without losing