Repository navigation
[5.X branch only] fix(common): don't recreate view when context shape doesn't change - #18277
Conversation
There was a problem hiding this comment.
ctxChange: SimpleChange is not correct (might be undefined)
There was a problem hiding this comment.
couldn't ctxChange be undefined here ?
There was a problem hiding this comment.
Nope, since the only way to get into this case would be to also change the templateRef. But this, in turn, would mean that we need to recreate view so wouldn't get into the else branch here.
In any case I've added a new test, just to be safe in the future (for example if we decide another @Input to the NgTemplateOutlet).
There was a problem hiding this comment.
Could you please re-structure the code to improve clarity ?
- add comments,
- move
ctxChange.isFirstChange()out of_hasContextShapeChangedso that the method actually does what it says (alternative is to rename the methods & add comments).
d5f1e98 to
f0c578e
Compare
There was a problem hiding this comment.
null should be undefined, right ?
f0c578e to
14713de
Compare
|
@vicb added comments, split code into smaller functions and simplified logic. Hopefully it is easier to follow now. PTAL |
|
Change looks good but definitely a change in behavior. Should we merge in 4.x ? |
Problem description: when using ngTemplateOutlet with context as an object literal in a template and binding to the context's property the embedded view would get re-created even if context object remains essentially the same (the same shape, just update to one properties). This happens since currently change detection will re-create object references when an object literal is used and one of its properties gets updated through a binding. Solution: this commit changes ngTemplateOutlet logic so we take contex't object shape into account before deciding if we should re-create view or just update existing context. Fixes angular#13407
14713de to
2871389
Compare
…ngular#18277) Problem description: when using ngTemplateOutlet with context as an object literal in a template and binding to the context's property the embedded view would get re-created even if context object remains essentially the same (the same shape, just update to one properties). This happens since currently change detection will re-create object references when an object literal is used and one of its properties gets updated through a binding. Solution: this commit changes ngTemplateOutlet logic so we take context object shape into account before deciding if we should re-create view or just update existing context. Fixes angular#13407
…ngular#18277) Problem description: when using ngTemplateOutlet with context as an object literal in a template and binding to the context's property the embedded view would get re-created even if context object remains essentially the same (the same shape, just update to one properties). This happens since currently change detection will re-create object references when an object literal is used and one of its properties gets updated through a binding. Solution: this commit changes ngTemplateOutlet logic so we take context object shape into account before deciding if we should re-create view or just update existing context. Fixes angular#13407
…ngular#18277) Problem description: when using ngTemplateOutlet with context as an object literal in a template and binding to the context's property the embedded view would get re-created even if context object remains essentially the same (the same shape, just update to one properties). This happens since currently change detection will re-create object references when an object literal is used and one of its properties gets updated through a binding. Solution: this commit changes ngTemplateOutlet logic so we take context object shape into account before deciding if we should re-create view or just update existing context. Fixes angular#13407
|
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. |
Fixes #13407
Problem description
When using
ngTemplateOutletwith context as an object literal in a template and binding to the context's property the embedded view would get re-created even if context object remains essentially the same (the same shape, just update to one properties).This happens since currently change detection will re-create object references when an object literal is used and one of its properties gets updated through a binding.
Solution proposal
This PR changes
ngTemplateOutletlogic so we take contex't object shape into account before deciding if we should re-create view or just update existing context.