GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): incorrectly throwing error for self-referencing component … · angular/angular@79a706c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/core
    • src/render3/jit
      • directive.ts
    • test/acceptance
      • component_spec.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/core/src/render3/jit/directive.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/render3/jit/directive.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ function getStandaloneDefFunctions(type: Type<any>, imports: Type<any>[]): {
245245
// Standalone components are always able to self-reference, so include the component's own
246246
// definition in its `directiveDefs`.
247247
cachedDirectiveDefs = [getComponentDef(type)!];
248-
const seen = new Set<Type<unknown>>();
248+
const seen = new Set<Type<unknown>>([type]);
249249

250250
for (const rawDep of imports) {
251251
ngDevMode && verifyStandaloneImport(rawDep, type);
Collapse file

‎packages/core/test/acceptance/component_spec.ts‎

Copy file name to clipboardExpand all lines: packages/core/test/acceptance/component_spec.ts
+64-2Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {DOCUMENT} from '@angular/common';
10-
import {ApplicationRef, Component, ComponentRef, createComponent, createEnvironmentInjector, Directive, ElementRef, EmbeddedViewRef, EnvironmentInjector, inject, Injectable, InjectionToken, Injector, Input, NgModule, OnDestroy, reflectComponentType, Renderer2, Type, ViewChild, ViewContainerRef, ViewEncapsulation, ɵsetDocument} from '@angular/core';
9+
import {DOCUMENT, NgIf} from '@angular/common';
10+
import {ApplicationRef, Component, ComponentRef, createComponent, createEnvironmentInjector, Directive, ElementRef, EmbeddedViewRef, EnvironmentInjector, forwardRef, inject, Injectable, InjectionToken, Injector, Input, NgModule, OnDestroy, reflectComponentType, Renderer2, Type, ViewChild, ViewContainerRef, ViewEncapsulation, ɵsetDocument} from '@angular/core';
1111
import {stringifyForError} from '@angular/core/src/render3/util/stringify_utils';
1212
import {TestBed} from '@angular/core/testing';
1313
import {expect} from '@angular/platform-browser/testing/src/matchers';
@@ -400,6 +400,68 @@ describe('component', () => {
400400
.toThrowError(
401401
/NG0300: Multiple components match node with tagname comp: CompA and CompB/);
402402
});
403+
404+
it('should not throw if a standalone component imports itself', () => {
405+
@Component({
406+
selector: 'comp',
407+
template: '<comp *ngIf="recurse"/>hello',
408+
standalone: true,
409+
imports: [Comp, NgIf]
410+
})
411+
class Comp {
412+
@Input() recurse = false;
413+
}
414+
415+
@Component({
416+
template: '<comp [recurse]="true"/>',
417+
standalone: true,
418+
imports: [Comp],
419+
})
420+
class App {
421+
}
422+
423+
let textContent = '';
424+
425+
expect(() => {
426+
const fixture = TestBed.createComponent(App);
427+
fixture.detectChanges();
428+
textContent = fixture.nativeElement.textContent.trim();
429+
}).not.toThrow();
430+
431+
// Ensure that the component actually rendered.
432+
expect(textContent).toBe('hellohello');
433+
});
434+
435+
it('should not throw if a standalone component imports itself using a forwardRef', () => {
436+
@Component({
437+
selector: 'comp',
438+
template: '<comp *ngIf="recurse"/>hello',
439+
standalone: true,
440+
imports: [forwardRef(() => Comp), NgIf]
441+
})
442+
class Comp {
443+
@Input() recurse = false;
444+
}
445+
446+
@Component({
447+
template: '<comp [recurse]="true"/>',
448+
standalone: true,
449+
imports: [Comp],
450+
})
451+
class App {
452+
}
453+
454+
let textContent = '';
455+
456+
expect(() => {
457+
const fixture = TestBed.createComponent(App);
458+
fixture.detectChanges();
459+
textContent = fixture.nativeElement.textContent.trim();
460+
}).not.toThrow();
461+
462+
// Ensure that the component actually rendered.
463+
expect(textContent).toBe('hellohello');
464+
});
403465
});
404466

405467
it('should use a new ngcontent attribute for child elements created w/ Renderer2', () => {

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.