fix(ivy): unable to project into multiple slots with default selector (#30561)
With View engine it was possible to declare multiple projection definitions and to programmatically project nodes into the slots. e.g. ```html <ng-content></ng-content> <ng-content></ng-content> ``` Using `ViewContainerRef#createComponent` allowed projecting nodes into one of the projection defs (through index) This no longer works with Ivy as the `projectionDef` instruction only retrieves a list of selectors instead of also retrieving entries for reserved projection slots which appear when using the default selector multiple times (as seen above). In order to fix this issue, the Ivy compiler now passes all projection slots to the `projectionDef` instruction. Meaning that there can be multiple projection slots with the same wildcard selector. This allows multi-slot projection as seen in the example above, and it also allows us to match the multi-slot node projection order from View Engine (to avoid breaking changes). It basically ensures that Ivy fully matches the View Engine behavior except of a very small edge case that has already been discussed in FW-886 (with the conclusion of working as intended). Read more here: https://hackmd.io/s/Sy2kQlgTE PR Close #30561
This commit is contained in:

committed by
Miško Hevery

parent
f4cd3740b2
commit
aca339e864
@ -963,18 +963,10 @@ describe('ViewContainerRef', () => {
|
||||
[[myNode]]);
|
||||
fixture.detectChanges();
|
||||
|
||||
// With Ivy the projected content is inserted into the last ng-content container,
|
||||
// while with View Engine the content is projected into the first ng-content slot.
|
||||
// View Engine correctly respects the passed index of "projectedNodes". See: FW-1331.
|
||||
if (ivyEnabled) {
|
||||
expect(getElementHtml(fixture.nativeElement))
|
||||
.toEqual(
|
||||
'<p vcref=""></p><embedded-cmp-with-ngcontent><hr><div>barbaz</div></embedded-cmp-with-ngcontent>');
|
||||
} else {
|
||||
expect(getElementHtml(fixture.nativeElement))
|
||||
.toEqual(
|
||||
'<p vcref=""></p><embedded-cmp-with-ngcontent><div>barbaz</div><hr></embedded-cmp-with-ngcontent>');
|
||||
}
|
||||
|
||||
expect(getElementHtml(fixture.nativeElement))
|
||||
.toEqual(
|
||||
'<p vcref=""></p><embedded-cmp-with-ngcontent><div>barbaz</div><hr></embedded-cmp-with-ngcontent>');
|
||||
});
|
||||
|
||||
it('should support reprojection of projectable nodes', () => {
|
||||
@ -1039,17 +1031,9 @@ describe('ViewContainerRef', () => {
|
||||
]);
|
||||
fixture.detectChanges();
|
||||
|
||||
// With Ivy multi-slot projection is currently not working. This is a bug that
|
||||
// is tracked with FW-1333.
|
||||
if (ivyEnabled) {
|
||||
expect(getElementHtml(fixture.nativeElement))
|
||||
.toEqual(
|
||||
'<p vcref=""></p><embedded-cmp-with-ngcontent><hr>12</embedded-cmp-with-ngcontent>');
|
||||
} else {
|
||||
expect(getElementHtml(fixture.nativeElement))
|
||||
.toEqual(
|
||||
'<p vcref=""></p><embedded-cmp-with-ngcontent>12<hr>34</embedded-cmp-with-ngcontent>');
|
||||
}
|
||||
expect(getElementHtml(fixture.nativeElement))
|
||||
.toEqual(
|
||||
'<p vcref=""></p><embedded-cmp-with-ngcontent>12<hr>34</embedded-cmp-with-ngcontent>');
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user