Skip to content
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

@ngrx/component: Use "global" rendering strategy in zoneless mode #3342

Closed
markostanimirovic opened this issue Mar 9, 2022 · 0 comments · Fixed by #3379
Closed

@ngrx/component: Use "global" rendering strategy in zoneless mode #3342

markostanimirovic opened this issue Mar 9, 2022 · 0 comments · Fixed by #3379

Comments

@markostanimirovic
Copy link
Member

markostanimirovic commented Mar 9, 2022

@ngrx/component uses changeDetectorRef.detectChanges in zoneless mode. This method will synchronously run change detection which can cause performance issues.

For example, the following component will be rerendered 3 times when "Emit new value" button is clicked:

@Component({
  selector: 'ngrx-number',
  template: `
    <p>{{ num$ | ngrxPush }}</p>
    <p>{{ num$ | ngrxPush }}</p>
    <p>{{ num$ | ngrxPush }}</p>

    <button (click)="emitNewValue()">Emit new value</button>
  `,
})
export class NumberComponent {
  readonly num$ = new BehaviorSubject(0);

  emitNewValue(): void {
    this.num$.next(Math.random());
  }
}

because the changeDetectorRef.detectChanges will be called 3 times under the hood.

As a solution, we can use the θmarkDirty function to trigger the change detection in zoneless mode. Also, the rendering strategy in zoneless mode will be "global" with θmarkDirty. This will make the rendering strategy consistent in both zoneless and zonefull mode.

@markostanimirovic markostanimirovic self-assigned this Mar 9, 2022
brandonroberts pushed a commit that referenced this issue May 23, 2022
Closes #3342

BREAKING CHANGES:

The native local rendering strategy is replaced by global
in zone-less mode for better performance.

BEFORE:

The change detection is triggered via `changeDetectorRef.detectChanges`
in zone-less mode.

AFTER:

The change detection is triggered via `ɵmarkDirty` in zone-less mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant