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(forms): more precise control cleanup #39623
Conversation
2d1be6a
to
bd54312
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.
Lgtm - a few nits. I assume that the changes to the circular deps are just due to reordering of the imports rather than any substantial differences?
Currently when an instance of the `FormControlName` directive is destroyed, the Forms package invokes the `cleanUpControl` to clear all directive-specific logic (such as validators, onChange handlers, etc) from a bound control. The logic of the `cleanUpControl` function should revert all setup performed by the `setUpControl` function. However the `cleanUpControl` is too aggressive and removes all callbacks related to the onChange and disabled state handling. This is causing problems when a form control is bound to multiple FormControlName` directives, causing other instances of that directive to stop working correctly when the first one is destroyed. This commit updates the cleanup logic to only remove callbacks added while setting up a control for a given directive instance. The fix is needed to allow adding `cleanUpControl` function to other places where cleanup is needed (missing this function calls in some other places causes memory leak issues).
bd54312
to
6e1f5b9
Compare
Thanks for review @petebacondarwin, great feedback! I've applied the necessary changes, please have a look when you get a sec.
Yeah, there are no substantial differences. I can do some cleanup by moving things around once this change (and the followup PR) lands. (Note to self: I've also started a new presubmit + global presubmit) |
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.
LGTM - nice work @AndrewKushnir!
Thanks for the review @petebacondarwin 👍 Global presubmit went well (no regressions), so I'm adding this PR to the merge queue. Thank you. |
Currently when an instance of the `FormControlName` directive is destroyed, the Forms package invokes the `cleanUpControl` to clear all directive-specific logic (such as validators, onChange handlers, etc) from a bound control. The logic of the `cleanUpControl` function should revert all setup performed by the `setUpControl` function. However the `cleanUpControl` is too aggressive and removes all callbacks related to the onChange and disabled state handling. This is causing problems when a form control is bound to multiple FormControlName` directives, causing other instances of that directive to stop working correctly when the first one is destroyed. This commit updates the cleanup logic to only remove callbacks added while setting up a control for a given directive instance. The fix is needed to allow adding `cleanUpControl` function to other places where cleanup is needed (missing this function calls in some other places causes memory leak issues). PR Close #39623
@AndrewKushnir is this fixing #20007 by any chance 🙏 ? |
@maxime1992 thanks for the question. No, this PR would not help with memory management, but it's a prerequisite for #39235, which should address the memory leak issue caused by the |
That. is. awesome. Thank you so much for looking into this 🙏 🎉 |
@maxime1992 JFYI I came across another issue while testing #39235 with the |
Currently when an instance of the `FormControlName` directive is destroyed, the Forms package invokes the `cleanUpControl` to clear all directive-specific logic (such as validators, onChange handlers, etc) from a bound control. The logic of the `cleanUpControl` function should revert all setup performed by the `setUpControl` function. However the `cleanUpControl` is too aggressive and removes all callbacks related to the onChange and disabled state handling. This is causing problems when a form control is bound to multiple FormControlName` directives, causing other instances of that directive to stop working correctly when the first one is destroyed. This commit updates the cleanup logic to only remove callbacks added while setting up a control for a given directive instance. The fix is needed to allow adding `cleanUpControl` function to other places where cleanup is needed (missing this function calls in some other places causes memory leak issues). PR Close angular#39623
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Currently when an instance of the
FormControlName
directive is destroyed, the Forms package invokesthe
cleanUpControl
to clear all directive-specific logic (such as validators, onChange handlers,etc) from a bound control. The logic of the
cleanUpControl
function should revert all setupperformed by the
setUpControl
function. However thecleanUpControl
is too aggressive and removesall callbacks related to the onChange and disabled state handling. This is causing problems when
a form control is bound to multiple FormControlName` directives, causing other instances of that
directive to stop working correctly when the first one is destroyed.
This commit updates the cleanup logic to only remove callbacks added while setting up a control
for a given directive instance.
The fix is needed to allow adding
cleanUpControl
function to other places where cleanup is needed(missing this function calls in some other places causes memory leak issues).
PR Type
What kind of change does this PR introduce?
Does this PR introduce a breaking change?