Revert "fix(core): notify profiler events in case of errors"

This reverts commit af1ba52587.

(cherry picked from commit adc2a57be0)
This commit is contained in:
Jessica Janiuk 2025-11-17 09:58:41 -08:00
parent a966ff18d4
commit 2dccdcd6bc
4 changed files with 11 additions and 133 deletions

View file

@ -623,7 +623,6 @@ export class ApplicationRef {
private tickImpl = (): void => {
(typeof ngDevMode === 'undefined' || ngDevMode) && warnIfDestroyed(this._destroyed);
if (this._runningTick) {
profiler(ProfilerEvent.ChangeDetectionEnd);
throw new RuntimeError(
RuntimeErrorCode.RECURSIVE_APPLICATION_REF_TICK,
ngDevMode && 'ApplicationRef.tick is called recursively',
@ -662,11 +661,8 @@ export class ApplicationRef {
let runs = 0;
while (this.dirtyFlags !== ApplicationRefDirtyFlags.None && runs++ < MAXIMUM_REFRESH_RERUNS) {
profiler(ProfilerEvent.ChangeDetectionSyncStart);
try {
this.synchronizeOnce();
} finally {
profiler(ProfilerEvent.ChangeDetectionSyncEnd);
}
this.synchronizeOnce();
profiler(ProfilerEvent.ChangeDetectionSyncEnd);
}
if ((typeof ngDevMode === 'undefined' || ngDevMode) && runs >= MAXIMUM_REFRESH_RERUNS) {

View file

@ -426,11 +426,9 @@ function detectChangesInComponent(
profiler(ProfilerEvent.ComponentStart);
const componentView = getComponentLViewByIndex(componentHostIdx, hostLView);
try {
detectChangesInViewIfAttached(componentView, mode);
} finally {
profiler(ProfilerEvent.ComponentEnd, componentView[CONTEXT] as any as {});
}
detectChangesInViewIfAttached(componentView, mode);
profiler(ProfilerEvent.ComponentEnd, componentView[CONTEXT] as any as {});
}
/**
@ -553,11 +551,8 @@ function processHostBindingOpCodes(tView: TView, lView: LView): void {
setBindingRootForHostBindings(bindingRootIndx, directiveIdx);
const context = lView[directiveIdx];
profiler(ProfilerEvent.HostBindingsUpdateStart, context);
try {
hostBindingFn(RenderFlags.Update, context);
} finally {
profiler(ProfilerEvent.HostBindingsUpdateEnd, context);
}
hostBindingFn(RenderFlags.Update, context);
profiler(ProfilerEvent.HostBindingsUpdateEnd, context);
}
}
} finally {

View file

@ -43,11 +43,9 @@ export function renderComponent(hostLView: LView, componentHostIdx: number) {
profiler(ProfilerEvent.ComponentStart);
try {
renderView(componentTView, componentView, componentView[CONTEXT]);
} finally {
profiler(ProfilerEvent.ComponentEnd, componentView[CONTEXT] as any as {});
}
renderView(componentTView, componentView, componentView[CONTEXT]);
profiler(ProfilerEvent.ComponentEnd, componentView[CONTEXT] as any as {});
}
/**

View file

@ -492,117 +492,6 @@ describe('profiler', () => {
).toBeTrue();
});
it('should capture child component creation events when a template error occurs', () => {
@Component({selector: 'my-child', template: '{{ error() }}'})
class ChildComponent {
constructor() {
throw new Error('Simulated error');
}
}
@Component({selector: 'my-comp', imports: [ChildComponent], template: '<my-child/>'})
class MyComponent {}
expect(() => TestBed.createComponent(MyComponent)).toThrow();
expect(p.hasEvents(ProfilerEvent.ComponentStart, ProfilerEvent.ComponentEnd)).toBeTrue();
});
it('should capture child component change detection events when a template error occurs', () => {
@Component({selector: 'my-child', template: '{{ error() }}'})
class ChildComponent {
error() {
throw new Error('Simulated error');
}
}
@Component({selector: 'my-comp', imports: [ChildComponent], template: '<my-child/>'})
class MyComponent {}
const fixture = TestBed.createComponent(MyComponent);
p.clearEvents();
expect(() => fixture.detectChanges(false)).toThrow();
expect(p.hasEvents(ProfilerEvent.ComponentStart, ProfilerEvent.ComponentEnd)).toBeTrue();
});
it('should capture child component change detection events when a template error occurs', () => {
@Component({selector: 'my-child', template: '{{ error() }}'})
class ChildComponent {
error() {
throw new Error('Simulated error');
}
}
@Component({selector: 'my-comp', imports: [ChildComponent], template: '<my-child/>'})
class MyComponent {}
TestBed.createComponent(MyComponent);
p.clearEvents();
expect(() => TestBed.tick()).toThrow();
expect(p.events).toEqual([
ProfilerEvent.ChangeDetectionStart,
ProfilerEvent.ChangeDetectionSyncStart,
ProfilerEvent.ComponentStart,
ProfilerEvent.TemplateUpdateStart,
ProfilerEvent.TemplateUpdateEnd,
ProfilerEvent.ComponentStart,
ProfilerEvent.TemplateUpdateStart,
ProfilerEvent.TemplateUpdateEnd,
ProfilerEvent.ComponentEnd,
ProfilerEvent.ComponentEnd,
ProfilerEvent.ChangeDetectionSyncEnd,
ProfilerEvent.ChangeDetectionEnd,
]);
});
it('should capture host binding events when an error occurs', () => {
@Component({selector: 'my-comp', host: {'[a]': 'error()'}, template: ''})
class MyComponent {
error() {
throw new Error('Simulated error');
}
}
const fixture = TestBed.createComponent(MyComponent);
p.clearEvents();
expect(() => fixture.detectChanges(false)).toThrow();
expect(
p.hasEvents(ProfilerEvent.HostBindingsUpdateEnd, ProfilerEvent.HostBindingsUpdateEnd),
).toBeTrue();
});
it('should capture symmetric tick events when incorrectly called recursively', () => {
@Component({selector: 'my-comp', template: '{{ illegalTick() }}'})
class MyComponent {
illegalTick() {
TestBed.tick();
}
}
TestBed.createComponent(MyComponent);
p.clearEvents();
expect(() => TestBed.tick()).toThrow();
expect(p.events).toEqual([
ProfilerEvent.ChangeDetectionStart,
ProfilerEvent.ChangeDetectionSyncStart,
ProfilerEvent.ComponentStart,
ProfilerEvent.TemplateUpdateStart,
ProfilerEvent.ChangeDetectionStart,
ProfilerEvent.ChangeDetectionEnd,
ProfilerEvent.TemplateUpdateEnd,
ProfilerEvent.ComponentEnd,
ProfilerEvent.ChangeDetectionSyncEnd,
ProfilerEvent.ChangeDetectionEnd,
]);
});
it('should invoke a profiler when host bindings are evaluated', () => {
@Component({
selector: 'my-comp',
@ -644,7 +533,7 @@ describe('profiler', () => {
template: `
@defer (on immediate) {
nothing to see here...
}
}
`,
})
class MyComponent {}