fix: crash when unrecognized selector sent #1153
Merged
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.
📜 Description
Fixed a crash like
[react_native_keyboard_controller.KCTextInputCompositeDelegate scrollViewDidScroll:]: unrecognized selector sent to instance 0x110bbf400
.💡 Motivation and Context
My gut feeling is that during
responds
we have a delegate and we recognize the event. But when it comes to actual forwarding our delegate is unset, so we can't forward it to delegate, but we have to forward it to somehwere, so we send it to ourKCTextInputCompositeDelegate
delegate, our delegate can't handle it and we get a crash 🤯As written in original implementation the issue seems to happen after navigation. And it actually makes sense - during navigation you may unmount a component, and unset delegate (or component may go into re-cycling pool and unset delegate).
Anyway, we don't have a reproduction example and it's only my guess what can go wrong based on stacktrace and additional information provided. If my assumption is correct, then the best thing we can do is to ignore that crash (ideally we shouldn't be able to say that our delegate can handle a particular request, but it looks like it's impossible to implement, because it's timing issue).
So in this PR I simply added a method for handling the exception and added a logger (based on logger information we can debug the issue further).
Closes #1119
📢 Changelog
iOS
doesNotRecognizeSelector
with proper logging;🤔 How Has This Been Tested?
Since there is no way to test it in example app I re-worked code so that
forwardingTarget
always throws an exception:My delegate doesn't implement many methods, so if you start to type in multiline input you'll get a crash almost instantly with the same stacktrace (that it happened in
forwardingTarget
).With this PR changes you'll not get a crash.
📸 Screenshots (if appropriate):
Screen.Recording.2025-10-12.at.19.49.44.mov
Screen.Recording.2025-10-12.at.19.48.16.mov
📝 Checklist