{{ message }}
fix(core): Call onDestroy in production mode as well#40120
Closed
mhevery wants to merge 1 commit intoangular:masterfrom
Closed
fix(core): Call onDestroy in production mode as well#40120mhevery wants to merge 1 commit intoangular:masterfrom
onDestroy in production mode as well#40120mhevery wants to merge 1 commit intoangular:masterfrom
Conversation
Contributor
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
Contributor
Author
AndrewKushnir
approved these changes
Dec 14, 2020
Contributor
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
Contributor
Author
josephperrott
pushed a commit
that referenced
this pull request
Dec 22, 2020
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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