Commit bb1bba0
sharing: Reset initialSharedData after sending the map to JS.
This resolves the 'Map already consumed' bug.
`Map already Consumed` is a fatal JS exception that occurs when react
bridge gives `ObjectAlreadyConsumedException`. This exception according
to the react-native documentation [1] at the time of writing this commit
is given when:
"caller attempts to modify or use a `WritableNativeArray` or
`WritableNativeMap` after it has already been added to a parent array or
map. This is unsafe since we reuse the native memory so the underlying
array/map is no longer valid."
One possible way to reproduce this issue is:
- revert changes made in this commit (comment out line
`initialSharedData = null` in `android/**/sharing/SharingModule.kt`)
- start the app using `tools/run-android`
- kill the app
- start another app and share text to zulip (It is important that
zulip starts using share intent, hence we do this step. It is also
important to share text, data with content doesn't leave the app in
recent apps view (discussed in next step), share playstore links as an
example.)
- cancle the share and quit zulip (use back presses if necessary), make
sure to "quit" the app and not "kill" the app.
- notice the app is still in the recent apps view (accessible by
long pressing home)
- start the app from recent apps.
- map already consumed should popup.
In this scenario it is assumed that when we backpress to quit zulip,
android system does not flush the entire memory of the app (so that it
can boot up faster, which is also noticable here). This also involves
the static variable `initialSharedIntent` we set when the app was
started previously using share intent.
But it seems that react native discovers that the data in
initialSharedIntent is reused and hence is unsafe to use thereby
giving us the exception and the bug.
The change introduced in this commit will fix any `map already consumed`
issue concerning `initialSharedIntent`, since we reset its value just
after its use. A more specific place to reset initialSharedData is
within `MainActivity.kt` inside condition that checks for
`FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY`. This will only resolve the steps
of reproduction discussed above, but the error may pop up somewhere
else.
[1] https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/bridge/ObjectAlreadyConsumedException.java
Commit message authored-by: Akash Dhiman <[email protected]>1 parent d99ad3a commit bb1bba0
File tree
2 files changed
+4
-3
lines changed- android/app/src/main/java/com/zulipmobile/sharing
- src/sharing
2 files changed
+4
-3
lines changedLines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
0 commit comments