-
-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Slow screen opening after react-native update #448
Comments
Maybe a long shot but, do you by any chance have reduce motion enabled on the device/simulator? |
I see this as-well something like a 500ms delay on rendering whatever is inside safe view |
There's not really anything to go off here. If you manage to make a minimal reproduction - or better yet, find the actual issue - let us know. |
@jacobp100 |
@jacobp100 @17Amir17 While I was preparing this project I found a problem (check the screenshot): |
Right so is it a problem with this library or another? |
I have this issue with BottomSheetModal. I created https://github.com/17Amir17/SafeAreaContext to reproduce. From the comments in my codebase the reason we have a SafeArea in the modal is because of a rare cutoff of some android device. Screen.Recording.2023-10-28.at.20.37.46.movI'm not really sure how to debug this further but would love to help @jacobp100 if you have any directions |
@jacobp100 I'm seeing this issue too. It seems like it's because is we are hitting this timeout in SafeAreaView and that freezes the UI for 500ms react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt Lines 97 to 99 in b086b0e
I debugged a little bit and it seems like the code in react-native-safe-area-context/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt Lines 77 to 95 in b086b0e
I'm not sure what the best fix here is though. |
Good catch on that. If you're able to get some flame graph and figure out what exactly is blocking the main thread, that would be helpful. Is this something that shows up only in development - or production too? |
If you increase the max time nanos to something much longer (say 10s), does it finish before? Or do we have a deadlock? |
Yea, I just upped it to 10s and the whole app freezes for those 10 seconds it's waiting. This is what I was logging: 2023-11-01 14:22:29.130 runOnNativeModulesQueueThread 0
2023-11-01 14:22:29.130 main thread 0
2023-11-01 14:22:29.130 awaitNanos 0
2023-11-01 14:22:39.131 awaitNanos 1
2023-11-01 14:22:39.131 main thread 1
2023-11-01 14:22:39.131 Timed out waiting for layout.
2023-11-01 14:22:39.140 native thread 0
2023-11-01 14:22:39.140 native thread 1 So yea, it looks like something isn't letting the code on the native thread run until the main thread times out waiting. |
What’s your setup? Version of react native? Are you using fabric? Also could you check the value of |
We are on react-native 0.72.5. No we are not using fabric. I printed the value of |
Try adding a |
Here's what the stacktrace looks like in
|
Do you have a few traces before and after that? |
I'm not sure what you mean? Before and after it's inside |
I think some other functions - presumably outside of this library - will be calling |
Hi. I got the same issue on iOS. Temporary fixed it using |
facing the same problem after updating to RN 0.72+ including 0.73-alpha(s).. this is in combination with |
Experiencing the same issue after upgrading to RN 0.72 (from 0.68). @jacobp100 is there anything I can do to help you debug this? |
Somebody needs to look into it. There’s only two people that actively maintain this, and I don’t think either of us will investigate this - so if you want this fixed, do take a look for yourself. We are of course on hand to answer any questions etc. |
So what I figured out is that
scheduled on the native module queue is called after the lock times out. I would assume that this means that |
@jacobp100 I found the offending code 🥳 In
before
This runs
on the native modules thread. This in turn calls
Since rn 72 (facebook/react-native@bc766ec) we have
guarding the entry and this in turn waits for the main thread where we are already waiting for this thread. Deadlock. |
🎉 do you know what the fix is? |
Sadly no idea yet. The problem is that |
My experience with core dev is they’re too busy to get back to you. If you find a work around though, we here are good at merging and releasing PRs. It sounds like you’re really close! |
@feiyin0719 Is there any way we can support testing this change to get it merged back? It looks like this issue affects several apps. Thanks in advance |
We have the same problem, we are trying to apply the patch from discord/react-native@5c0d4da to see if it fixes our issue. |
We also have this issue in our app. When applying the patch from discord/react-native@5c0d4da and building React Native from source, it fixes the issue. |
thanks for confirming it fixes the issue @vanHoi ! I'll try to get this reviewed & merged into react-native (need to figure out the CLA situation tho) |
Thanks @yayvery for the solution! Just to clarify, we have applied this patch to React Native 0.73.6, the issues still persists there. |
I can also confirm the patch works on 0.72.12. |
@yayvery @EvertEt @vanHoi hey all, I have a quick question, is this fix incorporated into the React Native 0.72.12 version? If not, is there a plan to incorporate this fix into the next 0.72 patch version? Thanks a lot in advance! I think this issue (#219 (comment)) is also related to one discussed above. |
@jackylu0124 the fix has not been merged in react native yet, and thus also not yet backported to 0.72. |
@EvertEt I see, thank you for the clarification! Is there a plan/or a task already made for merging the fix into React Native and backporting it to 0.72? Or are we not at that step yet? |
@jackylu0124, @yayvery was going to look into this but not sure what the timeline would be. Feel free to take a look. |
@feiyin0719 @yayvery Since this is quite a big issue for our project, I've gone ahead and opened a PR facebook/react-native#43643 describing the issue as best as I could. Comments and possible improvements would be much appreciated. |
Thanks for owning the PR @EvertEt ! |
Summary: In th3rdwave/react-native-safe-area-context#448 it was noticed that from 0.72 (bc766ec #35889) it was possible to get a deadlock in dispatchViewUpdates. ([More details](th3rdwave/react-native-safe-area-context#448 (comment))) This deadlock resulted in a laggy experience for all users using https://github.com/th3rdwave/react-native-safe-area-context/ on Android. To avoid this problem, the author of the original fix [proposed](th3rdwave/react-native-safe-area-context#448 (comment)) this solution which was tested by Discord and many other users. It would be great to have this backported to 0.72 and 0.73 because of the large userbase using react-native-safe-area-context since it's recommended by expo and react-navigation. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID] [FIXED] - Fixed possible deadlock in dispatchViewUpdates For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID] [FIXED] - Fixed possible deadlock in dispatchViewUpdates Pull Request resolved: #43643 Test Plan: The original memory leak remains fixed, and can be verified in https://github.com/feiyin0719/RNMemoryLeakAndroid. To verify the deadlock is gone, every app using https://github.com/th3rdwave/react-native-safe-area-context will work smoothly and not log any excessive `Timed out waiting for layout` (https://github.com/17Amir17/SafeAreaContext) Reviewed By: arushikesarwani94 Differential Revision: D55339059 Pulled By: zeyap fbshipit-source-id: c067997364fbec734510ce99b9994e89d044384a
this does not fix the issue for me. This is my patch file. Did I miss something? I'm using
|
@ziga-hvalec Make sure to also build React Native from the source: https://reactnative.dev/contributing/how-to-build-from-source |
Summary: In th3rdwave/react-native-safe-area-context#448 it was noticed that from 0.72 (bc766ec #35889) it was possible to get a deadlock in dispatchViewUpdates. ([More details](th3rdwave/react-native-safe-area-context#448 (comment))) This deadlock resulted in a laggy experience for all users using https://github.com/th3rdwave/react-native-safe-area-context/ on Android. To avoid this problem, the author of the original fix [proposed](th3rdwave/react-native-safe-area-context#448 (comment)) this solution which was tested by Discord and many other users. It would be great to have this backported to 0.72 and 0.73 because of the large userbase using react-native-safe-area-context since it's recommended by expo and react-navigation. <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID] [FIXED] - Fixed possible deadlock in dispatchViewUpdates For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID] [FIXED] - Fixed possible deadlock in dispatchViewUpdates Pull Request resolved: #43643 Test Plan: The original memory leak remains fixed, and can be verified in https://github.com/feiyin0719/RNMemoryLeakAndroid. To verify the deadlock is gone, every app using https://github.com/th3rdwave/react-native-safe-area-context will work smoothly and not log any excessive `Timed out waiting for layout` (https://github.com/17Amir17/SafeAreaContext) Reviewed By: arushikesarwani94 Differential Revision: D55339059 Pulled By: zeyap fbshipit-source-id: c067997364fbec734510ce99b9994e89d044384a
Summary: In th3rdwave/react-native-safe-area-context#448 it was noticed that from 0.72 (bc766ec #35889) it was possible to get a deadlock in dispatchViewUpdates. ([More details](th3rdwave/react-native-safe-area-context#448 (comment))) This deadlock resulted in a laggy experience for all users using https://github.com/th3rdwave/react-native-safe-area-context/ on Android. To avoid this problem, the author of the original fix [proposed](th3rdwave/react-native-safe-area-context#448 (comment)) this solution which was tested by Discord and many other users. It would be great to have this backported to 0.72 and 0.73 because of the large userbase using react-native-safe-area-context since it's recommended by expo and react-navigation. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID] [FIXED] - Fixed possible deadlock in dispatchViewUpdates For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID] [FIXED] - Fixed possible deadlock in dispatchViewUpdates Pull Request resolved: #43643 Test Plan: The original memory leak remains fixed, and can be verified in https://github.com/feiyin0719/RNMemoryLeakAndroid. To verify the deadlock is gone, every app using https://github.com/th3rdwave/react-native-safe-area-context will work smoothly and not log any excessive `Timed out waiting for layout` (https://github.com/17Amir17/SafeAreaContext) Reviewed By: arushikesarwani94 Differential Revision: D55339059 Pulled By: zeyap fbshipit-source-id: c067997364fbec734510ce99b9994e89d044384a
Summary: In th3rdwave/react-native-safe-area-context#448 it was noticed that from 0.72 (bc766ec #35889) it was possible to get a deadlock in dispatchViewUpdates. ([More details](th3rdwave/react-native-safe-area-context#448 (comment))) This deadlock resulted in a laggy experience for all users using https://github.com/th3rdwave/react-native-safe-area-context/ on Android. To avoid this problem, the author of the original fix [proposed](th3rdwave/react-native-safe-area-context#448 (comment)) this solution which was tested by Discord and many other users. It would be great to have this backported to 0.72 and 0.73 because of the large userbase using react-native-safe-area-context since it's recommended by expo and react-navigation. <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID] [FIXED] - Fixed possible deadlock in dispatchViewUpdates For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID] [FIXED] - Fixed possible deadlock in dispatchViewUpdates Pull Request resolved: #43643 Test Plan: The original memory leak remains fixed, and can be verified in https://github.com/feiyin0719/RNMemoryLeakAndroid. To verify the deadlock is gone, every app using https://github.com/th3rdwave/react-native-safe-area-context will work smoothly and not log any excessive `Timed out waiting for layout` (https://github.com/17Amir17/SafeAreaContext) Reviewed By: arushikesarwani94 Differential Revision: D55339059 Pulled By: zeyap fbshipit-source-id: c067997364fbec734510ce99b9994e89d044384a
So do we know which React Native versions (if any) include the fix? |
Should be 0.73.7. |
Amazing..thanks for confirming |
A fix for this has been merged in v0.72.13, v0.73.7 and v0.74.0-rc8. |
Summary: In th3rdwave/react-native-safe-area-context#448 it was noticed that from 0.72 (facebook/react-native@bc766ec facebook/react-native#35889) it was possible to get a deadlock in dispatchViewUpdates. ([More details](th3rdwave/react-native-safe-area-context#448 (comment))) This deadlock resulted in a laggy experience for all users using https://github.com/th3rdwave/react-native-safe-area-context/ on Android. To avoid this problem, the author of the original fix [proposed](th3rdwave/react-native-safe-area-context#448 (comment)) this solution which was tested by Discord and many other users. It would be great to have this backported to 0.72 and 0.73 because of the large userbase using react-native-safe-area-context since it's recommended by expo and react-navigation. <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID] [FIXED] - Fixed possible deadlock in dispatchViewUpdates For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID] [FIXED] - Fixed possible deadlock in dispatchViewUpdates Pull Request resolved: facebook/react-native#43643 Test Plan: The original memory leak remains fixed, and can be verified in https://github.com/feiyin0719/RNMemoryLeakAndroid. To verify the deadlock is gone, every app using https://github.com/th3rdwave/react-native-safe-area-context will work smoothly and not log any excessive `Timed out waiting for layout` (https://github.com/17Amir17/SafeAreaContext) Reviewed By: arushikesarwani94 Differential Revision: D55339059 Pulled By: zeyap fbshipit-source-id: c067997364fbec734510ce99b9994e89d044384a
We are still getting reports of ANR issues after releasing this patch (React Native 0.72.13). Or is this perhaps a different issue?
|
Temporary fixed it using |
Hey, everybody!
After updating react-native (and all libraries) from version 0.70.11 to 0.72.6, I got a problem that screens with SafeAreaView open slowly and without animation.
I couldn't find absolutely no information on how to fix it.
In the video the first screen "Security" is in SafeAreaView, the second screen "Your rank" is just View.
https://github.com/th3rdwave/react-native-safe-area-context/assets/93343100/45623a6f-a038-4372-837a-abfa7466b8e8
My App component is wrapped with (I tried with and without the initialMetrics parameter).
My package.json
{ "react": "18.2.0",
"react-native": "0.72.6",
"react-native-safe-area-context": "4.7.4",
"react-native-screens": "3.27.0",
"react-native-reanimated": "3.5.4",
"@react-navigation/bottom-tabs": "6.5.11",
"@react-navigation/native": "6.1.9",
"@react-navigation/stack": "6.3.20",
The text was updated successfully, but these errors were encountered: