From 0a2b66a9f3e39938488b0a4f2cde06c17b28de93 Mon Sep 17 00:00:00 2001 From: jhotadhari Date: Mon, 29 Jun 2026 23:11:31 +0200 Subject: [PATCH] fix: prevent unhandled rejection when ref.current becomes null calculateRectFromRef has a while-loop guard that waits for the ref to become available, but the subsequent do-while loop calls getRectForRef on each iteration without re-checking. When the ref becomes null between async iterations (component unmount, re-render), getRectForRef rejects, causing an unhandled promise rejection. Two changes: - AdaptivePopover: add null-guard in do-while loop (mirrors while-loop pattern) so the loop bails if ref is lost between iterations - Utility: resolve with Rect(0,0,0,0) instead of rejecting, as a safety net for all callers of getRectForRef Closes #153 Co-Authored-By: Claude --- src/AdaptivePopover.tsx | 5 +++++ src/Utility.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/AdaptivePopover.tsx b/src/AdaptivePopover.tsx index 562312d..b754729 100644 --- a/src/AdaptivePopover.tsx +++ b/src/AdaptivePopover.tsx @@ -236,6 +236,11 @@ export default class AdaptivePopover extends Component i === undefined)) { this.debug('calculateRectFromRef - rect not found, all properties undefined'); diff --git a/src/Utility.ts b/src/Utility.ts index f1ca74c..faa8cad 100644 --- a/src/Utility.ts +++ b/src/Utility.ts @@ -15,7 +15,7 @@ export function getRectForRef(ref: RefType): Promise { resolve(new Rect(x, y, width, height)) ); } else { - reject(new Error('getRectForRef - current is not set')); + resolve(new Rect(0, 0, 0, 0)); } }); }