Repository navigation
fix: read abort reasons from captured signals - #1994
Conversation
🦋 Changeset detectedLatest commit: fcfb7a5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 48 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
trevor-cortex
left a comment
There was a problem hiding this comment.
Summary
Works around a React Native 0.86 quirk where the abort event delivered to a listener can have target === null, which made (e.target as AbortSignal).reason throw. Both call sites now read .reason from the signal already captured in scope (signal in the RPC request coalescer, callerAbortSignal in the timeout confirmation strategy), and regression tests simulate the null-target event in both packages.
Why this is correct
In both cases the listener is registered directly on the same signal object that's now being read. Per spec, e.target for an abort event is that signal, so signal.reason is semantically identical to the old expression in conforming environments — and it keeps working where the event implementation fails to set target. Dropping the now-unused e parameter is the right cleanup, and the as AbortSignal casts go away as a bonus.
The tests take the only realistic route to reproduce this in Node: spy out addEventListener, capture the handler, and invoke it manually with a synthetic Event('abort') whose target is asserted to be null before the handler runs. Aborting the controller first ensures signal.reason is populated, mirroring the real-world sequence. Slightly implementation-coupled, but appropriate here.
Changeset with patch bumps for @solana/rpc and @solana/transaction-confirmation matches the scope of the fix.
Notes for other reviewers
- It may be worth a quick repo-wide grep for other
abortlisteners readinge.target(e.g. in the subscriptions or WebSocket packages) so the same RN issue doesn't resurface elsewhere. This PR fixes the two sites named in the linked issue. - No behavioral change for platforms with conforming
AbortSignalimplementations — this is purely a defensive source change.
LGTM — would approve, but I don't have approval rights on this repo.
BundleMonUnchanged files (150)
Total files change -40B -0.01% Final result: ✅ View report in BundleMon website ➡️ |
|
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |
Problem
In React Native 0.86, the abort event passed to the RPC coalescer can have
target === null. Readingevent.target.reasonthen throws:TypeError: Cannot read property 'reason' of nullI ran into this while testing Solana transaction confirmation in Trezor Suite: trezor/trezor-suite#30691
The timeout confirmation code used the same pattern.
Summary of Changes
Use the abort signal already in scope instead of reading it from the event. Added regression tests for both places.
I ran the node and browser tests, typecheck, lint, and Prettier for both affected packages.