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

refactor(core): Provide scheduler for use and coordination with zone change detection #54952

Closed
wants to merge 1 commit into from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Mar 19, 2024

This commit makes the zoneless scheduler (privately) available to applications that have ZoneJS-based change detection. This would catch any changes of interest (signal updates, markForCheck calls, attaching Dirty views) that happen outside the Angular Zone.

See #53844 for additional information about why this is important. More details to come in the a future commit that makes this a public option.

@atscott atscott added the area: core Issues related to the framework runtime label Mar 19, 2024
@ngbot ngbot bot added this to the Backlog milestone Mar 19, 2024
@atscott atscott added the target: minor This PR is targeted for the next minor release label Mar 19, 2024
@eneajaho
Copy link
Contributor

This is 🚀

Because this opens up the possibility to have zoneless and not zoneless parts of an application.

Will this work ?

@Directive({
  selector: 'zoneless',
  standalone: true
})
export class Zoneless {
  vcRef = inject(ViewContainerRef);
  tplRef = inject(TemplateRef);
  ngZone = inject(NgZone);

  ngOnInit() {
    this.ngZone.runOutsideAngular(() => {
       this.vcRef.createEmbeddedView(this.tplRef);
    });
  }
}

and apply it on some router-outlet

// main-layout.component.html

<header />
<router-outlet  *zoneless />
<footer />

@atscott
Copy link
Contributor Author

atscott commented Mar 19, 2024

Because this opens up the possibility to have zoneless and not zoneless parts of an application.

Will this work ?

Yes and no. ZoneJS still patches Promise (and many other APIs) globally so you'd really need to have a particular portion of the application operate in an isolated zone so it truly doesn't contribute to the main app's zone.

edit: You'd probably see things working somewhat as expected for a bit because create mode would create all the handlers outside the zone so all their callbacks would execute outside the zone. But change detection still runs inside NgZone.run so as soon as something in that view is created as part of change detection (i.e. and @if block with another listener), that would get created inside the Angular zone.

edit 2: example

@eneajaho
Copy link
Contributor

But change detection still runs inside NgZone.run so as soon as something in that view is created as part of change detection (i.e. and @if block with another listener), that would get created inside the Angular zone.

And that is supposed to change if Angular goes zoneless by default, right?

@atscott
Copy link
Contributor Author

atscott commented Mar 19, 2024

But change detection still runs inside NgZone.run so as soon as something in that view is created as part of change detection (i.e. and @if block with another listener), that would get created inside the Angular zone.

And that is supposed to change if Angular goes zoneless by default, right?

Change detection will always run inside ngZone.run but this doesn't change the execution zone in "zoneless" which uses NoopNgZone

@atscott atscott marked this pull request as ready for review March 25, 2024 22:55
@atscott atscott requested a review from alxhub March 26, 2024 15:38
@atscott atscott added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Mar 27, 2024
@atscott
Copy link
Contributor Author

atscott commented Mar 27, 2024

caretaker note: This will require fixing the MfW implementation, as seen in cl/619562101

…change detection

This commit makes the zoneless scheduler (privately) available to applications that
have ZoneJS-based change detection. This would catch any changes of
interest (signal updates, `markForCheck` calls, attaching `Dirty` views)
that happen outside the Angular Zone.

See angular#53844 for additional information about why this is important.
More details to come in the a future commit that makes this a public option.
@dylhunn
Copy link
Contributor

dylhunn commented Mar 27, 2024

This PR was merged into the repository by commit 80f96e7.

@dylhunn dylhunn closed this in 80f96e7 Mar 27, 2024
atscott added a commit to atscott/angular that referenced this pull request Mar 27, 2024
…ation

This commit fixes a mistake in angular#54952 where the first pending task was falsey because its ID is 0
dylhunn pushed a commit that referenced this pull request Mar 27, 2024
…ation (#55074)

This commit fixes a mistake in #54952 where the first pending task was falsey because its ID is 0

PR Close #55074
ilirbeqirii pushed a commit to ilirbeqirii/angular that referenced this pull request Apr 6, 2024
…change detection (angular#54952)

This commit makes the zoneless scheduler (privately) available to applications that
have ZoneJS-based change detection. This would catch any changes of
interest (signal updates, `markForCheck` calls, attaching `Dirty` views)
that happen outside the Angular Zone.

See angular#53844 for additional information about why this is important.
More details to come in the a future commit that makes this a public option.

PR Close angular#54952
ilirbeqirii pushed a commit to ilirbeqirii/angular that referenced this pull request Apr 6, 2024
…ation (angular#55074)

This commit fixes a mistake in angular#54952 where the first pending task was falsey because its ID is 0

PR Close angular#55074
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants