fix(android): prevent ConcurrentModificationException from deep linking effect - #702
Open
sentry[bot] wants to merge 1 commit into
Open
fix(android): prevent ConcurrentModificationException from deep linking effect#702sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
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.
This PR addresses a
ConcurrentModificationExceptionoccurring on Android, specifically inIntentModule.onHostResume.Problem:
The original
useEffectinuseDeepLinking.tshadstoreReadyas a dependency. WhenstoreReadytransitioned fromfalsetotrue, the effect would re-run, leading to multiple, concurrent calls toLinking.getInitialURL(). On Android, this caused React Native'sIntentModuleto attempt to modify its internalArrayListof URL/intent listeners while iterating over it, resulting in aConcurrentModificationException.Solution:
useEffect: The singleuseEffecthas been split into two distinct effects.useEffectwith an empty dependency array ([]) now handles the initialLinking.getInitialURL()call and registers theLinking.addEventListener. The initial URL is stored in auseRefto be processed later.useEffectnow depends only onstoreReady. It processes the initial URL (read from theuseRef) and handlesShortcuts.getInitialShortcut()andShortcutsEmitter.addListeneronly whenstoreReadyistrue.This change ensures that
Linking.getInitialURL()is called only once during the component's lifecycle, eliminating the race condition and preventing theConcurrentModificationException.Fixes BETTER-RAIL-3S
This PR was automatically generated by Sentry. You can adjust this setting at any time.