-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix avoid context access after widget disposal #4112
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request aims to fix potential crashes by avoiding BuildContext access after asynchronous operations, which is a great improvement for the app's stability. The changes correctly apply the recommended pattern of checking mounted after await and extracting provider lookups before await.
However, I've found a couple of places within the modified code block in initState where this pattern was not fully applied, leaving potential use_build_context_synchronously violations. My review comments point these out with suggestions for a complete fix to ensure the initState logic is fully robust against this class of errors.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly addresses potential crashes by preventing the use of BuildContext across asynchronous gaps. The changes involve moving provider lookups before await calls and adding mounted checks, which is a solid improvement for the app's stability. I've identified one critical issue related to deep link handling that could lead to a crash and have provided a suggestion to resolve it.
|
Guarding with mounted every time is not the way. Tell me exactly what the cause is at the line of code level. |
|
Hey @krushnarout 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! 💜 |
4971247 to
18da5c5
Compare
I have removed the extra mounted checks. omi/app/lib/core/app_shell.dart Line 378 in a3678f8
in this line the crash happened, the provider was accessed after an async boundary inside a post frame callback. I moved provider reads before the async call and did the same for the other providers |
omi/app/lib/core/app_shell.dart
Lines 378 to 382 in a3678f8
here it tried to use the widget after it was disposed and moved the provider lookup before the async call and added a mounted check