You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working on #3800 I've noticed frequent crashes on iOS. I'll explain this using the demo from the test code, basically two screens, second screen has a RectButton.
Navigate to second screen
Go back
Navigate to the second screen again
App crashes
Sometime it crashes immediately on startup.
Why is it happening?
Native handlers are handled differently compared to others. The main problem was that we tried to attach handler that was previously dropped, but NativeDetector has no information that this happened. The flow here looks as follows:
We navigate to screen with button
addSubview is called - at this point it won't attach anything as _nativeHandlers is empty
updateProps is called - handlers are attached
We navigate back to first screen
Handler is dropped
We navigate again to second screen
addSubview is called - it tries to attach handler that was dropped, therefore app crashes
Solution
To fix this issue, we clear _nativeHandlers in prepareForRecycle method.
Test plan
I've tested it on my branch with components re-written to new API, using the following code in EmptyExample:
Hmm, I see that we already disabled recycling only on macOS. Disabling that would be ok, but a better, and correct, thing to do would be to reset all local fields inside prepareForRecycle. It can stay disabled on macOS, I'm sure there was a reason why our components do that but don't recall it.
For now I've cleared only _nativeHandlers, as other sets seem to be correctly cleared at this point. WDYT?
Can everything be reset? I shouldn't impact performance in a meaningful way and will likely prevent some nasty bugs in the future, where that assumption may no longer hold.
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
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.
What is happening
While working on #3800 I've noticed frequent crashes on
iOS. I'll explain this using the demo from the test code, basically two screens, second screen has aRectButton.Sometime it crashes immediately on startup.
Why is it happening?
Nativehandlers are handled differently compared to others. The main problem was that we tried to attach handler that was previously dropped, butNativeDetectorhas no information that this happened. The flow here looks as follows:addSubviewis called - at this point it won't attach anything as_nativeHandlersis emptyupdatePropsis called - handlers are attachedaddSubviewis called - it tries to attach handler that was dropped, therefore app crashesSolution
To fix this issue, we clear
_nativeHandlersinprepareForRecyclemethod.Test plan
I've tested it on my branch with components re-written to new API, using the following code in EmptyExample: