8000 fix(core): properly handle the case where getSignalGraph is called on a componentless NodeInjector by AleksanderBodurri · Pull Request #60772 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

fix(core): properly handle the case where getSignalGraph is called on a componentless NodeInjector #60772

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/core/src/render3/util/signal_debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
SIGNAL_NODE,
SignalNode,
} from '../../../primitives/signals';
import {isLView} from '../interfaces/type_checks';

export interface DebugSignalGraphNode {
kind: string;
Expand Down Expand Up @@ -79,9 +80,10 @@ function getTemplateConsumer(injector: NodeInjector): ReactiveLViewConsumer | nu
const lView = getNodeInjectorLView(injector)!;
assertLView(lView);
const templateLView = lView[tNode.index]!;
assertLView(templateLView);

return templateLView[REACTIVE_TEMPLATE_CONSUMER];
if (isLView(templateLView)) {
return templateLView[REACTIVE_TEMPLATE_CONSUMER] ?? null;
}
return null;
}

function getNodesAndEdgesFromSignalMap(signalMap: ReadonlyMap<ReactiveNode, ReactiveNode[]>): {
Expand Down
48 changes: 47 additions & 1 deletion packages/core/test/acceptance/signal_debug_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
* found in the LICENSE file at https://angular.dev/license
*/

import {Component, computed, effect, inject, Injectable, signal} from '../../src/core';
import {NodeInjector} from '../../../core/src/render3/di';
import {getDirectives} from '../../../core/src/render3/util/discovery_utils';
import {
Component,
Directive,
computed,
effect,
inject,
Injectable,
signal,
Injector,
} from '../../src/core';
import {
getFrameworkDIDebugData,
setupFrameworkInjectorProfiler,
Expand Down Expand Up @@ -302,4 +313,39 @@ describe('getSignalGraph', () => {
producer: fourFiveSixNode,
});
}));

it('should return no nodes or edges for a NodeInjector that only has directives and no component', () => {
@Directive({
selector: '[myDirective]',
})
class MyDirective {
injector = inject(Injector);
}

@Component({
selector: 'component-with-directive',
template: `<div id="element-with-directive" myDirective></div>`,
imports: [MyDirective],
})
class WithDirective {}

TestBed.configureTestingModule({imports: [WithDirective]});
const fixture = TestBed.createComponent(WithDirective);
fixture.detectChanges();

const element = fixture.nativeElement.querySelector('#element-with-directive');
// get the directive instance
const directiveInstances = getDirectives(element);
expect(directiveInstances.length).toBe(1);
const directiveInstance = directiveInstances[0];
expect(directiveInstance).toBeInstanceOf(MyDirective);
const injector = (directiveInstance as MyDirective).injector;
expect(injector).toBeInstanceOf(NodeInjector);
const signalGraph = getSignalGraph(injector);
expect(signalGraph).toBeDefined();

const {nodes, edges} = signalGraph;
expect(nodes.length).toBe(0);
expect(edges.length).toBe(0);
});
});
Loading
0