-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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(core): Call onDestroy
in production mode as well
#40120
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.
Thanks for the fix Misko! 👍
I have a couple more proposals that we can look into to avoid similar issues:
-
rename
getTViewCleanup
andgetLCleanup
(togetOrCreateTViewCleanup
andgetOrCreateLViewCleanup
respectively). This should highlight the fact that calling these methods might cause side effects. -
in the
storeCleanupWithContext
function itself, call freeze only whentView.cleanup
is not null, i.e.:
// If context is null that this is instance specific callback. These callbacks can only be
// inserted after template shared instances. For this reason in ngDevMode we freeze the TView.
if (ngDevMode && tView.cleanup !== null) {
Object.freeze(tView.cleanup);
}
What do you think?
d26bb53
to
e3c0cb3
Compare
DONE
Unfortunately, I can't do that. |
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 👍 (just one minor comment)
PR angular#39876 introduced an error where the `onDestroy` of `ComponentRef` would only get called if `ngDevMode` was set to true. This was because in dev mode we would freeze `TCleanup` to verify that no more static cleanup would get added to `TCleanup` array. This ensured that `TCleanup` was always present in dev mode. In production the `TCleanup` would get created only when needed. The resulting cleanup code was incorrectly indented and would only run if `TCleanup` was present causing this issue. Fix angular#40105
PR #39876 introduced an error where the `onDestroy` of `ComponentRef` would only get called if `ngDevMode` was set to true. This was because in dev mode we would freeze `TCleanup` to verify that no more static cleanup would get added to `TCleanup` array. This ensured that `TCleanup` was always present in dev mode. In production the `TCleanup` would get created only when needed. The resulting cleanup code was incorrectly indented and would only run if `TCleanup` was present causing this issue. Fix #40105 PR Close #40120
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. |
PR #39876 introduced an error where the
onDestroy
ofComponentRef
would only get called ifngDevMode
was set to true. This was because in dev mode we would freezeTCleanup
to verify that no more static cleanup would get added toTCleanup
array. This ensured thatTCleanup
was always present in dev mode. In production theTCleanup
would get created only when needed. The resulting cleanup code was incorrectly indented and would only run ifTCleanup
was present causing this issue.Fix #40105
## PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information