fix(ivy): ensure views created in constructors dont break queries (#29983)
Previous to this change, we assumed embedded views could only be created after their parent template node had completed processing. As a result, we only set up query logic for containers after directives on the node were created. However, this assumption didn't take into account the case where a directive on a template node could create views in its constructor. This commit fixes query logic to work with views created in constructors. In that case, we need to create a query container before the new view is rendered so query results in the view aren't lost. But since the query container is created before directives have completed processing, we also have to ensure that query results gathered later on the template node are inserted before that query container. Otherwise, query results in embedded views will clobber query results on template nodes. This splice mode may be slightly slower than the normal matching for queries on containers, but we should only fall back to this strategy in the edge case where views are created in constructors. (We should encourage developers to create views in ngOnInit instead). PR Close #29983
This commit is contained in:
@ -37,6 +37,13 @@ export interface LQueries {
|
||||
*/
|
||||
addNode(tNode: TElementNode|TContainerNode|TElementContainerNode): void;
|
||||
|
||||
/**
|
||||
* Notify `LQueries` that a new `TNode` has been created and needs to be added to query results
|
||||
* if matching query predicate. This is a special mode invoked if the query container has to
|
||||
* be created out of order (e.g. view created in the constructor of a directive).
|
||||
*/
|
||||
insertNodeBeforeViews(tNode: TElementNode|TContainerNode|TElementContainerNode): void;
|
||||
|
||||
/**
|
||||
* Notify `LQueries` that a new LContainer was added to ivy data structures. As a result we need
|
||||
* to prepare room for views that might be inserted into this container.
|
||||
|
Reference in New Issue
Block a user