Skip to content

Commit

Permalink
refactor(core): Do no run queries in checkNoChanges
Browse files Browse the repository at this point in the history
Quieries should not run in checkNoChanges mode.  We don't want components
to behave differently depending on whether check no changes is enabled or not.
  • Loading branch information
atscott committed Oct 25, 2023
1 parent 76152a5 commit 5ebd17e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
34 changes: 17 additions & 17 deletions packages/core/src/render3/instructions/change_detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ export function refreshView<T>(
markTransplantedViewsForRefresh(lView);
detectChangesInEmbeddedViews(lView, ChangeDetectionMode.Global);

// Content query results must be refreshed before content hooks are called.
if (tView.contentQueries !== null) {
refreshContentQueries(tView, lView);
}

// execute content hooks (AfterContentInit, AfterContentChecked)
// PERF WARNING: do NOT extract this to a separate function without running benchmarks
if (!isInCheckNoChangesPass) {
// Content query results must be refreshed before content hooks are called.
if (tView.contentQueries !== null) {
refreshContentQueries(tView, lView);
}

// execute content hooks (AfterContentInit, AfterContentChecked)
// PERF WARNING: do NOT extract this to a separate function without running benchmarks
if (hooksInitPhaseCompleted) {
const contentCheckHooks = tView.contentCheckHooks;
if (contentCheckHooks !== null) {
Expand All @@ -210,17 +210,17 @@ export function refreshView<T>(
detectChangesInChildComponents(lView, components, ChangeDetectionMode.Global);
}

// View queries must execute after refreshing child components because a template in this view
// could be inserted in a child component. If the view query executes before child component
// refresh, the template might not yet be inserted.
const viewQuery = tView.viewQuery;
if (viewQuery !== null) {
executeViewQueryFn<T>(RenderFlags.Update, viewQuery, context);
}

// execute view hooks (AfterViewInit, AfterViewChecked)
// PERF WARNING: do NOT extract this to a separate function without running benchmarks
if (!isInCheckNoChangesPass) {
// View queries must execute after refreshing child components because a template in this view
// could be inserted in a child component. If the view query executes before child component
// refresh, the template might not yet be inserted.
const viewQuery = tView.viewQuery;
if (viewQuery !== null) {
executeViewQueryFn<T>(RenderFlags.Update, viewQuery, context);
}

// execute view hooks (AfterViewInit, AfterViewChecked)
// PERF WARNING: do NOT extract this to a separate function without running benchmarks
if (hooksInitPhaseCompleted) {
const viewCheckHooks = tView.viewCheckHooks;
if (viewCheckHooks !== null) {
Expand Down
6 changes: 4 additions & 2 deletions packages/core/test/acceptance/i18n_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2488,14 +2488,16 @@ describe('runtime i18n', () => {

// Create embedded view
q.create();
fixture.detectChanges();
fixture.detectChanges(false);
fixture.detectChanges(false);
expect(q.query.length).toEqual(1);
expect(toHtml(fixture.nativeElement))
.toEqual(`<div-query>Contenu<!--ng-container--></div-query>`);

// Disable ng-if
fixture.componentInstance.visible = false;
fixture.detectChanges();
fixture.detectChanges(false);
fixture.detectChanges(false);
expect(q.query.length).toEqual(0);
expect(toHtml(fixture.nativeElement))
.toEqual(`<div-query>Contenu<!--ng-container--></div-query>`);
Expand Down

0 comments on commit 5ebd17e

Please sign in to comment.