Skip to content

Commit

Permalink
Handle errors from DOM.getAllBoundingClientRects (#10361)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbenl authored Feb 26, 2024
1 parent b48b5d8 commit f8972ec
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 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,7 @@ export function NodePickerContextRoot({ children }: PropsWithChildren<{}>) {
}

// Start loading rects eagerly; we'll need them in the hover/click handlers
const boundingRectsPromise = boundingRectsCache.readAsync(replayClient, pauseId);
boundingRectsCache.prefetch(replayClient, pauseId);

const { limitToNodeIds, onSelected } = options;

Expand All @@ -162,10 +162,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 boundingRectsCache.readAsync(replayClient, pauseId);
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 f8972ec

Please sign in to comment.