Skip to content

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Oct 9, 2025

📜 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 our KCTextInputCompositeDelegate 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

  • added error handler via overriding 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:

  override func forwardingTarget(for aSelector: Selector!) -> Any? {
    return super.forwardingTarget(for: aSelector)
  }

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):

Before After
Screen.Recording.2025-10-12.at.19.49.44.mov
Screen.Recording.2025-10-12.at.19.48.16.mov

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

Copy link
Contributor

github-actions bot commented Oct 9, 2025

📊 Package size report

Current size Target Size Difference
224050 bytes 223889 bytes 161 bytes 📈

@kirillzyusko kirillzyusko force-pushed the fix/crash-when-unrecognized-selector-sent branch from afb255a to b2973d3 Compare October 12, 2025 10:15
@kirillzyusko kirillzyusko marked this pull request as ready for review October 12, 2025 17:50
@kirillzyusko kirillzyusko merged commit 4ab7be0 into main Oct 13, 2025
15 checks passed
@kirillzyusko kirillzyusko deleted the fix/crash-when-unrecognized-selector-sent branch October 13, 2025 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎯 crash Library triggers a crash of the app 🍎 iOS iOS specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"react_native_keyboard_controller.KCTextInputCompositeDelegate scrollViewDidScroll: unrecognized selector sent " crash on iOS

1 participant