From 96cd25fcc1808f9f7fbb53f4f756358438cc8131 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Tue, 9 Nov 2021 05:20:57 -0800 Subject: [PATCH] Fix NPE in Interactive.tsx Summary: Fixed some incorrect non-null assertions that showed up in monitoring. Reviewed By: timur-valiev Differential Revision: D32278433 fbshipit-source-id: afe4913d8aef38c371461b4d0b817b2625153de1 --- desktop/flipper-plugin/src/ui/Interactive.tsx | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/desktop/flipper-plugin/src/ui/Interactive.tsx b/desktop/flipper-plugin/src/ui/Interactive.tsx index 7216d4cfc..508d2eefa 100644 --- a/desktop/flipper-plugin/src/ui/Interactive.tsx +++ b/desktop/flipper-plugin/src/ui/Interactive.tsx @@ -406,9 +406,12 @@ export class Interactive extends React.Component< calculateResize(event: MouseEvent) { const {resizingInitialCursor, resizingInitialRect, resizingSides} = this.state; + if (!resizingSides || !resizingInitialCursor) { + return; + } - const deltaLeft = resizingInitialCursor!.left - event.clientX; - const deltaTop = resizingInitialCursor!.top - event.clientY; + const deltaLeft = resizingInitialCursor.left - event.clientX; + const deltaTop = resizingInitialCursor.top - event.clientY; let newLeft = resizingInitialRect!.left; let newTop = resizingInitialRect!.top; @@ -417,19 +420,19 @@ export class Interactive extends React.Component< let newHeight = resizingInitialRect!.height; // right - if (resizingSides!.right === true) { + if (resizingSides.right === true) { newWidth -= deltaLeft; } // bottom - if (resizingSides!.bottom === true) { + if (resizingSides.bottom === true) { newHeight -= deltaTop; } const rect = this.getRect(); // left - if (resizingSides!.left === true) { + if (resizingSides.left === true) { newLeft -= deltaLeft; newWidth += deltaLeft; @@ -446,7 +449,7 @@ export class Interactive extends React.Component< } // top - if (resizingSides!.top === true) { + if (resizingSides.top === true) { newTop -= deltaTop; newHeight += deltaTop; @@ -465,23 +468,23 @@ export class Interactive extends React.Component< if (event.altKey) { const windows = this.getPossibleTargetWindows(rect); - if (resizingSides!.left === true) { + if (resizingSides.left === true) { const newLeft2 = maybeSnapLeft(rect, windows, newLeft); newWidth += newLeft - newLeft2; newLeft = newLeft2; } - if (resizingSides!.top === true) { + if (resizingSides.top === true) { const newTop2 = maybeSnapTop(rect, windows, newTop); newHeight += newTop - newTop2; newTop = newTop2; } - if (resizingSides!.bottom === true) { + if (resizingSides.bottom === true) { newHeight = maybeSnapTop(rect, windows, newTop + newHeight) - newTop; } - if (resizingSides!.right === true) { + if (resizingSides.right === true) { newWidth = maybeSnapLeft(rect, windows, newLeft + newWidth) - newLeft; } }