-
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): Forward refs now supported #27439
Conversation
You can preview c572156 at https://pr27439-c572156.ngbuilds.io/. |
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.
This should probably be a feat(ivy)
not fix(ivy)
since forwardRef
s were unsupported before.
Also, check if this fixes any more tests besides just this one.
for (let i = moduleQueue.length - 1; i--;) { | ||
const {moduleType, ngModule} = moduleQueue[i]; | ||
|
||
if (ngModule.declarations && ngModule.declarations.every(isResolvedDeclaration)) { |
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.
ngModule.declarations
could be nested, e.g: [[[forwardRef(() => Cmp)]]]
.
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.
resolved
@@ -19,14 +20,46 @@ import {reflectDependencies} from './util'; | |||
|
|||
const EMPTY_ARRAY: Type<any>[] = []; | |||
|
|||
const moduleQueue: Array<{moduleType: Type<any>, ngModule: NgModule}> = []; |
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.
Maybe make a named type for this?
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.
Done
@@ -51,6 +51,9 @@ export function compileComponent(type: Type<any>, metadata: Component): void { | |||
error.push(`Did you run and wait for 'resolveComponentResources()'?`); | |||
throw new Error(error.join('\n')); | |||
} | |||
|
|||
flushModuleScopingQueueAsMuchAsPossible(); |
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.
Add a comment here explaining what's happening.
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.
Done
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 must be moved below the assignment of the compilation result of ngComponent
below.
The flushModuleScopingQueueAsMuchAsPossible
may find that the component can be patched. It sees that ngComponentDef
is present and therefore reads it to patch its scope, which will re-enter here again. We should probably not do that, as it results in repeated compilation.
} | ||
} | ||
|
||
/** Returns truthy if a declaration (fron an ngModule.declarations) is resolved. */ |
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.
Coerce this to boolean
.
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.
Done
/** | ||
* Compiles a module in JIT mode. | ||
* | ||
* This function automatically gets called when a class has a `@NgModule` decorator. | ||
*/ | ||
export function compileNgModule(moduleType: Type<any>, ngModule: NgModule = {}): void { | ||
compileNgModuleDefs(moduleType, ngModule); | ||
setScopeOnDeclaredComponents(moduleType, ngModule); | ||
enqueueModuleForDelayedScoping(moduleType, ngModule); |
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.
Add a comment here explaining what's happening.
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.
Done
|
You can preview 8bc38ba at https://pr27439-8bc38ba.ngbuilds.io/. |
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 |
3aded9b
to
099157a
Compare
CLAs look good, thanks! |
Squashed and updated the commit message as requested... Will review CI failures once they're done running. |
You can preview 099157a at https://pr27439-099157a.ngbuilds.io/. |
You can preview 3aded9b at https://pr27439-3aded9b.ngbuilds.io/. |
You can preview 11a259d at https://pr27439-11a259d.ngbuilds.io/. |
You can preview d645daf at https://pr27439-d645daf.ngbuilds.io/. |
moduleQueue.slice(i, 1); | ||
setScopeOnDeclaredComponents(moduleType, ngModule); | ||
if (!flushingModuleQueue) { | ||
flushingModuleQueue = true; |
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.
This dance could probably be avoided if we move flushModuleScopingQueueAsMuchAsPossible
to after the completion of the ngComponentDef
compilation (see #27439 (comment)). This hack is now required because ngComponentDef
is not re-entrant.
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 you're right about the flush needing to be moved... However, I'm going to leave this defensive check in this flush, because flushing should be idempotent.
You can preview cf143cc at https://pr27439-cf143cc.ngbuilds.io/. |
You can preview 3e51daf at https://pr27439-3e51daf.ngbuilds.io/. |
You can preview a2d42c1 at https://pr27439-a2d42c1.ngbuilds.io/. |
Adds deferred execution of scope setting for modules such that forward refs can be supported in ivy. Design docs can be found at https://docs.google.com/document/d/11KTbybis9rt0cZgMKd1wo_IKb6y1PMU-RoTDVLTXK4Y/edit#
a2d42c1
to
a39e019
Compare
I've rebased and force-pushed this PR |
You can preview a39e019 at https://pr27439-a39e019.ngbuilds.io/. |
Adds deferred execution of scope setting for modules such that forward refs can be supported in ivy. Design docs can be found at https://docs.google.com/document/d/11KTbybis9rt0cZgMKd1wo_IKb6y1PMU-RoTDVLTXK4Y/edit# PR Close angular#27439
Adds deferred execution of scope setting for modules such that forward refs can be supported in ivy. Design docs can be found at https://docs.google.com/document/d/11KTbybis9rt0cZgMKd1wo_IKb6y1PMU-RoTDVLTXK4Y/edit# PR Close angular#27439
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. |
Adds deferred execution of scope setting for modules such that forward refs can be supported in ivy. Design docs can be found at https://docs.google.com/document/d/11KTbybis9rt0cZgMKd1wo_IKb6y1PMU-RoTDVLTXK4Y/edit#