Skip to content
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

Conversation

pkozlowski-opensource
Copy link
Member

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). The queryInstructions function has the same structure as the main template function but is executed at different time.

@pkozlowski-opensource pkozlowski-opensource added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release comp: ivy labels Jun 20, 2018
@mary-poppins
Copy link

You can preview ee5c92d at https://pr24587-ee5c92d.ngbuilds.io/.

@mary-poppins
Copy link

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';
Copy link
Member Author

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';
Copy link
Member Author

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

@googlebot
Copy link

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 cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

Copy link
Contributor

@mhevery mhevery left a 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` | ✅ | ✅ | |
Copy link
Contributor

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';
Copy link
Contributor

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';
Copy link
Contributor

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;
Copy link
Contributor

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(
Copy link
Contributor

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 = [],
Copy link
Contributor

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"
Copy link
Contributor

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"
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

@mhevery mhevery added cla: yes and removed action: review The PR is still awaiting reviews from at least one requested reviewer cla: no labels Jun 20, 2018
@googlebot
Copy link

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.)

@mary-poppins
Copy link

You can preview 8413299 at https://pr24587-8413299.ngbuilds.io/.

@pkozlowski-opensource
Copy link
Member Author

@mhevery fixups from 8413299 LGTM - I was actually going back and forth on the viewQuery name :-)

If I understand correctly we can land this PR with your fixup and take care of the rest in the follow-up PRs, right? (I will add those items to the sprint tasks)

@mhevery
Copy link
Contributor

mhevery commented Jun 20, 2018

If I understand correctly we can land this PR with your fixup and take care of the rest in the follow-up PRs, right? (I will add those items to the sprint tasks)

correct, and please add them to sprint.

@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label Jun 20, 2018
@mhevery
Copy link
Contributor

mhevery commented Jun 20, 2018

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants