fix: Speculative fixes for arrow invariant failures (#11241)

Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
Márk Tolmács
2026-05-06 16:39:45 +02:00
committed by GitHub
parent 974b338b7e
commit 7f56cc0cf3
3 changed files with 31 additions and 14 deletions
+5 -6
View File
@@ -734,12 +734,11 @@ const getBindingStrategyForDraggingBindingElementEndpoints_simple = (
}); });
// Handle outside-outside binding to the same element // Handle outside-outside binding to the same element
if (otherBinding && otherBinding.elementId === hit?.id) { if (
invariant( otherBinding &&
!opts?.newArrow || appState.selectedLinearElement?.initialState.origin, otherBinding.elementId === hit?.id &&
"appState.selectedLinearElement.initialState.origin must be defined for new arrows", (!opts?.newArrow || appState.selectedLinearElement?.initialState.origin)
); ) {
return { return {
start: { start: {
mode: "inside", mode: "inside",
+5 -5
View File
@@ -486,7 +486,7 @@ export class LinearElementEditor {
selectedPointsIndices, selectedPointsIndices,
)}) points(0..${ )}) points(0..${
element.points.length - 1 element.points.length - 1
}) lastClickedPoint(${lastClickedPoint})`, }) lastClickedPoint(${lastClickedPoint}) isElbowArrow: ${elbowed}`,
); );
// Fall back to the actual last point as a last resort. // Fall back to the actual last point as a last resort.
@@ -2139,13 +2139,13 @@ const pointDraggingUpdates = (
} => { } => {
const naiveDraggingPoints = new Map( const naiveDraggingPoints = new Map(
selectedPointsIndices.map((pointIndex) => { selectedPointsIndices.map((pointIndex) => {
// NOTE: Avoid stale point index issue potentially caused by elbow
// arrows unpredictably changing the number of points during dragging
const point = element.points[pointIndex] ?? element.points.at(-1);
return [ return [
pointIndex, pointIndex,
{ {
point: pointFrom<LocalPoint>( point: pointFrom<LocalPoint>(point[0] + deltaX, point[1] + deltaY),
element.points[pointIndex][0] + deltaX,
element.points[pointIndex][1] + deltaY,
),
isDragging: true, isDragging: true,
}, },
]; ];
+21 -3
View File
@@ -10408,20 +10408,38 @@ class App extends React.Component<AppProps, AppState> {
); );
let linearElementEditor = this.state.selectedLinearElement; let linearElementEditor = this.state.selectedLinearElement;
if (!linearElementEditor) {
if (
!linearElementEditor ||
linearElementEditor.elementId !== newElement.id
) {
linearElementEditor = new LinearElementEditor( linearElementEditor = new LinearElementEditor(
newElement, newElement,
this.scene.getNonDeletedElementsMap(), this.scene.getNonDeletedElementsMap(),
); );
}
const lastClickedPointOutOfBounds =
linearElementEditor &&
(linearElementEditor.initialState.lastClickedPoint < 0 ||
linearElementEditor.initialState.lastClickedPoint >=
points.length);
if (lastClickedPointOutOfBounds) {
console.warn(
"Last clicked point is out of bounds. Attempting to fix it.",
);
linearElementEditor = { linearElementEditor = {
...linearElementEditor, ...linearElementEditor,
selectedPointsIndices: [1], selectedPointsIndices: [points.length - 1],
initialState: { initialState: {
...linearElementEditor.initialState, ...linearElementEditor.initialState,
lastClickedPoint: 1, prevSelectedPointsIndices: null,
lastClickedPoint: points.length - 1,
}, },
hoverPointIndex: points.length - 1,
}; };
} }
this.setState({ this.setState({
newElement, newElement,
...LinearElementEditor.handlePointDragging( ...LinearElementEditor.handlePointDragging(