fix: prevent unhandled rejection when ref.current becomes null between async iterations#203
Open
jhotadhari wants to merge 1 commit into
Open
fix: prevent unhandled rejection when ref.current becomes null between async iterations#203jhotadhari wants to merge 1 commit into
jhotadhari wants to merge 1 commit into
Conversation
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 SteffeyDev#153 Co-Authored-By: Claude <noreply@anthropic.com>
Collaborator
|
It seems to me like it kinda makes sense for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
calculateRectFromRefhas awhileloop guard that waits forfromRef.currentto become truthy, but the subsequentdo...whileloop callsgetRectForRef(fromRef)on each iteration without re-checking. When the ref becomesnullbetween async iterations (component unmount, rapid open/close, re-render),getRectForRefrejects withError: getRectForRef - current is not set. This rejection is never caught, resulting in an unhandled promise rejection.Fixes #153
Changes
1. AdaptivePopover.tsx — add null-guard in do-while loop
Mirrors the existing
whileloop pattern — if the ref is lost between async iterations, bail gracefully:2. Utility.ts — resolve instead of reject
Changed
getRectForRefto resolve withRect(0, 0, 0, 0)instead of rejecting. This acts as a safety net for all callers (BasePopover,JSModalPopover, etc.) that use.then()without error handlers. The primary fix is #1 above; this is a belt-and-suspenders backup.Verification
whileloop incalculateRectFromRefalready uses the same guard pattern — this fix extends it to thedo...whileloop where it was missingcalculateRectFromRefalready handles all-undefinedrect properties (line 240-243), so the function is designed to tolerate missing measurements — the reject was preventing that graceful path from being reachable🤖 Generated with Claude Code