Skip to content

Commit

Permalink
Handle errors from DOM.getAllBoundingClientRects
Browse files Browse the repository at this point in the history
  • Loading branch information
hbenl committed Feb 26, 2024
1 parent 3c39fb5 commit 7574155
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/ui/components/NodePickerContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectId, PauseId } from "@replayio/protocol";
import { NodeBounds, ObjectId, PauseId } from "@replayio/protocol";
import {
PropsWithChildren,
createContext,
Expand Down Expand Up @@ -153,7 +153,16 @@ export function NodePickerContextRoot({ children }: PropsWithChildren<{}>) {
}

// Start loading rects eagerly; we'll need them in the hover/click handlers
const boundingRectsPromise = boundingRectsCache.readAsync(replayClient, pauseId);
let boundingRectsPromise: PromiseLike<NodeBounds[]> | NodeBounds[] | undefined;
try {
boundingRectsPromise = boundingRectsCache.readAsync(replayClient, pauseId);
} catch {
setState({
status: "error",
options,
});
return;
}

const { limitToNodeIds, onSelected } = options;

Expand All @@ -162,10 +171,18 @@ export function NodePickerContextRoot({ children }: PropsWithChildren<{}>) {
if (position != null) {
const { x, y } = position;

const boundingRects = await boundingRectsPromise;
const nodeBounds = getMouseTarget(boundingRects, x, y, limitToNodeIds);

return nodeBounds?.node ?? null;
try {
const boundingRects = await boundingRectsPromise!;
const nodeBounds = getMouseTarget(boundingRects, x, y, limitToNodeIds);

return nodeBounds?.node ?? null;
} catch {
setState({
status: "error",
options,
});
return null;
}
}

return null;
Expand Down

0 comments on commit 7574155

Please sign in to comment.