fix(core): Call onDestroy in production mode as well#40120
fix(core): Call onDestroy in production mode as well#40120mhevery wants to merge 1 commit intoangular:masterfrom
onDestroy in production mode as well#40120Conversation
AndrewKushnir
left a comment
There was a problem hiding this comment.
Thanks for the fix Misko! 👍
I have a couple more proposals that we can look into to avoid similar issues:
-
rename
getTViewCleanupandgetLCleanup(togetOrCreateTViewCleanupandgetOrCreateLViewCleanuprespectively). This should highlight the fact that calling these methods might cause side effects. -
in the
storeCleanupWithContextfunction itself, call freeze only whentView.cleanupis 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. |
AndrewKushnir
left a comment
There was a problem hiding this comment.
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
onDestroyofComponentRefwould only get called ifngDevModewas set to true. This was because in dev mode we would freezeTCleanupto verify that no more static cleanup would get added toTCleanuparray. This ensured thatTCleanupwas always present in dev mode. In production theTCleanupwould get created only when needed. The resulting cleanup code was incorrectly indented and would only run ifTCleanupwas 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