-
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(ivy): support queries for views inserted in lifecycle hooks #24587
fix(ivy): support queries for views inserted in lifecycle hooks #24587
Conversation
You can preview ee5c92d at https://pr24587-ee5c92d.ngbuilds.io/. |
ee5c92d
to
8cae739
Compare
You can preview 8cae739 at https://pr24587-8cae739.ngbuilds.io/. |
@@ -15,7 +15,7 @@ import {Sanitizer} from '../sanitization/security'; | |||
import {assertComponentType, assertDefined} from './assert'; | |||
import {queueInitHooks, queueLifecycleHooks} from './hooks'; | |||
import {CLEAN_PROMISE, ROOT_DIRECTIVE_INDICES, _getComponentHostLElementNode, baseDirectiveCreate, createLViewData, createTView, detectChangesInternal, enterView, executeInitAndContentHooks, getRootView, hostElement, initChangeDetectorIfExisting, leaveView, locateHostElement, setHostBindings,} from './instructions'; | |||
import {ComponentDef, ComponentDefInternal, ComponentType} from './interfaces/definition'; | |||
import {ComponentDef, ComponentDefInternal, ComponentType, RenderFlags} from './interfaces/definition'; |
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.
RenderFlags
import left from other changes, remove.
@@ -17,7 +16,7 @@ import {Type} from '../type'; | |||
import {resolveRendererType2} from '../view/util'; | |||
|
|||
import {diPublic} from './di'; | |||
import {ComponentDefFeature, ComponentDefInternal, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefInternal, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeDef, PipeType, PipeTypesOrFactory} from './interfaces/definition'; | |||
import {ComponentDefFeature, ComponentDefInternal, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefInternal, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeDef, PipeType, PipeTypesOrFactory, RenderFlags} from './interfaces/definition'; |
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.
RenderFlags
import not needed here, remove
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
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.
I did most of the fixups here: 8413299
Can you take care of the remainder of the comments.
@@ -192,7 +192,7 @@ The goal is for the `@Component` (and friends) to be the compiler of template. S | |||
| `@ContentChildren` | ✅ | ✅ | ❌ | | |||
| `@ContentChild` | ✅ | ✅ | ✅ | | |||
| `@ViewChildren` | ✅ | ✅ | ❌ | | |||
| `@ViewChild` | ✅ | ✅ | ✅ | | |||
| `@ViewChild` | ✅ | ✅ | ❌ | |
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.
Could we add the compiler changes? as follow on PR?
@@ -15,7 +15,7 @@ import {Sanitizer} from '../sanitization/security'; | |||
import {assertComponentType, assertDefined} from './assert'; | |||
import {queueInitHooks, queueLifecycleHooks} from './hooks'; | |||
import {CLEAN_PROMISE, ROOT_DIRECTIVE_INDICES, _getComponentHostLElementNode, baseDirectiveCreate, createLViewData, createTView, detectChangesInternal, enterView, executeInitAndContentHooks, getRootView, hostElement, initChangeDetectorIfExisting, leaveView, locateHostElement, setHostBindings,} from './instructions'; | |||
import {ComponentDef, ComponentDefInternal, ComponentType} from './interfaces/definition'; | |||
import {ComponentDef, ComponentDefInternal, ComponentType, RenderFlags} from './interfaces/definition'; |
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.
I think this Import is not needed
@@ -17,7 +16,7 @@ import {Type} from '../type'; | |||
import {resolveRendererType2} from '../view/util'; | |||
|
|||
import {diPublic} from './di'; | |||
import {ComponentDefFeature, ComponentDefInternal, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefInternal, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeDef, PipeType, PipeTypesOrFactory} from './interfaces/definition'; | |||
import {ComponentDefFeature, ComponentDefInternal, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefInternal, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeDef, PipeType, PipeTypesOrFactory, RenderFlags} from './interfaces/definition'; |
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.
un-needed import revert
* execution is different as compared to all other instructions (after change detection hooks but | ||
* before view hooks). | ||
*/ | ||
queryInstructions?: ComponentTemplate<T>| null; |
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.
bikeshedding: I think the word instructions
does not add value. We don't call it templateInstructions
and so it should be dropped.
Also even thought it is same signature as ComponentTemplate
we should have a separate name alias for it. ComponentQuery
type: NgTemplateOutletDef, | ||
selectors: [['', 'ngTemplateOutlet', '']], | ||
factory: () => new NgTemplateOutletDef(injectViewContainerRef()), | ||
features: [NgOnChangesFeature( |
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.
Could you rewrite NgTemplateOutlet
to not have NgOnChanges
in a follow up PR.
@@ -228,14 +228,16 @@ export function toHtml<T>(componentOrElement: T | RElement): string { | |||
|
|||
export function createComponent( | |||
name: string, template: ComponentTemplate<any>, directives: DirectiveTypesOrFactory = [], | |||
pipes: PipeTypesOrFactory = []): ComponentType<any> { | |||
pipes: PipeTypesOrFactory = [], |
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.
number of positional args is getting long. Consider cleaning up by making the optional args named?
@@ -188,6 +188,12 @@ | |||
{ | |||
"name": "locateHostElement" | |||
}, | |||
{ | |||
"name": "queryCreateInstructions" |
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.
Hello world should not be pulling in these instructions. What is going on?
@@ -440,6 +440,12 @@ | |||
{ | |||
"name": "namespaceHTML" | |||
}, | |||
{ |
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.
same here.
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) |
You can preview 8413299 at https://pr24587-8413299.ngbuilds.io/. |
correct, and please add them to sprint. |
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. |
This PR changes how we generate code for view queries.
Previously query-related instructions (create, refresh) were part of component's template function. Unfortunately this meant that queries are refreshed too early (before change detection hooks are run) and potentially were missing views inserted by directives - more details in #23707
With this PR query-related instructions are generated in a dedicated
queryInstructions
function (similar to a template function). ThequeryInstructions
function has the same structure as the main template function but is executed at different time.