fix RCTImageManager crash#2
Merged
SzymczakJ merged 3 commits intoJun 18, 2026
Merged
Conversation
Backport of upstream PR react#55135 ("fix rctimage observer crash when unloading with events in-flight"). Convert ImageResponseObserverCoordinator's observers from raw pointers to std::shared_ptr<const ImageResponseObserver> so an observer cannot dangle while an image event is in flight (the documented react#55135 crash in nativeImageResponseProgress). RCTImageComponentView now holds its proxy as a shared_ptr and passes it directly (a final ImageResponseObserver subclass converts implicitly to shared_ptr<const ImageResponseObserver>). Also fix an over-removal bug in removeObserver: erase(position, end()) removed every observer from the match onward, which could prematurely empty observers_ and trigger an unwanted cancelRequest_(). Use erase(position) to remove only the single matched observer, matching the add/remove balance the comment describes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…crash `loaderRequest.cancellationBlock` can be nil (a loader that returns no cancellation block, or a request that has already completed). The captured `sharedCancelationFunction` invoked it unconditionally, so when a cancel is triggered during view recycling (RCTImageComponentView::prepareForRecycle → _setStateAndResubscribeImageResponseObserver → removeObserver → cancelRequest_()), a nil block was called. Invoking a nil Objective-C block dereferences `block->invoke` at offset 0x10 → EXC_BAD_ACCESS / KERN_INVALID_ADDRESS at 0x10. Nil-guard the captured block so the cancel is a no-op when there is nothing to cancel. This is Discord-specific hardening on top of the upstream observer-lifetime fix (react#55135, ported in the preceding commit) and is the likely direct cause of the reported crash. Fixes DISCORD-IOS-M4EH Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
WoLewicki
approved these changes
Jun 17, 2026
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.
Possibly fixes: https://discord.sentry.io/issues/7451653844/?project=230973&query=&referrer=issue-stream&sort=freq - Asana
majority of changes are taken from react#55135 which fixes similar bug upstream. Rest is additional hardening in RCTImageManager to fix all the edge cases.