-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Fix: Remove attach target on deactivation of widget from overlay portal controller #164439
base: master
Are you sure you want to change the base?
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
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.
Hi @rkishan516 thank you for sending a PR!
It looks like this is failing many tests, and lacks tests itself. Can you take a look?
Thanks!
ccc208a
to
a1b0390
Compare
@Piinks I have made required changes. |
} | ||
} | ||
|
||
@override | ||
void dispose() { | ||
assert(widget.controller._attachTarget == this); | ||
void deactivate() { |
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.
If the OverlayPortal
is reparented, the _attachTarget
has to be restored right? Also could you add a test for this?
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.
Sure
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.
I have pushed the required change.
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.
It should probably happen in activate
instead of didUpdateWidget
.
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.
Yaa, that will be correct. Let me do the change.
4c7cdd2
to
1781190
Compare
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.
Detaching the controller from the state when it's deactivated makes sense to me.
However this would create a new corner case: when the state is deactivated, we don't want the developer to call show
or hide
on the associated controller because the state the controller attaches to may not rebuild. I think that can happen if you cache the OverlayPortal and gives it a global key.
assert(widget.controller._attachTarget == this); | ||
void deactivate() { | ||
super.deactivate(); | ||
assert(widget.controller._attachTarget == null || widget.controller._attachTarget == this); |
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.
I think the assert here should be assert(widget.controller._attachTarget == this)
?
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.
Yes, that should be the case but when reattaching with global key, it was causing failures.
But i think since we are moving reattach in activate
method, this can be removed.
I will write a test for this and check. |
db30016
to
58584ed
Compare
I have added the test, we don't need to call |
It seems there's a leak in one of the new tests. Maybe one of the OverlayEntries were not disposed at the end of the test? |
I think setting
|
Element.debugIsActive I think this will not solve the issue because in release it will always reattach to newer element. |
23c1126
to
df3f365
Compare
Even after disposing overlay entries, its showing leak. |
df3f365
to
e3304ec
Compare
The issue won't happen in release builds. The crash is caused by an assert. |
The relevant error messages were:
|
Okay, then I will do the change in |
late OverlayEntry overlayEntry1, overlayEntry2; | ||
addTearDown(() { | ||
overlayEntry1.dispose(); | ||
return overlayEntry2.dispose(); |
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.
nit: remove the return
); | ||
|
||
// Move to second overlay | ||
setState(() { |
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.
I suspect when the StatefulBuilder
rebuilds, the builder callback will be called a second time, creating new OverlayEntries so in the test 4 OverlayEntries were created but only 2 were disposed.
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.
Yaa, I need to give GlobalKey to Overlay
widgets such that they also maintain themself until test is completed.
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.
Even after adding global key, tests are failing
e3304ec
to
d6c5f3d
Compare
d6c5f3d
to
cef835f
Compare
Fix: Remove attach target on deactivation of widget from overlay portal controller
fixes: #164376
Pre-launch Checklist
///
).